//设置libs private static void SetLibs(PBXProject proj, Hashtable table) { if (table != null) { string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); ArrayList addList = table["+"] as ArrayList; if (addList != null) { foreach (string i in addList) { AddLibToProject(proj, target, i); } } ArrayList removeList = table["-"] as ArrayList; if (removeList != null) { foreach (string i in removeList) { RemoveLibFromProject(proj, target, i); } } } }
//设置frameworks private static void SetFrameworks(PBXProject proj, Hashtable table) { if (table != null) { string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); ArrayList addList = table["+"] as ArrayList; if (addList != null) { foreach (string i in addList) { proj.AddFrameworkToProject(target, i, false); } } ArrayList removeList = table["-"] as ArrayList; if (removeList != null) { foreach (string i in removeList) { proj.RemoveFrameworkFromProject(target, i); } } } }
public static void OnPostprocessBuild(string xcodePath, string configPath) { pluginPath = configPath.Replace("XcodeSetting.json", ""); string projPath = PBXProject.GetPBXProjectPath(xcodePath); PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(projPath)); string plistPath = xcodePath + "/Info.plist"; PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); PlistElementDict rootDict = plist.root; string productName = GetProductName(xcodePath); string entitlementFilePath = Path.Combine(PBXProject.GetUnityTargetName(), productName + ".entitlements"); ProjectCapabilityManager pcbManager = new ProjectCapabilityManager(proj, projPath, entitlementFilePath, PBXProject.GetUnityTargetName()); //读取配置文件 string json = File.ReadAllText(configPath); Hashtable table = json.hashtableFromJson(); embedFrameworksTable = table.SGet <Hashtable>("embedframeworks"); //plist SetPlist(proj, rootDict, table.SGet <Hashtable>("plist")); plist.WriteToFile(plistPath); //lib SetLibs(proj, table.SGet <Hashtable>("libs")); //framework SetFrameworks(proj, table.SGet <Hashtable>("frameworks")); //building setting SetBuildProperties(proj, table.SGet <Hashtable>("properties")); SetShellScriptBuildPhase(proj, table.SGet <Hashtable>("runscript")); //复制文件 CopyFiles(proj, xcodePath, table.SGet <Hashtable>("files")); //复制文件夹 CopyFolders(proj, xcodePath, table.SGet <Hashtable>("folders")); //文件编译符号 SetFilesCompileFlag(proj, table.SGet <Hashtable>("filesCompileFlag")); //加入能力 SetCapabilitys(pcbManager, table.SGet <Hashtable>("capabilitys")); //写入 File.WriteAllText(projPath, proj.WriteToString()); Console.WriteLine("***Info.plist*****\n" + File.ReadAllText(plistPath)); }