Facebook-sdk-for-unity: Undefined symbol: swiftCompatibility

Created on 25 Jun 2020  ·  21Comments  ·  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: 2018.4.23
  • Unity SDK Version: 7.21.0
  • Installation Platform & Verison: iOS

Goals

I want to be able to update Facebook SDK without constant problem solving.

Expected Results

XCode would cleanly build the client after updating the SDK.

Actual Results

XCode fails to build

Steps to Reproduce

Update from 7.20.0 -> 7.21.0 and build on XCode

Code Samples & Details

Showing Recent Messages
Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements
Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility50

bug

Most helpful comment

@Khaled-Wolf thanks for the code, that's really useful, but still even if this makes the project compile then the framework are not embedded in the binary automatically and the app crashes at startup as mentioned by @NumaNumaNuma. I have tried to manually embed the FB frameworks to the build but I honestly don't know which file from which project I should add to which target. All my attempts failed... Any clue on that? (and also, any clue in how to make it work using a post process script?)

All 21 comments

Current workaround is adding use_framework! to the Podfile in your exported XCode project

Current workaround is adding use_framework! to the Podfile in your exported XCode project

Thanks @KylinChang it worked for me!

Thanks @KylinChang ,
It would be helpful if this is added to the release notes of the bugged version in the SDK download page.

Wow thanks so much, you should definitely add something to the change log.
Also, it'suse_frameworks! (plural)👍

after adding use_frameworks! the project builds, but crashes on start with this error:
[13858:5861271] Error loading /var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Library not loaded: @rpath/FBSDKCoreKit.framework/FBSDKCoreKit Referenced from: /private/var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework Reason: image not found

Adding it to the list of embedded frameworks didn't help.

Anything else I need to do?

It's not working for me! I added "use_frameworks!" but the build still fails. Do I need something else?

after adding use_frameworks! the project builds, but crashes on start with this error:
[13858:5861271] Error loading /var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Library not loaded: @rpath/FBSDKCoreKit.framework/FBSDKCoreKit Referenced from: /private/var/containers/Bundle/Application/59B84CDD-B5F4-4BEB-A75B-44DC54DE13E3/myProject.app/Frameworks/UnityFramework.framework/UnityFramework Reason: image not found

Adding it to the list of embedded frameworks didn't help.

Anything else I need to do?

I get the same thing :/

@KylinChang can you share what your podfile looks like please?

I was able to build it now, but it fails with the same error when running. Anybody was able to make it work?

Same problem here with Unity 2019.4.1, Facebook SDK 7.21.1.

Using use_frameworks! will just use the dynamic libraries instead of the static ones. It compiles, of course, but then those frameworks must be embedded somehow. Still looking into this, but in any case I need Unity generated XCode workspace/project to already be setup or our CI system will fail...

Having to manually modify the podfile and then the project is something that we should not have to do for such an easy task as simply integrating the Facebook SDK...

Same problem here with Unity 2019.4.1, Facebook SDK 7.21.1.

Using use_frameworks! will just use the dynamic libraries instead of the static ones. It compiles, of course, but then those frameworks must be embedded somehow. Still looking into this, but in any case I need Unity generated XCode workspace/project to already be setup or our CI system will fail...

Having to manually modify the podfile and then the project is something that we should not have to do for such an easy task as simply integrating the Facebook SDK...

Here you can setup a simple post build script to modify the podfile programmatically, I use it in my project and it works just fine
Create a new MonoBehaviour file (for example: PostProcessBuild_Podfile.cs) and put it in Assets/Editor folder

using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;

public class PostProcessBuild_Podfile : MonoBehaviour
{
[PostProcessBuildAttribute(45)]//must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's added before "pod install" (50)
private static void PostProcessBuild_iOS(BuildTarget target, string buildPath)
{
if (target == BuildTarget.iOS)
{
var fileName = buildPath + "/Podfile";
var endTag = "platform :ios, '9.0'";
var lineToAdd = "use_frameworks!";

        Debug.Log("PostProcess: Adding use_frameworks! to podfile, this fix for new Facebook SDK");
        var txtLines = File.ReadAllLines(fileName).ToList();
        txtLines.Insert(txtLines.IndexOf(endTag)+1, lineToAdd);
        File.WriteAllLines(fileName, txtLines);
        Debug.Log("PostProcess: Adding use_frameworks! to podfile Completed successfully!");
    }
}

}

image

@Khaled-Wolf thanks for the code, that's really useful, but still even if this makes the project compile then the framework are not embedded in the binary automatically and the app crashes at startup as mentioned by @NumaNumaNuma. I have tried to manually embed the FB frameworks to the build but I honestly don't know which file from which project I should add to which target. All my attempts failed... Any clue on that? (and also, any clue in how to make it work using a post process script?)

I've reverted to using an older version of the sdk for now (7.19.2 is the most recent one that doesn't use the 7.0 swift iOS sdk).

I also reverted back to 7.19.2 as use_frameworks! Seems to have caused issues with other pods I’m using.
We will wait for an updated Facebook SDK to try again :(

@NumaNumaNuma yeah that seems to be the only option for now, it compiles and runs without problems! Thanks for sharing this!

Current workaround here is to add "use_frameworks!" to Podfile or add an empty swift file to exported iOS project. The issue is fixed in https://github.com/facebook/facebook-sdk-for-unity/commit/8fdb57a76d2f5a14c168e91663280d40f274c74c and will be shipped in the next release.

@KylinChang And this is 6 days already from that commit, what happen? Why it still have error in travis and why it not released yet?

@Thaina If you're in a rush maybe you could try and fixing it manually. If you look at the commit it's a very small change you could try to implement yourself. Add that blank swift file and the 2 build properties to your xcode project in a post-build script in unity. Sucks having to do it manually, but it might save you a few days (weeks?) while they release it.
Or maybe they do weekly releases and it'll be out tomorrow :D

@NumaNumaNuma First, because that doesn't work

So I don't actually know I do something wrong or the fix is not really work in the first place. Or it has some requirement that it should or must be a fix from facebook SDK package directly or any other reason

Second, it not official so it pollute my code and need to actually remove it in the future when the real fix came out so I try to avoid that. And that's why I don't like to do that before confirm that facebook will not release it soon

Third, it really didn't work, at least in unity 2020.2

  • That .swift cannot be exist in Editor folder or else it would not be copied into actual xcode project
  • In 2019.3 and after, unity change their build structure into main and framework

    • So just set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to YES in only one main target is not fix the problem

    • Set to both target cause error that Invalid bundle… contains disallowed file 'frameworks'

In my case I need to move that .swift outside into Assets folder. Then made a build process like this

```C#

if UNITY_2019_3_OR_NEWER

    string target = proj.GetUnityMainTargetGuid();

else

    string targetName = PBXProject.GetUnityTargetName();
    string target = proj.TargetGuidByName(targetName);

endif

////

if UNITY_2019_3_OR_NEWER

    foreach(var framework in new [] { target,proj.GetUnityFrameworkTargetGuid() })

else

    foreach(var framework in new [] { target })

endif

    {
        proj.SetBuildProperty(framework, "ENABLE_BITCODE", "NO");
        proj.SetBuildProperty(framework, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES");
        proj.SetBuildProperty(framework, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
        proj.SetBuildProperty(framework, "SWIFT_VERSION", "5.0");
    }

```

Current workaround here is to add "use_frameworks!" to Podfile or add an empty swift file to exported iOS project. The issue is fixed in 8fdb57a and will be shipped in the next release.

Hi! Coud you please say when you are going to release fix?

@KylinChang The fix is correct for older versions of Unity, but Unity 2019.3 and newer require a different target to be "fixed":
https://github.com/YousicianGit/facebook-sdk-for-unity/commit/878fc7b73d9a2c3751bb36792f0276cdfacf9495

I'll submit the fix in a PR soon.

The issue is fixed in the latest release

Was this page helpful?
0 / 5 - 0 ratings