Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

XCode Embedded Binaries

Discussion in 'iOS and tvOS' started by SHiLLySiT, Sep 12, 2016.

  1. SHiLLySiT

    SHiLLySiT

    Joined:
    Feb 26, 2013
    Posts:
    12
    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:
    http://answers.unity3d.com/questions/1074471/is-it-possible-to-use-the-xcode-manipulation-api-t.html
    http://forum.unity3d.com/threads/is...s-to-the-embedded-binaries-build-step.358357/
    https://issuetracker.unity3d.com/issues/Embedded-Binaries-function-in-XCode-Manipulation-API

    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.
     
  2. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    Not sure this will help, but take a look at XUPorter https://github.com/onevcat/XUPorter. 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.
     
  3. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    You could try contacting Robert at egoMotion. His egoXproject tool doesn't currently have that feature but it's possible he could add it?
     
  4. zfavourite99

    zfavourite99

    Joined:
    Jan 2, 2018
    Posts:
    2
    #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!
     
  5. ernesb

    ernesb

    Joined:
    Feb 12, 2017
    Posts:
    32
    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
     
  6. Deleted User

    Deleted User

    Guest

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

    Code (CSharp):
    1.    
    2. using UnityEditor.iOS.Xcode.Custom;
    3. using UnityEditor.iOS.Xcode.Custom.Extensions;
    4.  
    5.  
    6.     static void AddDynamicFrameworksForUnity5(string path)
    7.     {
    8. #if UNITY_5
    9.         UnityEditor.iOS.Xcode.Custom.PBXProject pbxProj = new UnityEditor.iOS.Xcode.Custom.PBXProject();
    10.         pbxProj.ReadFromFile(path);
    11.  
    12.         string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");
    13.  
    14.         const string defaultLocationInProj = "Frameworks/Plugins/iOS";
    15.         const string exampleFrameworkName = "XXOO.framework";
    16.  
    17.         string framework = Path.Combine(defaultLocationInProj, exampleFrameworkName);
    18.         string fileGuid = pbxProj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);
    19.         PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProj, targetGuid, fileGuid);
    20.         pbxProj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
    21.         pbxProj.WriteToFile (path);
    22. #endif
    23.     }
    24.  
    using Unity.iOS.Extensisons.Xcode.dll to your project.
     

    Attached Files:

    mmSimon likes this.