Unity iOS build failure due to duplicate symbols

ios
unity

#1

We use OpenCV in our project, which conflicts with symbols built into libaffdex-native.a. The affdex static library seems to include symbols from third party libraries that we’re also using.

I solved this by wrapping libaffdex-native.a in a dynamic library to isolate it’s symbols. Could the SDK be updated to use a dynamic library out of the box?

Unity’s XCode API finally supports adding embedded binaries to the XCode project via post-build script, so there would be no hassle of having to add it manually each time you build anymore. Unity does recognize cocoa touch frameworks as plugins now (not sure if this was always the case).

It would be nice to be able to use the Unity SDK as-is and update without having to modify anything, so if the Unity SDK could ship with a dynamic library instead, it would be appreciated.

Thanks!

Post build script for adding embedded binary to XCode project:

#if UNITY_IOS
using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;

public class AffdexPostBuild : ScriptableObject
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        var projFile = PBXProject.GetPBXProjectPath(pathToBuiltProject);

        var proj = new PBXProject();
        proj.ReadFromFile(projFile);

        var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
        var fmwkGuid = proj.FindFileGuidByProjectPath("Frameworks/Affdex/Plugins/iOS/affdex_dynamic.framework");
        proj.AddFileToEmbedFrameworks(targetGuid, fmwkGuid);
        proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

        proj.WriteToFile(projFile);
    }
}
#endif

#2

Hi Nicolas, thanks again for sharing your experience and solution. I’ll add this to our backlog.