public static string AddWatchApp(this PBXProject proj, string mainTargetGuid, string watchExtensionTargetGuid, string name, string bundleId, string infoPlistPath) { string str1 = proj.AddTarget(name, ".app", "com.apple.product-type.application.watchapp2"); string str2 = proj.nativeTargets[watchExtensionTargetGuid].name.Replace(" ", "_"); foreach (string name1 in proj.BuildConfigNames()) { string configGuid = proj.BuildConfigByName(str1, name1); if (name1.Contains("Debug")) { PBXProjectExtensions.SetDefaultWatchAppDebugBuildFlags(proj, configGuid); } else { PBXProjectExtensions.SetDefaultWatchAppReleaseBuildFlags(proj, configGuid); } proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId); proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath); proj.SetBuildPropertyForConfig(configGuid, "IBSC_MODULE", str2); } proj.AddResourcesBuildPhase(str1); string sectionGuid1 = proj.AddCopyFilesBuildPhase(str1, "Embed App Extensions", "", "13"); proj.AddFileToBuildSection(str1, sectionGuid1, proj.GetTargetProductFileRef(watchExtensionTargetGuid)); string sectionGuid2 = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed Watch Content", "$(CONTENTS_FOLDER_PATH)/Watch", "16"); proj.AddFileToBuildSection(mainTargetGuid, sectionGuid2, proj.GetTargetProductFileRef(str1)); proj.AddTargetDependency(str1, watchExtensionTargetGuid); proj.AddTargetDependency(mainTargetGuid, str1); return(str1); }
public static string AddStickerExtension( this PBXProject proj, string mainTargetGuid, string name, string bundleId, string infoPlistPath) { string ext = ".appex"; string str = proj.AddTarget(name, ext, "com.apple.product-type.app-extension.messages-sticker-pack"); foreach (string buildConfigName in proj.BuildConfigNames()) { string configGuid = proj.BuildConfigByName(str, buildConfigName); if (buildConfigName.Contains("Debug")) { proj.SetDefaultAppExtensionDebugBuildFlags(configGuid); } else { proj.SetDefaultAppExtensionReleaseBuildFlags(configGuid); } proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath); proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId); } proj.AddSourcesBuildPhase(str); proj.AddResourcesBuildPhase(str); proj.AddFrameworksBuildPhase(str); string sectionGuid = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed App Extensions", "", "13"); proj.AddFileToBuildSection(mainTargetGuid, sectionGuid, proj.GetTargetProductFileRef(str)); proj.AddTargetDependency(mainTargetGuid, str); return(str); }
public static string AddFileToEmbedLibraries( this PBXProject proj, string targetGuid, string fileGuid) { PBXNativeTargetData nativeTarget = proj.nativeTargets[targetGuid]; string index = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Libraries", "", "10"); PBXCopyFilesBuildPhaseData copyFile = proj.copyFiles[index]; PBXBuildFileData buildFile = proj.FindFrameworkByFileGuid(copyFile, fileGuid); if (buildFile == null) { buildFile = PBXBuildFileData.CreateFromFile(fileGuid, false, (string)null); proj.BuildFilesAdd(targetGuid, buildFile); copyFile.files.AddGUID(buildFile.guid); } proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"); proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)"); proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/../Frameworks"); buildFile.codeSignOnCopy = true; buildFile.removeHeadersOnCopy = true; return(buildFile.guid); }
public static void IosXcodeFix(string path) { PBXProject project = new PBXProject(); string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; project.ReadFromString(File.ReadAllText(projPath)); string target = project.TargetGuidByName("Unity-iPhone"); Debug.Log("Setting linker flag ENABLE_BITCODE to NO"); project.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //get the framework file id (check for possible different locations) string fileId = null; //universal (new) if (fileId == null) { fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/universal/webrtccsharpwrap.framework"); } //armv7 only if (fileId == null) { fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/armv7/webrtccsharpwrap.framework"); } //arm64 only if (fileId == null) { fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/arm64/webrtccsharpwrap.framework"); } //manual placement if (fileId == null) { fileId = project.FindFileGuidByProjectPath("Frameworks/webrtccsharpwrap.framework"); } Debug.Log("Adding build phase CopyFrameworks to copy the framework to the app Frameworks directory"); #if UNITY_2017_2_OR_NEWER project.AddFileToEmbedFrameworks(target, fileId); #else string copyFilePhase = project.AddCopyFilesBuildPhase(target, "CopyFrameworks", "", "10"); project.AddFileToBuildSection(target, copyFilePhase, fileId); //Couldn't figure out how to set that flag yet. Debug.LogWarning("Code Sign On Copy flag must be set manually via Xcode for webrtccsharpwrap.framework:" + "Project settings -> Build phases -> Copy Frameworks -> set the flag Code Sign On Copy"); #endif //make sure the Framework is expected in the Frameworks path. Without that ios won't find the framework project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); File.WriteAllText(projPath, project.WriteToString()); }
public void AddBuildPhasesOutputIsExpected() { ResetGuidGenerator(); PBXProject proj = ReadPBXProject(); string target = proj.AddTarget("TestTarget", ".dylib", "test.type"); proj.AddSourcesBuildPhase(target); proj.AddResourcesBuildPhase(target); proj.AddFrameworksBuildPhase(target); proj.AddCopyFilesBuildPhase(target, "Copy resources", "$(DST_PATH)", "13"); TestOutput(proj, "add_build_phases1.pbxproj"); }
private static void AddEmbeddedFrameworks(PBXProject proj, string targetGuid) { foreach (var framework in ISD_Settings.Instance.EmbededFrameworks) { var fileGuid = proj.AddFile(framework.AbsoluteFilePath, "Frameworks/" + framework.FileName, PBXSourceTree.Source); var embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); proj.AddFileToBuildSection(targetGuid, embedPhase, fileGuid); #if UNITY_2017_4_OR_NEWER proj.AddFileToEmbedFrameworks(targetGuid, fileGuid); #endif proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks"); } }
public void AddBuildPhasesReturnsExistingBuildPhase() { ResetGuidGenerator(); PBXProject proj = ReadPBXProject(); string target = proj.AddTarget("TestTarget", ".dylib", "test.type"); Assert.IsNull(proj.GetSourcesBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000005", proj.AddSourcesBuildPhase(target)); Assert.AreEqual("CCCCCCCC0000000000000005", proj.GetSourcesBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000005", proj.AddSourcesBuildPhase(target)); Assert.IsNull(proj.GetResourcesBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000006", proj.AddResourcesBuildPhase(target)); Assert.AreEqual("CCCCCCCC0000000000000006", proj.GetResourcesBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000006", proj.AddResourcesBuildPhase(target)); Assert.IsNull(proj.GetFrameworksBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000007", proj.AddFrameworksBuildPhase(target)); Assert.AreEqual("CCCCCCCC0000000000000007", proj.GetFrameworksBuildPhaseByTarget(target)); Assert.AreEqual("CCCCCCCC0000000000000007", proj.AddFrameworksBuildPhase(target)); Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "13")); Assert.AreEqual("CCCCCCCC0000000000000008", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "13")); Assert.AreEqual("CCCCCCCC0000000000000008", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "13")); Assert.AreEqual("CCCCCCCC0000000000000008", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "13")); // check whether all parameters are actually matched against existing phases Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files2", "", "13")); Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "path", "13")); Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "14")); Assert.AreEqual("CCCCCCCC0000000000000009", proj.AddCopyFilesBuildPhase(target, "Copy files2", "", "13")); Assert.AreEqual("CCCCCCCC0000000000000009", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files2", "", "13")); Assert.AreEqual("CCCCCCCC0000000000000010", proj.AddCopyFilesBuildPhase(target, "Copy files", "path", "13")); Assert.AreEqual("CCCCCCCC0000000000000010", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "path", "13")); Assert.AreEqual("CCCCCCCC0000000000000011", proj.AddCopyFilesBuildPhase(target, "Copy files", "", "14")); Assert.AreEqual("CCCCCCCC0000000000000011", proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "14")); }
public void WhenUnknownSectionExistsAddCopyFilesBuildPhaseWorks() { ResetGuidGenerator(); PBXProject proj = ReadPBXProject("base_unknown_section.pbxproj"); string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); Assert.IsNotNull(proj.GetSourcesBuildPhaseByTarget(target)); Assert.IsNotNull(proj.GetResourcesBuildPhaseByTarget(target)); Assert.IsNotNull(proj.GetFrameworksBuildPhaseByTarget(target)); //Adding additional sections when an unknown section is already present in pbxproj should work Assert.IsNull(proj.GetCopyFilesBuildPhaseByTarget(target, "Copy files", "", "13")); Assert.IsNotNull(proj.AddCopyFilesBuildPhase(target, "Copy files", "", "13")); }
public static void AddFileToEmbedFrameworks(this PBXProject proj, string targetGuid, string fileGuid) { PBXNativeTargetData nativeTargetData = proj.nativeTargets[targetGuid]; string index = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); PBXCopyFilesBuildPhaseData phase = proj.copyFiles[index]; PBXBuildFileData buildFile = proj.FindFrameworkByFileGuid(phase, fileGuid); if (buildFile == null) { buildFile = PBXBuildFileData.CreateFromFile(fileGuid, false, (string)null); proj.BuildFilesAdd(targetGuid, buildFile); phase.files.AddGUID(buildFile.guid); } proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); buildFile.codeSignOnCopy = true; buildFile.removeHeadersOnCopy = true; }
private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget == BuildTarget.iOS) { Debug.Log("Running Zapic Xcode Scripts"); string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; var proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string targetGuid = proj.TargetGuidByName("Unity-iPhone"); Debug.Log("Zapic: Including Swift Libraries"); proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); Debug.Log("Zapic: Setting search path"); proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks"); //Find the existing framework id var frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/Zapic.framework"); //Try lowercase if (string.IsNullOrEmpty(frameworkId)) { frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/zapic.framework"); } if (string.IsNullOrEmpty(frameworkId)) { Debug.LogError("Zapic: Unable to find iOS framework"); } Debug.Log("Zapic:Adding embedded frameworks"); string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); proj.AddFileToBuildSection(targetGuid, embedPhase, frameworkId); // Apply settings File.WriteAllText(projPath, proj.WriteToString()); Debug.Log("Zapic:Done configuring xcode settings"); } }
/// <inheritdoc /> /// <remarks> /// Postprocessing of generated Xcode project. /// Collects all user frameworks and adds them as embedded to Xcode project. /// </remarks> public void OnPostprocessBuild(BuildTarget target, string path) { if (target != BuildTarget.iOS) { return; } string projectPath = PBXProject.GetPBXProjectPath(path); PBXProject xproject = new PBXProject(); xproject.ReadFromString(File.ReadAllText(projectPath)); string targetName = PBXProject.GetUnityTargetName(); string targetGuid = xproject.TargetGuidByName(targetName); string embedPhaseGuid = xproject.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); xproject.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks"); foreach (string framework in FindFrameworks()) { Debug.LogFormat("Adding framework `{0}`", framework); string frameworkPathInProject = "Frameworks/" + framework; var fileGuid = xproject.FindFileGuidByProjectPath(frameworkPathInProject); if (fileGuid == null) { Debug.LogFormat("Framework `{0}` NOT FOUND in generated xCode project.", frameworkPathInProject); continue; } xproject.AddFileToBuildSection(targetGuid, embedPhaseGuid, fileGuid); } // Hack to Enable Code Sign on Copy attribute for embedded frameworks // Unity 2017.2.0f3 does not provide necessary API so replace in text required. string content = System.Text.RegularExpressions.Regex.Replace( xproject.WriteToString(), @"(.*\.framework in Embed Frameworks \*/ = .*) \};", @"$1 settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };" ); File.WriteAllText(projectPath, content); }
/// <summary> /// Configures file for embed framework section for the given native target. /// /// This function also internally calls <code>proj.AddFileToBuild(targetGuid, fileGuid)</code> /// to ensure that the framework is added to the list of linked frameworks. /// /// If the target has already configured the given file as embedded framework, this function has /// no effect. /// /// A projects containing multiple native targets, a single file or folder reference can be /// configured to be built in all, some or none of the targets. The file or folder reference is /// added to appropriate build section depending on the file extension. /// </summary> /// <param name="proj">A project passed as this argument.</param> /// <param name="targetGuid">The GUID of the target as returned by [[TargetGuidByName()]].</param> /// <param name="fileGuid">The file GUID returned by [[AddFile]] or [[AddFolderReference]].</param> public static void AddFileToEmbedFrameworks(this PBXProject proj, string targetGuid, string fileGuid) { PBXNativeTargetData target = proj.nativeTargets[targetGuid]; var phaseGuid = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10"); var phase = proj.copyFiles[phaseGuid]; var frameworkEmbedFileData = proj.FindFrameworkByFileGuid(phase, fileGuid); if (frameworkEmbedFileData == null) { frameworkEmbedFileData = PBXBuildFileData.CreateFromFile(fileGuid, false, null); proj.BuildFilesAdd(targetGuid, frameworkEmbedFileData); phase.files.AddGUID(frameworkEmbedFileData.guid); } frameworkEmbedFileData.codeSignOnCopy = true; frameworkEmbedFileData.removeHeadersOnCopy = true; }
private static void AddEmbeddedFrameworks(PBXProject project, string targetGuid) { string frameworkRelativePath = Path.Combine(InstabugPluginPath, InstabugFrameworkName); string frameworkAbsolutePath = Path.Combine(Application.dataPath, frameworkRelativePath); string frameworkGuid = project.AddFile(frameworkAbsolutePath, "Frameworks/" + InstabugFrameworkName, PBXSourceTree.Source); project.AddFileToBuild(targetGuid, frameworkGuid); string embedPhaseGuid = project.AddCopyFilesBuildPhase(targetGuid, BuildPhaseName, "", "10" /* Frameworks */); project.AddFileToBuildSection(targetGuid, embedPhaseGuid, frameworkGuid); // HACK: Use the correct path in the project. Not sure why it's using the absolute path. string projectContents = project.WriteToString(); projectContents = projectContents.Replace(frameworkAbsolutePath, "Frameworks/" + frameworkRelativePath); project.ReadFromString(projectContents); }
private static void AddEmbeddedBinary(string projectPath) { const string buildPhaseName = "Embed Libraries"; const string dylibName = "libOVRLipSync.dylib"; var project = new PBXProject(); project.ReadFromFile(projectPath); // Don't add the same library twice if (project.FindFileGuidByProjectPath(dylibName) != null) { return; } var targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName()); // Limit the target to ARM64 project.SetBuildProperty(targetGUID, "ARCHS", "arm64"); // Add dylib to the project var dylibGUID = project.AddFile( Path.Combine(Application.dataPath, "Oculus/LipSync/Plugins/iOS/" + dylibName), dylibName); // Copy it to the same folder as executable var embedPhaseGuid = project.AddCopyFilesBuildPhase(targetGUID, buildPhaseName, "", "6"); project.AddFileToBuildSection(targetGUID, embedPhaseGuid, dylibGUID); var content = project.WriteToString(); // Add CodeSignOnCopy attribute ot the library using an ugly regex content = Regex.Replace(content, "(?<=" + buildPhaseName + ")(?:.*)(\\/\\* " + Regex.Escape(dylibName) + " \\*\\/)(?=; };)", m => m.Value.Replace( "/* " + dylibName + " */", "/* " + dylibName + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, );}" ) ); File.WriteAllText(projectPath, content); }