//添加 bundle private static void AddBundle(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj) { SearchOption searchOption; if (secondFilePath.Contains("/ShareSDK/")) //shareSDK { searchOption = SearchOption.TopDirectoryOnly; } else { searchOption = SearchOption.AllDirectories; } string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.bundle", searchOption); foreach (string lastFilePath in secondDirectories) { if (secondFilePath.EndsWith("SDK/ShareSDK") && lastFilePath.Contains("Support/PlatformSDK")) { continue; } // Debug.Log("lastFilePath" + lastFilePath); string bundlePath = lastFilePath.Replace(pathModel.rootPath, ""); // Debug.Log("bundlePath" + bundlePath); string savePath = xcodeTargetPath + bundlePath; //将 framework copy到指定目录 DirectoryInfo bundleInfo = new DirectoryInfo(lastFilePath); DirectoryInfo saveBundleInfo = new DirectoryInfo(savePath); CopyAll(bundleInfo, saveBundleInfo); //将 framework 加入 proj中 xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + bundlePath, PBXSourceTree.Sdk)); } }
//添加 Framework private static void AddFramework(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj, ref bool hasMobFramework) { SearchOption searchOption; if (secondFilePath.Contains("/ShareSDK/")) //shareSDK { searchOption = SearchOption.TopDirectoryOnly; } else { searchOption = SearchOption.AllDirectories; } string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.framework", searchOption); foreach (string lastFilePath in secondDirectories) { // Debug.Log("lastFilePath" + lastFilePath); int index = lastFilePath.LastIndexOf("/"); //framework 名称 string frameworkName = lastFilePath.Substring(index + 1); // Debug.Log("frameworkName" + frameworkName); bool isMOBFoundation = (frameworkName == "MOBFoundation.framework"); if (!isMOBFoundation || (isMOBFoundation && !hasMobFramework)) { if (isMOBFoundation && !hasMobFramework) { // Debug.Log("isMOBFoundation " + lastFilePath); hasMobFramework = true; } string frameworkPath = lastFilePath.Replace(pathModel.rootPath, ""); // Debug.Log("frameworkPath" + frameworkPath); string savePath = xcodeTargetPath + frameworkPath; int tempIndex = frameworkPath.LastIndexOf("/"); string saveFrameworkPath = frameworkPath.Substring(0, tempIndex); //将 framework copy到指定目录AddURLSchemes DirectoryInfo frameworkInfo = new DirectoryInfo(lastFilePath); DirectoryInfo saveFrameworkInfo = new DirectoryInfo(savePath); CopyAll(frameworkInfo, saveFrameworkInfo); //将 framework 加入 proj中 xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + frameworkPath, PBXSourceTree.Sdk)); //将 build setting 设置 xcodeProj.AddBuildProperty(xcodeTargetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)" + saveFrameworkPath); } } }
//添加 .a文件 private static void AddStaticLibrary(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj) { // SearchOption searchOption; // if (secondFilePath.Contains ("/ShareSDK/")) //shareSDK // { // searchOption = SearchOption.TopDirectoryOnly; // } // else // { // searchOption = SearchOption.AllDirectories; // } string[] secondDirectories = Directory.GetFiles(secondFilePath, "*.a", SearchOption.AllDirectories); foreach (string lastFilePath in secondDirectories) { if (secondFilePath.EndsWith("SDK/ShareSDK") && lastFilePath.Contains("Support/PlatformSDK")) { continue; } string staticLibraryPath = lastFilePath.Replace(pathModel.rootPath, ""); int index = staticLibraryPath.LastIndexOf("/"); //项目目录 string saveStaticLibraryPath = staticLibraryPath.Substring(0, index); //存放的本地目录 string saveDirectory = xcodeTargetPath + saveStaticLibraryPath; if (!Directory.Exists(saveDirectory)) { Directory.CreateDirectory(saveDirectory); } //将.a copy到指定目录 FileInfo fileInfo = new FileInfo(lastFilePath); string savePath = xcodeTargetPath + staticLibraryPath; fileInfo.CopyTo(savePath, true); //将.a 加入 proj中 xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + staticLibraryPath, PBXSourceTree.Sdk)); //将 build setting 设置 xcodeProj.AddBuildProperty(xcodeTargetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)" + saveStaticLibraryPath); } }
//添加 .h文件 private static void AddHeader(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj) { string[] secondDirectories = Directory.GetFiles(secondFilePath, "*.h", SearchOption.AllDirectories); ArrayList savePathArray = new ArrayList(); foreach (string lastFilePath in secondDirectories) { if (secondFilePath.EndsWith("SDK/ShareSDK") && lastFilePath.Contains("Support/PlatformSDK")) { continue; } if (!lastFilePath.Contains(".framework")) { string headerPath = lastFilePath.Replace(pathModel.rootPath, ""); int index = headerPath.LastIndexOf("/"); //项目目录 string saveHeaderPath = headerPath.Substring(0, index); //存放的本地目录 string saveDirectory = xcodeTargetPath + saveHeaderPath; if (!Directory.Exists(saveDirectory)) { Directory.CreateDirectory(saveDirectory); } //将.h copy到指定目录 FileInfo fileInfo = new FileInfo(lastFilePath); string savePath = xcodeTargetPath + headerPath; fileInfo.CopyTo(savePath, true); //将.h 加入 proj中 xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + headerPath, PBXSourceTree.Source)); if (!savePathArray.Contains(saveHeaderPath)) { savePathArray.Add(saveHeaderPath); //将 build setting 设置 xcodeProj.AddBuildProperty(xcodeTargetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)" + saveHeaderPath); } } } }
//添加其他资源 private static void AddOtherFile(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj, Hashtable fileFlags) { string[] secondDirectories = Directory.GetFiles(secondFilePath, "*", SearchOption.AllDirectories); foreach (string lastFilePath in secondDirectories) { if (secondFilePath.EndsWith("SDK/ShareSDK") && lastFilePath.Contains("Support/PlatformSDK")) { continue; } // Debug.LogWarning("lastFilePath:" + lastFilePath); if (!lastFilePath.Contains(".framework") && !lastFilePath.Contains(".a") && !lastFilePath.Contains(".h") && !lastFilePath.Contains(".bundle") && !lastFilePath.Contains(".DS_Store") && !lastFilePath.Contains(".meta")) { string otherFilePath = lastFilePath.Replace(pathModel.rootPath, ""); int index = otherFilePath.LastIndexOf("/"); //项目目录 string saveOtherFilePath = otherFilePath.Substring(0, index); string fileName = otherFilePath.Substring(index + 1); //存放的本地目录 string saveDirectory = xcodeTargetPath + saveOtherFilePath; if (!Directory.Exists(saveDirectory)) { Directory.CreateDirectory(saveDirectory); } //将其他文件拷贝到指定目录 FileInfo fileInfo = new FileInfo(lastFilePath); string savePath = xcodeTargetPath + otherFilePath; fileInfo.CopyTo(savePath, true); //将.a 加入 proj中 Debug.LogWarning(savePath); if (fileFlags.ContainsKey(fileName)) { string flag = (string)fileFlags[fileName]; Debug.Log(flag); xcodeProj.AddFileToBuildWithFlags(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + otherFilePath, PBXSourceTree.Source), flag); } else { xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + otherFilePath, PBXSourceTree.Source)); } } } }
//添加 .a文件 private static void AddStaticLibrary(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj) { string[] secondDirectories = Directory.GetFiles(secondFilePath, "*.a", SearchOption.AllDirectories); foreach (string lastFilePath in secondDirectories) { // Debug.Log("lastFilePath" + lastFilePath); string staticLibraryPath = lastFilePath.Replace(pathModel.rootPath, ""); int index = staticLibraryPath.LastIndexOf("/"); //项目目录 string saveStaticLibraryPath = staticLibraryPath.Substring(0, index); //存放的本地目录 string saveDirectory = xcodeTargetPath + saveStaticLibraryPath; if (!Directory.Exists(saveDirectory)) { Directory.CreateDirectory(saveDirectory); } //将.a copy到指定目录 FileInfo fileInfo = new FileInfo(lastFilePath); string savePath = xcodeTargetPath + staticLibraryPath; fileInfo.CopyTo(savePath, true); //将.a 加入 proj中 xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + staticLibraryPath, PBXSourceTree.Sdk)); //将 build setting 设置 xcodeProj.AddBuildProperty(xcodeTargetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)" + saveStaticLibraryPath); } }
//添加 Framework private static void AddFramework(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, string xcodeFrameworkTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj, ref bool hasMobFramework, MOBXCodeEditorModel editModel) { SearchOption searchOption; if (secondFilePath.Contains("/ShareSDK/") || secondFilePath.Contains("\\ShareSDK\\") || secondFilePath.Contains("/ShareSDK\\")) //shareSDK { searchOption = SearchOption.TopDirectoryOnly; } else { searchOption = SearchOption.AllDirectories; } string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.framework", searchOption); foreach (string lastFilePath in secondDirectories) { // Debug.Log("lastFilePath" + lastFilePath); int index = lastFilePath.LastIndexOf("\\"); int fileNameIndex = 2; if (index == -1) { fileNameIndex = 1; index = lastFilePath.LastIndexOf("/"); } //framework 名称 string frameworkName = lastFilePath.Substring(index + fileNameIndex); // Debug.Log("frameworkName" + frameworkName); bool isMOBFoundation = (frameworkName == "MOBFoundation.framework"); if (!isMOBFoundation || (isMOBFoundation && !hasMobFramework)) { if (isMOBFoundation && !hasMobFramework) { // Debug.Log("isMOBFoundation " + lastFilePath); hasMobFramework = true; } string frameworkPath = lastFilePath.Replace(pathModel.rootPath, ""); // Debug.Log("frameworkPath" + frameworkPath); string savePath = xcodeTargetPath + frameworkPath; int tempIndex = frameworkPath.LastIndexOf("\\"); if (tempIndex == -1) { tempIndex = frameworkPath.LastIndexOf("/"); } string saveFrameworkPath = frameworkPath.Substring(0, tempIndex); string targetGuid = xcodeFrameworkTargetGuid; //将 framework copy到指定目录AddURLSchemes DirectoryInfo frameworkInfo = new DirectoryInfo(lastFilePath); DirectoryInfo saveFrameworkInfo = new DirectoryInfo(savePath); CopyAll(frameworkInfo, saveFrameworkInfo); //将 framework 加入 proj中 if (frameworkName == "ShareSDKLink.framework" && !editModel.isOpenRestoreScene) { continue; } string fileGuid = (string)xcodeProj.AddFile(frameworkPath.Substring(1), "MOB" + frameworkPath, PBXSourceTree.Absolute); string[] dynamicframework = { "OasisSDK.framework", "SCSDKCreativeKit.framework", "SCSDKLoginKit.framework", "SCSDKCoreKit.framework" }; int dynamicIndex = Array.IndexOf(dynamicframework, frameworkName); if (dynamicIndex >= 0) { targetGuid = xcodeTargetGuid; xcodeProj.AddFileToBuildSection(targetGuid, xcodeProj.AddFrameworksBuildPhase(targetGuid), fileGuid); #if UNITY_2019_3_OR_NEWER xcodeProj.AddFileToEmbedFrameworks(targetGuid, fileGuid, targetGuid); #endif } else { xcodeProj.AddFileToBuildSection(targetGuid, xcodeProj.AddFrameworksBuildPhase(targetGuid), fileGuid); } //将 build setting 设置 xcodeProj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)" + saveFrameworkPath.Replace("\\", "/")); } } }