public void OnPostprocessBuild(BuildReport report) { var summary = report.summary; if (summary.platform == BuildTarget.iOS) { var appTrackingTransparencySettings = AppTrackingTransparencySettingsManager.LoadSettings(); if (!appTrackingTransparencySettings.AutomaticPostProcessing) { return; } var projectPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(summary.outputPath); var pbxProject = new UnityEditor.iOS.Xcode.PBXProject(); pbxProject.ReadFromFile(projectPath); #if UNITY_2019_3_OR_NEWER var frameworkTargetGuid = pbxProject.GetUnityFrameworkTargetGuid(); var mainTargetGuid = pbxProject.GetUnityMainTargetGuid(); #else var frameworkTargetGuid = pbxProject.GetUnityTargetName(); var mainTargetGuid = pbxProject.GetUnityTargetName(); #endif if (appTrackingTransparencySettings.AddAppTransparencyTrackingFramework) { pbxProject.AddFrameworkToProject(frameworkTargetGuid, "AppTrackingTransparency.framework", true); } if (appTrackingTransparencySettings.AddUserTrackingUsageDescription) { string infoPlistPath; if (appTrackingTransparencySettings.AutoDetectInfoPlistFilePath) { infoPlistPath = Path.Combine( summary.outputPath, pbxProject.GetBuildPropertyForAnyConfig(mainTargetGuid, "INFOPLIST_FILE")); } else { infoPlistPath = Path.Combine( summary.outputPath, appTrackingTransparencySettings.MainInfoPlistFilePath); } var infoPlist = new UnityEditor.iOS.Xcode.PlistDocument(); infoPlist.ReadFromFile(infoPlistPath); infoPlist.root.SetString("NSUserTrackingUsageDescription", appTrackingTransparencySettings.UserTrackingUsageDescription); infoPlist.WriteToFile(infoPlistPath); } pbxProject.WriteToFile(projectPath); } }
public void OnPostprocessBuild(BuildTarget InTarget, string InPath) { if (InTarget == BuildTarget.iOS) { #if UNITY_IOS string plistPath = Path.Combine(InPath, "Info.plist"); UnityEditor.iOS.Xcode.PlistDocument plist = new UnityEditor.iOS.Xcode.PlistDocument(); plist.ReadFromFile(plistPath); plist.root.SetString("GADApplicationIdentifier", AdManager.AD_APP_ID); File.WriteAllText(plistPath, plist.WriteToString()); #endif } }
private static void CreateExportPlist(string method) { string path = string.Format("{0}{1}.plist", Constant.Path.Project, method); var plist = new UnityEditor.iOS.Xcode.PlistDocument(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } plist.root.SetString("method", method); plist.root.SetString("teamID", PlayerSettings.iOS.appleDeveloperTeamID); plist.root.SetBoolean("compileBitcode", false); plist.WriteToFile(path); }
private static void CreateXcodeProjectPlist() { var plist = new UnityEditor.iOS.Xcode.PlistDocument(); if (System.IO.File.Exists(Constant.Path.XcodeProjectPlist)) { plist.ReadFromFile(Constant.Path.XcodeProjectPlist); } else { plist.WriteToFile(Constant.Path.XcodeProjectPlist); } // '수출 규정 관련 문서가 누락됨' 방지 코드 plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false); plist.WriteToFile(Constant.Path.XcodeProjectPlist); }
public static void UpdateInfoPList(BuildTarget buildTarget, string pathToBuiltProject) { if (buildTarget != BuildTarget.iOS) return; var settings = InputSystem.settings.iOS; if (!settings.motionUsage.enabled) return; var plistPath = pathToBuiltProject + "/Info.plist"; var contents = File.ReadAllText(plistPath); var description = InputSystem.settings.iOS.motionUsage.usageDescription; #if UNITY_IOS || UNITY_TVOS var plist = new UnityEditor.iOS.Xcode.PlistDocument(); plist.ReadFromString(contents); var root = plist.root; var buildKey = "NSMotionUsageDescription"; if (root[buildKey] != null) Debug.LogWarning($"{buildKey} is already present in Info.plist, the value will be overwritten."); root.SetString(buildKey, description); File.WriteAllText(plistPath, plist.WriteToString()); #endif }
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 }
private static void CheckCommandLine(BuildTargetGroup buildTargetGroup) { var args = System.Environment.GetCommandLineArgs(); if (null != args) { for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (i + 1 < args.Length) { string argValue = args[i + 1]; switch (arg) { case "-bundleIdentifier": { PlayerSettings.applicationIdentifier = argValue; PlayerSettings.SetApplicationIdentifier(buildTargetGroup, argValue); } break; case "-buildNumber": { int buildNumber = 0; if (int.TryParse(argValue, out buildNumber)) { string bundleVersion = PlayerSettings.bundleVersion; PlayerSettings.Android.bundleVersionCode = buildNumber; PlayerSettings.iOS.buildNumber = PlayerSettings.Android.bundleVersionCode.ToString(); PlayerSettings.bundleVersion = bundleVersion + "." + buildNumber; } } break; case "-appleDeveloperTeamID": { PlayerSettings.iOS.appleEnableAutomaticSigning = true; PlayerSettings.iOS.appleDeveloperTeamID = argValue; } break; case "-iOSManualProvisioningProfileID": { PlayerSettings.iOS.iOSManualProvisioningProfileID = argValue; } break; case "-keystoreName": { PlayerSettings.Android.keystoreName = argValue; } break; case "-keystorePass": { PlayerSettings.Android.keystorePass = argValue; } break; case "-keyaliasName": { PlayerSettings.Android.keyaliasName = argValue; } break; case "-AndroidSdkRoot": { EditorPrefs.SetString("AndroidSdkRoot", argValue); } break; case "-AndroidNdkRoot": { EditorPrefs.SetString("AndroidNdkRoot", argValue); } break; case "-JdkPath": { EditorPrefs.SetString("JdkPath", argValue); } break; case "-ScriptingImplementation": { ScriptingImplementation scriptingImplementation = default(ScriptingImplementation); switch (argValue) { case "mono2x": scriptingImplementation = ScriptingImplementation.Mono2x; break; case "il2cpp": scriptingImplementation = ScriptingImplementation.IL2CPP; break; case "winrtdotnet": scriptingImplementation = ScriptingImplementation.WinRTDotNET; break; } PlayerSettings.SetScriptingBackend(buildTargetGroup, ScriptingImplementation.Mono2x); } break; case "-plist": { string path = string.Format("{0}{1}.plist", Constant.Path.Project, "exportOptionsPlist"); var plist = new UnityEditor.iOS.Xcode.PlistDocument(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } try { string[] dicts = argValue.Split(','); foreach (var dict in dicts) { string[] keyValue = dict.Split(':'); string key = keyValue[0]; string value = keyValue[1]; switch (key) { case "method": case "teamID": case "signingStyle": case "signingCertificate": plist.root.SetString(key, value); break; case "compileBitcode": case "ITSAppUsesNonExemptEncryption": plist.root.SetBoolean(key, bool.Parse(value)); break; case "provisioningProfiles": var provisioningProfiles = plist.root.CreateDict(key); var provisioningProfilesKeyValue = value.Split('@'); provisioningProfiles.SetString(provisioningProfilesKeyValue[0], provisioningProfilesKeyValue[1]); break; } } } catch (Exception e) { Debug.LogWarning(e.ToString()); } plist.WriteToFile(path); } break; } } } } }