Search Unity

Embed framework to Xcode project

Discussion in 'iOS and tvOS' started by van_ustwo, Mar 1, 2016.

  1. van_ustwo

    van_ustwo

    Joined:
    Jul 10, 2012
    Posts:
    82
    I need to embed a third party framework to my PostProcessBuild script.
    Is it possible to do this with Xcode manipulation api?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    If you're on Unity 5 or higher, frameworks are automatically identified as plugins, and the editor allows you to include them in the build:
    upload_2016-3-3_21-41-41.png

    The same is also possible to achieve with the Xcode API. If you must do it through code, let me know i can share the code to do that.
     
  3. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
  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!
     
    austinborden and SanderPaladin like this.