public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS || buildTarget == BuildTarget.tvOS) { #if UNITY_IOS || UNITY_TVOS string projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path); UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); #if UNITY_2019_3_OR_NEWER string target = proj.GetUnityMainTargetGuid(); #else string targetName = UnityEditor.iOS.Xcode.PBXProject.GetUnityTargetName(); string target = proj.TargetGuidByName(targetName); #endif proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFrameworkToProject(target, "AdSupport.framework", false); proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", true); //proj.SetBuildProperty(target, "ENABLE_BITCODE", "YES"); File.WriteAllText(projPath, proj.WriteToString()); #endif } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS || buildTarget == BuildTarget.tvOS) { #if UNITY_IOS || UNITY_TVOS string projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path); UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); #if UNITY_2019_3_OR_NEWER string target = proj.GetUnityMainTargetGuid(); #else string targetName = UnityEditor.iOS.Xcode.PBXProject.GetUnityTargetName(); string target = proj.TargetGuidByName(targetName); #endif proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFrameworkToProject(target, "AdSupport.framework", false); proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", true); //proj.SetBuildProperty(target, "ENABLE_BITCODE", "YES"); #if gameanalytics_topon_enabled string toponHelperFilePath = Path.Combine(path, "Libraries/GameAnalytics/Plugins/iOS/GameAnalyticsTopOnHelper.m"); string contents = File.ReadAllText(toponHelperFilePath); contents = contents.Replace("#if gameanalytics_topon_enabled", "").Replace("#endif", ""); File.WriteAllText(toponHelperFilePath, contents); #endif File.WriteAllText(projPath, proj.WriteToString()); #endif } }
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS || buildTarget == BuildTarget.tvOS) { #if UNITY_IOS || UNITY_TVOS string projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path); UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); #if UNITY_2019_3_OR_NEWER string target = proj.GetUnityMainTargetGuid(); #else string targetName = UnityEditor.iOS.Xcode.PBXProject.GetUnityTargetName(); string target = proj.TargetGuidByName(targetName); #endif proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); proj.AddFrameworkToProject(target, "AdSupport.framework", false); proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", true); //proj.SetBuildProperty(target, "ENABLE_BITCODE", "YES"); #if gameanalytics_topon_enabled string toponSubPath = "Libraries/GameAnalytics/Plugins/iOS/GameAnalyticsTopOnHelper.m"; string[] topOnGuids = AssetDatabase.FindAssets("GameAnalyticsTopOnHelper", null); if (topOnGuids.Length > 0) { string[] p = AssetDatabase.GUIDToAssetPath(topOnGuids[0]).Split(new char[] { '/' }, 2); if (p.Length > 1) { toponSubPath = "Libraries/" + p[1]; } } string toponHelperFilePath = Path.Combine(path, toponSubPath); string topOncontents = File.ReadAllText(toponHelperFilePath); topOncontents = topOncontents.Replace("#if gameanalytics_topon_enabled", "").Replace("#endif", ""); File.WriteAllText(toponHelperFilePath, topOncontents); #endif #if gameanalytics_hyperbid_enabled string hyperbidSubPath = "Libraries/GameAnalytics/Plugins/iOS/GameAnalyticsHyperBidHelper.m"; string[] hyperBidGuids = AssetDatabase.FindAssets("GameAnalyticsHyperBidHelper", null); if (hyperBidGuids.Length > 0) { string[] p = AssetDatabase.GUIDToAssetPath(hyperBidGuids[0]).Split(new char[] { '/' }, 2); if (p.Length > 1) { hyperbidSubPath = "Libraries/" + p[1]; } } string hyperbidHelperFilePath = Path.Combine(path, hyperbidSubPath); string hyperbidContents = File.ReadAllText(hyperbidHelperFilePath); hyperbidContents = hyperbidContents.Replace("#if gameanalytics_hyperbid_enabled", "").Replace("#endif", ""); File.WriteAllText(hyperbidHelperFilePath, hyperbidContents); #endif File.WriteAllText(projPath, proj.WriteToString()); #endif } }
private void OnPostprocessBuildiOS(BuildReport report) { #if UNITY_IOS if (!IsBuiltForAppCenter) { return; } Debug.Log("TestAppPostBuildProcessor.OnPostprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath); BuildTarget buildTarget = report.summary.platform; string path = report.summary.outputPath; string projectPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path); var proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projectPath)); string xcodeTargetGUID = proj.TargetGuidByName("Unity-iPhone"); proj.AddFrameworkToProject(xcodeTargetGUID, "calabash.framework", false); proj.AddFileToBuild(xcodeTargetGUID, proj.AddFile("calabash.framework", "calabash.framework", UnityEditor.iOS.Xcode.PBXSourceTree.Source)); proj.SetBuildProperty(xcodeTargetGUID, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"); proj.AddBuildProperty(xcodeTargetGUID, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)"); proj.AddBuildProperty(xcodeTargetGUID, "OTHER_LDFLAGS", "-ObjC"); proj.AddBuildProperty(xcodeTargetGUID, "OTHER_LDFLAGS", "-force_load"); proj.AddBuildProperty(xcodeTargetGUID, "OTHER_LDFLAGS", "$(SOURCE_ROOT)/calabash.framework/calabash"); proj.AddBuildProperty(xcodeTargetGUID, "OTHER_LDFLAGS", "-framework"); proj.AddBuildProperty(xcodeTargetGUID, "OTHER_LDFLAGS", "CFNetwork"); File.WriteAllText(projectPath, proj.WriteToString()); #endif }
private static void OnPostprocessBuildIOS(string pathToBuiltProject) { // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module #if UNITY_IOS string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string target = proj.TargetGuidByName("Unity-iPhone"); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity")); string[] filesToCopy = new string[] { "PlatformBase.h", "RenderAPI_Metal.mm", "RenderAPI_OpenGLCoreES.cpp", "RenderAPI.cpp", "RenderAPI.h", "RenderingPlugin.cpp", }; for (int i = 0; i < filesToCopy.Length; ++i) { var srcPath = Path.Combine("../PluginSource/source", filesToCopy[i]); var dstLocalPath = "Libraries/" + filesToCopy[i]; var dstPath = Path.Combine(pathToBuiltProject, dstLocalPath); File.Copy(srcPath, dstPath, true); proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath)); } File.WriteAllText(projPath, proj.WriteToString()); #endif // #if UNITY_IOS }
// Implementation of OnPostProcessUpdateProjectDeps(). // NOTE: This is separate from the post-processing method to prevent the // Mono runtime from loading the Xcode API before calling the post // processing step. public static void UpdateProjectDeps( BuildTarget buildTarget, string pathToBuiltProject) { // If the Pods directory does not exist, the pod download step // failed. var podsDir = Path.Combine(pathToBuiltProject, PODS_DIR); if (!Directory.Exists(podsDir)) { return; } Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Frameworks")); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Resources")); string pbxprojPath = GetProjectPath(pathToBuiltProject); var project = new UnityEditor.iOS.Xcode.PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string target = project.TargetGuidByName(TARGET_NAME); HashSet <string> frameworks = new HashSet <string>(); HashSet <string> linkFlags = new HashSet <string>(); foreach (var frameworkFullPath in Directory.GetDirectories(podsDir, "*.framework", SearchOption.AllDirectories)) { string frameworkName = new DirectoryInfo(frameworkFullPath).Name; string destFrameworkPath = Path.Combine("Frameworks", frameworkName); string destFrameworkFullPath = Path.Combine(pathToBuiltProject, destFrameworkPath); // Only move this framework if it contains a library. // Skip frameworks that consist of just resources, they're handled // in a separate import step. if (!File.Exists(Path.Combine( frameworkFullPath, Path.GetFileName(frameworkFullPath) .Replace(".framework", "")))) { continue; } PlayServicesSupport.DeleteExistingFileOrDirectory( destFrameworkFullPath); Directory.Move(frameworkFullPath, destFrameworkFullPath); project.AddFileToBuild( target, project.AddFile(destFrameworkPath, destFrameworkPath, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); string moduleMapPath = Path.Combine(Path.Combine(destFrameworkFullPath, "Modules"), "module.modulemap"); if (File.Exists(moduleMapPath)) { // Parse the modulemap, format spec here: // http://clang.llvm.org/docs/Modules.html#module-map-language using (StreamReader moduleMapFile = new StreamReader(moduleMapPath)) { string line; char[] delim = { ' ' }; while ((line = moduleMapFile.ReadLine()) != null) { string[] items = line.TrimStart(delim).Split(delim, 2); if (items.Length > 1) { if (items[0] == "link") { if (items[1].StartsWith("framework")) { items = items[1].Split(delim, 2); frameworks.Add(items[1].Trim( new char[] { '\"' }) + ".framework"); } else { linkFlags.Add("-l" + items[1]); } } } } } } string resourcesFolder = Path.Combine(destFrameworkFullPath, "Resources"); if (Directory.Exists(resourcesFolder)) { string[] resFiles = Directory.GetFiles(resourcesFolder); string[] resFolders = Directory.GetDirectories(resourcesFolder); foreach (var resFile in resFiles) { string destFile = Path.Combine("Resources", Path.GetFileName(resFile)); File.Copy(resFile, Path.Combine(pathToBuiltProject, destFile), true); project.AddFileToBuild( target, project.AddFile( destFile, destFile, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } foreach (var resFolder in resFolders) { string destFolder = Path.Combine("Resources", new DirectoryInfo(resFolder).Name); string destFolderFullPath = Path.Combine(pathToBuiltProject, destFolder); PlayServicesSupport.DeleteExistingFileOrDirectory( destFolderFullPath); Directory.Move(resFolder, destFolderFullPath); project.AddFileToBuild( target, project.AddFile( destFolder, destFolder, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } } foreach (var framework in frameworks) { project.AddFrameworkToProject(target, framework, false); } foreach (var linkFlag in linkFlags) { project.AddBuildProperty(target, "OTHER_LDFLAGS", linkFlag); } // Add all source files found under the pods directory to the project. // This is a very crude way of partially supporting source pods. var podPathToProjectPaths = new Dictionary <string, string>(); // Find pod source files and map them to paths relative to the target // Xcode project. foreach (var filename in FindFilesWithExtensions(podsDir, SOURCE_FILE_EXTENSIONS)) { // Save the path relative to the target project for each path // relative to the generated pods Xcode project. // +1 in the following expressions to strip the file separator. podPathToProjectPaths[filename.Substring(podsDir.Length + 1)] = filename.Substring(pathToBuiltProject.Length + 1); } // Add a reference to each source file in the target project. foreach (var podPathProjectPath in podPathToProjectPaths) { project.AddFileToBuild( target, project.AddFile(podPathProjectPath.Value, podPathProjectPath.Value, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } // Attempt to read per-file compile / build settings from the Pods // project. var podsProjectPath = GetProjectPath(podsDir, PODS_PROJECT_NAME); var podsProject = new UnityEditor.iOS.Xcode.PBXProject(); podsProject.ReadFromString(File.ReadAllText(podsProjectPath)); foreach (var directory in Directory.GetDirectories(podsDir)) { // Each pod will have a top level directory under the pods dir // named after the pod. Also, some pods have build targets in the // xcode project where each build target has the same name as the // pod such that pod Foo is in directory Foo with build target Foo. // Since we can't read the build targets from the generated Xcode // project using Unity's API, we scan the Xcode project for targets // to optionally retrieve build settings for each source file // the settings can be applied in the target project. var podTargetName = Path.GetFileName(directory); var podTargetGuid = podsProject.TargetGuidByName(podTargetName); Log(String.Format("Looking for target: {0} guid: {1}", podTargetName, podTargetGuid ?? "null"), verbose: true); if (podTargetGuid == null) { continue; } foreach (var podPathProjectPath in podPathToProjectPaths) { var podSourceFileGuid = podsProject.FindFileGuidByRealPath( podPathProjectPath.Key); if (podSourceFileGuid == null) { continue; } var podSourceFileCompileFlags = podsProject.GetCompileFlagsForFile(podTargetGuid, podSourceFileGuid); if (podSourceFileCompileFlags == null) { continue; } var targetSourceFileGuid = project.FindFileGuidByProjectPath( podPathProjectPath.Value); if (targetSourceFileGuid == null) { Log("Unable to find " + podPathProjectPath.Value + " in generated project", level: LogLevel.Warning); continue; } Log(String.Format( "Setting {0} compile flags to ({1})", podPathProjectPath.Key, String.Join(", ", podSourceFileCompileFlags.ToArray())), verbose: true); project.SetCompileFlagsForFile(target, targetSourceFileGuid, podSourceFileCompileFlags); } } File.WriteAllText(pbxprojPath, project.WriteToString()); }
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath) { if (buildTarget != BuildTarget.iOS) { return; } #if UNITY_IOS var proj = new UnityEditor.iOS.Xcode.PBXProject(); string projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(buildPath); proj.ReadFromFile(projPath); string target = proj.TargetGuidByName("Unity-iPhone"); string plistPath = buildPath + "/Info.plist"; var plist = new UnityEditor.iOS.Xcode.PlistDocument(); plist.ReadFromFile(plistPath); //获取所有的配置文件 string CONFIG_PATH = Application.dataPath + "/../SDK/iOS/"; List <Unity_Xcode_Json> jsons = new List <Unity_Xcode_Json>(); string[] files = Directory.GetFiles(CONFIG_PATH, "*.json", SearchOption.TopDirectoryOnly); for (int i = 0; i < files.Length; i++) { jsons.Add(JsonUtility.FromJson <Unity_Xcode_Json>(File.ReadAllText(files[i]))); } //创建资源目录 string frameworkPath = buildPath + "/Frameworks/Plugins/iOS/"; if (!Directory.Exists(frameworkPath)) { Directory.CreateDirectory(frameworkPath); } string aPath = buildPath + "/Libraries/Plugins/iOS/"; if (!Directory.Exists(aPath)) { Directory.CreateDirectory(aPath); } proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Frameworks/Plugins/iOS"); proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"); proj.SetBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)/Libraries/Plugins/iOS"); proj.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)/Libraries"); proj.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)"); proj.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(inherited)"); for (int i = 0; i < jsons.Count; i++) { Unity_Xcode_Json json = jsons[i]; //系统静态库引用 if (json.internal_frameworks != null) { for (int j = 0; j < json.internal_frameworks.Length; j++) { proj.AddFrameworkToProject(target, json.internal_frameworks[j], false); } } //系统动态库引用 if (json.internal_dynamiclibs != null) { for (int j = 0; j < json.internal_dynamiclibs.Length; j++) { proj.AddFileToBuild(target, proj.AddFile("usr/lib/" + json.internal_dynamiclibs[j], "Frameworks/" + json.internal_dynamiclibs[j], UnityEditor.iOS.Xcode.PBXSourceTree.Sdk)); } } //外部静态库引用 if (json.external_frameworks != null) { for (int j = 0; j < json.external_frameworks.Length; j++) { EditorUtils_Common.copy_files(CONFIG_PATH + json.external_frameworks[j], frameworkPath); string fileName = Path.GetFileName(json.external_frameworks[j]); proj.AddFileToBuild(target, proj.AddFile("Frameworks/Plugins/iOS/" + fileName, "Frameworks/" + fileName, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } //外部静态库引用 if (json.external_staticlibs != null) { for (int j = 0; j < json.external_staticlibs.Length; j++) { EditorUtils_Common.copy_files(CONFIG_PATH + json.external_staticlibs[j], aPath); string fileName = Path.GetFileName(json.external_staticlibs[j]); proj.AddFileToBuild(target, proj.AddFile("Libraries/Plugins/iOS/" + fileName, "Libraries/" + fileName, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } //外部文件引用 if (json.external_files != null) { for (int j = 0; j < json.external_files.Length; j++) { EditorUtils_Common.copy_files(CONFIG_PATH + json.external_files[j], aPath); string fileName = Path.GetFileName(json.external_files[j]); proj.AddFileToBuild(target, proj.AddFile("Libraries/Plugins/iOS/" + fileName, "Libraries/" + fileName, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } if (json.lib_searchpath != null) { for (int j = 0; j < json.lib_searchpath.Length; j++) { proj.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)/Libraries/Plugins/iOS/" + json.lib_searchpath[j]); } } if (json.framework_searchpath != null) { for (int j = 0; j < json.framework_searchpath.Length; j++) { proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Frameworks/Plugins/iOS/" + json.framework_searchpath[j]); } } //BuildSetting if (json.buildset_set != null) { for (int j = 0; j < json.buildset_set.Length; j++) { proj.SetBuildProperty(target, json.buildset_set[j].key, json.buildset_set[j].value); } } if (json.buildset_add != null) { for (int j = 0; j < json.buildset_add.Length; j++) { proj.UpdateBuildProperty(target, json.buildset_add[j].key, new List <string>() { json.buildset_add[j].value }, new List <string>()); } } //Info.plist if (json.plistset != null) { var dict = plist.root.AsDict(); for (int j = 0; j < json.plistset.Length; j++) { dict.SetString(json.plistset[j].key, json.plistset[j].value); } } if (json.plistarray != null) { var dict = plist.root.AsDict(); for (int j = 0; j < json.plistarray.Length; j++) { var array = dict.CreateArray(json.plistarray[j].key); for (int k = 0; k < json.plistarray[j].value.Length; k++) { array.AddString(json.plistarray[j].value[k]); } } } if (json.plistarraydict != null) { var dict = plist.root.AsDict(); for (int j = 0; j < json.plistarraydict.Length; j++) { var arrayDict = dict.CreateDict(json.plistarraydict[j].key); var array = arrayDict.CreateArray(json.plistarraydict[j].value.key); for (int k = 0; k < json.plistarraydict[j].value.value.Length; k++) { array.AddString(json.plistarraydict[j].value.value[k]); } } } } proj.WriteToFile(projPath); plist.WriteToFile(plistPath); #endif }
public static void OnPostProcessUpdateProjectDeps( BuildTarget buildTarget, string pathToBuiltProject) { if (!InjectDependencies()) return; // If the Pods directory does not exist, the pod download step // failed. var podsDir = Path.Combine(pathToBuiltProject, "Pods"); if (!Directory.Exists(podsDir)) return; Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Frameworks")); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Resources")); string pbxprojPath = GetProjectPath(pathToBuiltProject); var project = new UnityEditor.iOS.Xcode.PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string target = project.TargetGuidByName(TARGET_NAME); HashSet<string> frameworks = new HashSet<string>(); HashSet<string> linkFlags = new HashSet<string>(); foreach (var frameworkFullPath in Directory.GetDirectories(podsDir, "*.framework", SearchOption.AllDirectories)) { string frameworkName = new DirectoryInfo(frameworkFullPath).Name; string destFrameworkPath = Path.Combine("Frameworks", frameworkName); string destFrameworkFullPath = Path.Combine(pathToBuiltProject, destFrameworkPath); // Only move this framework if it contains a library. // Skip frameworks that consist of just resources, they're handled // in a separate import step. if (!File.Exists(Path.Combine( frameworkFullPath, Path.GetFileName(frameworkFullPath) .Replace(".framework", "")))) { continue; } PlayServicesSupport.DeleteExistingFileOrDirectory( destFrameworkFullPath); Directory.Move(frameworkFullPath, destFrameworkFullPath); project.AddFileToBuild( target, project.AddFile(destFrameworkPath, destFrameworkPath, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); string moduleMapPath = Path.Combine(Path.Combine(destFrameworkFullPath, "Modules"), "module.modulemap"); if (File.Exists(moduleMapPath)) { // Parse the modulemap, format spec here: // http://clang.llvm.org/docs/Modules.html#module-map-language using (StreamReader moduleMapFile = new StreamReader(moduleMapPath)) { string line; char[] delim = {' '}; while ((line = moduleMapFile.ReadLine()) != null) { string[] items = line.TrimStart(delim).Split(delim, 2); if (items.Length > 1) { if (items[0] == "link") { if (items[1].StartsWith("framework")) { items = items[1].Split(delim, 2); frameworks.Add(items[1].Trim( new char[] {'\"'}) + ".framework"); } else { linkFlags.Add("-l" + items[1]); } } } } } } string resourcesFolder = Path.Combine(destFrameworkFullPath, "Resources"); if (Directory.Exists(resourcesFolder)) { string[] resFiles = Directory.GetFiles(resourcesFolder); string[] resFolders = Directory.GetDirectories(resourcesFolder); foreach (var resFile in resFiles) { string destFile = Path.Combine("Resources", Path.GetFileName(resFile)); File.Copy(resFile, Path.Combine(pathToBuiltProject, destFile), true); project.AddFileToBuild( target, project.AddFile( destFile, destFile, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } foreach (var resFolder in resFolders) { string destFolder = Path.Combine("Resources", new DirectoryInfo(resFolder).Name); string destFolderFullPath = Path.Combine(pathToBuiltProject, destFolder); PlayServicesSupport.DeleteExistingFileOrDirectory( destFolderFullPath); Directory.Move(resFolder, destFolderFullPath); project.AddFileToBuild( target, project.AddFile( destFolder, destFolder, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } } foreach (var framework in frameworks) { project.AddFrameworkToProject(target, framework, false); } foreach (var linkFlag in linkFlags) { project.AddBuildProperty(target, "OTHER_LDFLAGS", linkFlag); } File.WriteAllText(pbxprojPath, project.WriteToString()); }
public static void OnPostProcessUpdateProjectDeps( BuildTarget buildTarget, string pathToBuiltProject) { if (!InjectDependencies()) { return; } // If the Pods directory does not exist, the pod download step // failed. var podsDir = Path.Combine(pathToBuiltProject, "Pods"); if (!Directory.Exists(podsDir)) { return; } Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Frameworks")); Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Resources")); string pbxprojPath = GetProjectPath(pathToBuiltProject); var project = new UnityEditor.iOS.Xcode.PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string target = project.TargetGuidByName(TARGET_NAME); HashSet <string> frameworks = new HashSet <string>(); HashSet <string> linkFlags = new HashSet <string>(); foreach (var frameworkFullPath in Directory.GetDirectories(podsDir, "*.framework", SearchOption.AllDirectories)) { string frameworkName = new DirectoryInfo(frameworkFullPath).Name; string destFrameworkPath = Path.Combine("Frameworks", frameworkName); string destFrameworkFullPath = Path.Combine(pathToBuiltProject, destFrameworkPath); // Only move this framework if it contains a library. // Skip frameworks that consist of just resources, they're handled // in a separate import step. if (!File.Exists(Path.Combine( frameworkFullPath, Path.GetFileName(frameworkFullPath) .Replace(".framework", "")))) { continue; } PlayServicesSupport.DeleteExistingFileOrDirectory( destFrameworkFullPath); Directory.Move(frameworkFullPath, destFrameworkFullPath); project.AddFileToBuild( target, project.AddFile(destFrameworkPath, destFrameworkPath, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); string moduleMapPath = Path.Combine(Path.Combine(destFrameworkFullPath, "Modules"), "module.modulemap"); if (File.Exists(moduleMapPath)) { // Parse the modulemap, format spec here: // http://clang.llvm.org/docs/Modules.html#module-map-language using (StreamReader moduleMapFile = new StreamReader(moduleMapPath)) { string line; char[] delim = { ' ' }; while ((line = moduleMapFile.ReadLine()) != null) { string[] items = line.TrimStart(delim).Split(delim, 2); if (items.Length > 1) { if (items[0] == "link") { if (items[1].StartsWith("framework")) { items = items[1].Split(delim, 2); frameworks.Add(items[1].Trim( new char[] { '\"' }) + ".framework"); } else { linkFlags.Add("-l" + items[1]); } } } } } } string resourcesFolder = Path.Combine(destFrameworkFullPath, "Resources"); if (Directory.Exists(resourcesFolder)) { string[] resFiles = Directory.GetFiles(resourcesFolder); string[] resFolders = Directory.GetDirectories(resourcesFolder); foreach (var resFile in resFiles) { string destFile = Path.Combine("Resources", Path.GetFileName(resFile)); File.Copy(resFile, Path.Combine(pathToBuiltProject, destFile), true); project.AddFileToBuild( target, project.AddFile( destFile, destFile, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } foreach (var resFolder in resFolders) { string destFolder = Path.Combine("Resources", new DirectoryInfo(resFolder).Name); string destFolderFullPath = Path.Combine(pathToBuiltProject, destFolder); PlayServicesSupport.DeleteExistingFileOrDirectory( destFolderFullPath); Directory.Move(resFolder, destFolderFullPath); project.AddFileToBuild( target, project.AddFile( destFolder, destFolder, UnityEditor.iOS.Xcode.PBXSourceTree.Source)); } } } foreach (var framework in frameworks) { project.AddFrameworkToProject(target, framework, false); } foreach (var linkFlag in linkFlags) { project.AddBuildProperty(target, "OTHER_LDFLAGS", linkFlag); } File.WriteAllText(pbxprojPath, project.WriteToString()); }