Facebook-sdk-for-unity: Unity 2019.3 - library not found for -lFBSDKCoreKit

Created on 24 Mar 2020  ·  16Comments  ·  Source: facebook/facebook-sdk-for-unity

Checklist

Environment

Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:

  • Unity Editor Version: 2019.3.6f1
  • Unity SDK Version: 7.19.1
  • Installation Platform & Verison: iOS version 10+ XCode 11.3.1'

Goals

Build for iOS using Unity 2019.3

Expected Results

Successful build

Actual Results

Compilation fails because library -lFBSDKCoreKit is not found.
Other issues are closed but is not fixed on Facebook SDK 7.19+:

https://github.com/facebook/facebook-sdk-for-unity/issues/352
https://github.com/facebook/facebook-sdk-for-unity/issues/350

Steps to Reproduce

Create fresh project in unity
Install FB SDK package (7.19.1)
Build Unity Project (2019.3.6f1)
Try to build Xcode project on Xcode ( version 11.3.1)
Check errors

bug

Most helpful comment

I had the same issue. Though no matter what I set my cocoapod generation to in Unity Play Services Resolver, the .xcworkspace wasn't being created.

How i fixed it:
open the terminal in the root folder of your project and run
pod install
this created the .xcworkspace file. After opening it, adding signing info etc as usual and then building it, it finally worked.

All 16 comments

I have the exact same problem.
Unity: 2019.3.6f1
FB SDK: (7.19.1)
XCode: 11.3.1

Exact same problem.
Unity: 2018.4.5f1 (LTS)
FB SDK: 7.19.1
XCode: 11.3.1

I think I just figured what the problem was. I was building the Unity project from the project file, whereas with cocoapods you need to open the project in xcode from the workspace file as it includes the unity project AND the cocoapods project. Never built anything from the workspace file before with Unity. My bad.

@flamepygmy
That solved the problem for me as well. :-)
I am not familiar at all with XCode, but I guess a workspace is comparable to a Visual Studio solution. Until now I had always just double clicked on the .xcodeproj file.

I had the same issue. Though no matter what I set my cocoapod generation to in Unity Play Services Resolver, the .xcworkspace wasn't being created.

How i fixed it:
open the terminal in the root folder of your project and run
pod install
this created the .xcworkspace file. After opening it, adding signing info etc as usual and then building it, it finally worked.

I'm currently migrating my regular game to 2019.3 as well and I'm facing the same issue.

This seems to be a problem where FBSDKCOCOAPODS=1 is being included as a preprocessor macro of the main target (Unity-iPhone) instead of UnityFramework, which is the one targeted by IOSResolver and includes all source code exported when building the XCode workspace.

Without this macro, FBSDKCoreKitImport.h will end up pointing to the wrong include/import:

#if defined BUCK
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#elif defined __cplusplus
#import <FBSDKCoreKit.h>
#elif defined FBSDKCOCOAPODS
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#else
@import FBSDKCoreKit;
#endif

Looking into the Facebook SDK source code, I think the problem is in the FixupFiles.cs:
```c#
public static void AddBuildFlag(string path)
{
string projPath = Path.Combine(path, Path.Combine("Unity-iPhone.xcodeproj", "project.pbxproj"));
PBXProject proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
string targetGUID = proj.TargetGuidByName("Unity-iPhone");
proj.AddBuildProperty(targetGUID, "GCC_PREPROCESSOR_DEFINITIONS", " $(inherited) FBSDKCOCOAPODS=1");
proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
proj.AddFrameworkToProject(targetGUID, "Accelerate.framework", true);
File.WriteAllText(projPath, proj.WriteToString());
}

It's still looking for the `Unity-iPhone` target when it should be looking for `UnityFramework` instead for Unity 2019.3.

I can submit a pull request with a quick workaround for the issue like the following, just let me know if I'm in the right direction. Also, I don't have much knowledge on this repo source code, so there could be better solutions than this one.

**PBXProject.cs:**
```c#
        /// <summary>
        /// Returns the default main target name in Unity project.
        /// The returned target name can then be used to retrieve the GUID of the target via TargetGuidByName
        /// function. This function can only be used in Unity-generated projects.
        /// </summary>
        /// <returns>The default main target name.</returns>
        public static string GetUnityTargetName()
        {
#if UNITY_2019_3_OR_NEWER
            return "UnityFramework";
#else
            return "Unity-iPhone";
#endif
        }

FixupFiles.cs:
c# public static void AddBuildFlag(string path) { string projPath = Path.Combine(path, Path.Combine("Unity-iPhone.xcodeproj", "project.pbxproj")); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string targetGUID = proj.TargetGuidByName(GetUnityTargetName()); proj.AddBuildProperty(targetGUID, "GCC_PREPROCESSOR_DEFINITIONS", " $(inherited) FBSDKCOCOAPODS=1"); proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC"); proj.AddFrameworkToProject(targetGUID, "Accelerate.framework", true); File.WriteAllText(projPath, proj.WriteToString()); }

Been wrestling with an adjacent issue on 2019.3, it builds but doesn't run. Would appreciate any guidance. Very similar issue to OPs so I'm not sure it warrants a separate issue.

@felippeduran Tried your fix and built the SDK DLLs from source, still getting the same error I was getting before:

2020-04-15 03:25:54.105800+0300 offroad3[35344:6034574] Error loading /var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Library not loaded: @rpath/FBSDKCoreKit.framework/FBSDKCoreKit Referenced from: /private/var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework Reason: image not found 2020-04-15 03:25:54.268034+0300 offroad3[35344:6034574] Error loading /var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Library not loaded: @rpath/FBSDKCoreKit.framework/FBSDKCoreKit Referenced from: /private/var/containers/Bundle/Application/FE59C147-7622-42CD-BE51-39AA849780D6/offroad3.app/Frameworks/UnityFramework.framework/UnityFramework Reason: image not found

EDIT:

This turned out to be an issue with an ad mediator integrating Facebook Audience Network, and not the Facebook Unity SDK. If you have similar output to me, it was the Appodeal mediation plugin causing this. Otherwise, please disregard this comment.

EDIT 2:

For future googling reference, since I couldn't find this specific issue, the solution to my issue was to simply directly add the frameworks to the Embed Frameworks section of the Build Phases of the Unity-iPhone target.

@aVolnov, did my suggested fix work for you then?

@felippeduran I'm not actually sure since my problem turned out to be a different beast altogether.

@flamepygmy you just saved my life. Lost so many hours on this :(

yup, the Unity iOS pipeline truly is error prone... So many pieces that have to work together, completely unpredictable if any package update breaks anything.

Commenting @flo-wolf's suggestion also fixed this issue for me on 2019.3.9f1.

However, the way I went about it was to completely uninstall cocoapods and reinstall it so that it was a fresh install. I also closed Unity in the process to make sure it was installed cleanly through the Play Services Resolver.

I had been using old cocoapods installs on older projects. I'm not sure what changed in the last year to make it so a fresh install was the best approach - just upgrading the local cocoapods install via terminal may work too, but I was at my wits end ;).

I think I just figured what the problem was. I was building the Unity project from the project file, whereas with cocoapods you need to open the project in xcode from the workspace file as it includes the unity project AND the cocoapods project. Never built anything from the workspace file before with Unity. My bad. @flamepygmy

This worked for me. Thank you!

Open and build Unity-iPhone.xcworkspace instead of Unity-iPhone.xcodeproj

I still wasn't able to generate a Working Build with Unity 2019.3.
These fixes were already sent by "pull request" and there some estimates for release? Unity 2019.3 was released on January 28, it's about 6 months and Facebook SDK still was not made compatible with it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yasuohasegawa picture yasuohasegawa  ·  4Comments

michelleran picture michelleran  ·  4Comments

michelleran picture michelleran  ·  6Comments

derwaldgeist picture derwaldgeist  ·  4Comments

alchemyincarnate picture alchemyincarnate  ·  4Comments