XCode Embedded Binaries

I’m working on a project for a client who has provided their SDK. It needs to be added to the “Embedded Binaries” section of the XCode project for it to work. There doesn’t seem to be a way to do this automagically from Unity which breaks our build process.

I’ve found these links but none provide a solution:

Does this function already exist in the latest Unity (5.4.0) in some form? If not, what work arounds have others been using? I can’t be the first to be using a 3rd party framework with an automated build process.

Not sure this will help, but take a look at XUPorter GitHub - onevcat/XUPorter: Add files and frameworks to your Xcode project after it is generated by Unity 3D.. It is used as Unity plugin to do post-build task to configure XCode’s building stuff. I took a peek there once and it’s not complete and not all build setting / build phases can be configured. But the code is clean enough that you might want to modify to suite your need.

You could try contacting Robert at egoMotion. His egoXproject tool doesn’t currently have that feature but it’s possible he could add it?

#if UNITY_EDITOR_OSX

using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;

#endif

public class TestBuildPostprocessor {
[PostProcessBuildAttribute(100)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {

if (target != BuildTarget.iOS) {
UnityEngine.Debug.LogWarning (“Target is not iPhone. XCodePostProcess will not run”);
return;
}
#if UNITY_EDITOR_OSX
//EmbedFrameworks
string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
PBXProject proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
string targetGuid = proj.TargetGuidByName(“Unity-iPhone”);
const string defaultLocationInProj = “Plugins/iOS”;
const string coreFrameworkName = “test.framework”;
string framework = Path.Combine(defaultLocationInProj, coreFrameworkName);
string fileGuid = proj.AddFile(framework, “Frameworks/” + framework, PBXSourceTree.Sdk);
PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
proj.SetBuildProperty(targetGuid, “LD_RUNPATH_SEARCH_PATHS”, “$(inherited) @executable_path/Frameworks”);
proj.WriteToFile (projPath);
//EmbedFrameworks end
#endif
}
}

This code worked for me!

The above code works for Unity 2017 and up, for Unity 5.6, anyone knows if there is a way to embed frameworks without AddFileToEmbedFrameworks? Looks like there is no such thing on Unity 5.6

https://bitbucket.org/Unity-Technologies/xcodeapi

using UnityEditor.iOS.Xcode.Custom;
using UnityEditor.iOS.Xcode.Custom.Extensions;


    static void AddDynamicFrameworksForUnity5(string path)
    {
#if UNITY_5
        UnityEditor.iOS.Xcode.Custom.PBXProject pbxProj = new UnityEditor.iOS.Xcode.Custom.PBXProject();
        pbxProj.ReadFromFile(path);

        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");

        const string defaultLocationInProj = "Frameworks/Plugins/iOS";
        const string exampleFrameworkName = "XXOO.framework";

        string framework = Path.Combine(defaultLocationInProj, exampleFrameworkName);
        string fileGuid = pbxProj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProj, targetGuid, fileGuid);
        pbxProj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
        pbxProj.WriteToFile (path);
#endif
    }

using Unity.iOS.Extensisons.Xcode.dll to your project.

3979972–342148–Unity.iOS.Extensions.Xcode.dll.zip (49.8 KB)

1 Like