public void AddMultipleSourceFilesWorks() { ResetGuidGenerator(); PBXProject proj = ReadPBXProject(); string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); // check addition of relative path proj.AddFileToBuild(target, proj.AddFile("relative/path1.cc", "Classes/some/path/path1.cc", PBXSourceTree.Source)); // check addition of absolute path proj.AddFileToBuild(target, proj.AddFile("/absolute/path/abs1.cc", "Classes/some/path/abs1.cc", PBXSourceTree.Source)); proj.AddFileToBuild(target, proj.AddFile("/absolute/path/abs2.cc", "Classes/some/abs2.cc", PBXSourceTree.Source)); // check addition of files with unknown extensions proj.AddFileToBuild(target, proj.AddFile("relative/path1.unknown_ext", "Classes/some/path/path1.unknown_ext", PBXSourceTree.Source)); // check whether folder references work proj.AddFileToBuild(target, proj.AddFolderReference("relative/path2", "Classes/some/path/path2", PBXSourceTree.Source)); // check whether we correctly add folder references with weird extensions to resources proj.AddFileToBuild(target, proj.AddFolderReference("relative/path3.cc", "Classes/some/path/path3.cc", PBXSourceTree.Source)); // check whether we correctly add files which are not buildable proj.AddFileToBuild(target, proj.AddFolderReference("relative/lib.dll", "Classes/some/path/lib.dll", PBXSourceTree.Source)); Assert.IsTrue(proj.FindFileGuidByRealPath("relative/path1.cc") == "CCCCCCCC0000000000000001"); Assert.IsTrue(proj.FindFileGuidByRealPath("/absolute/path/abs1.cc") == "CCCCCCCC0000000000000005"); Assert.IsTrue(proj.FindFileGuidByProjectPath("Classes/some/path/abs1.cc") == "CCCCCCCC0000000000000005"); Assert.AreEqual(1, proj.GetGroupChildrenFiles("Classes/some").Count); TestOutput(proj, "add_file2.pbxproj"); }
internal static void CopyAndReplaceDirectory(string srcPath, string dstPath) { if (Directory.Exists(dstPath)) { Directory.Delete(dstPath); } if (File.Exists(dstPath)) { File.Delete(dstPath); } Directory.CreateDirectory(dstPath); foreach (var file in Directory.GetFiles(srcPath)) { File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file))); //ignore useless files for 'Copy Bundle Resources' if (!file.Contains(".DS_Store") && !file.Contains(".framework")) { proj.AddFileToBuild(targetGuid, proj.AddFile(Path.Combine(dstPath, Path.GetFileName(file)), Path.Combine(dstPath, Path.GetFileName(file)), PBXSourceTree.Source)); } } foreach (var dir in Directory.GetDirectories(srcPath)) { CopyAndReplaceDirectory(dir, Path.Combine(dstPath, Path.GetFileName(dir))); if (Path.GetFileName(dir).Contains(".bundle")) { proj.AddFolderReference(Path.Combine(dstPath, Path.GetFileName(dir)), Path.Combine(dstPath, Path.GetFileName(dir)), PBXSourceTree.Source); proj.AddFileToBuild(targetGuid, proj.AddFile(Path.Combine(dstPath, Path.GetFileName(dir)), Path.Combine(dstPath, Path.GetFileName(dir)), PBXSourceTree.Source)); } } }
private static void EditProject(string pathToBuild) { // Edit Unity-iPhone proj var pbx = new PBXProject(); var pbxPath = Path.Combine(pathToBuild, "Unity-iPhone.xcodeproj/project.pbxproj"); if (!File.Exists(pbxPath)) { Debug.LogWarning($"PBX not found, skipping EditProject. Path: {pbxPath}"); return; } pbx.ReadFromFile(pbxPath); var guidUnityFrameworkTarget = pbx.GetUnityFrameworkTargetGuid(); var guidFile = pbx.AddFolderReference(Path.Combine(pathToBuild, "Data"), "Data"); pbx.AddFileToBuild(guidUnityFrameworkTarget, guidFile); pbx.SetBuildProperty(guidUnityFrameworkTarget, "ENABLE_BITCODE", "NO"); pbx.UpdateBuildProperty(guidUnityFrameworkTarget, "OTHER_LDFLAGS", new[] { "-Wl,-U,_FlutterUnityPluginOnMessage" }, null); pbx.WriteToFile(pbxPath); Debug.Log("Editing build settings completed"); }
static void AddGoogleMapsBundleToProjectResources(string path, PBXProject project, string targetGUID, string sourcePath, string destPath) { var resourceBundlePath = Path.Combine(path, sourcePath); var addFolderReference = project.AddFolderReference(resourceBundlePath, destPath, PBXSourceTree.Absolute); project.AddFileToBuild(targetGUID, addFolderReference); }
/// <summary> /// Enumerates Unity output files and add necessary files into Xcode project file. /// It only add a reference entry into project.pbx file, without actually copy it. /// Xcode pre-build script will copy files into correct location. /// </summary> private static void UpdateUnityProjectFiles(string pathToBuiltProject) { var pbx = new PBXProject(); var pbxPath = Path.Combine(XcodeProjectRoot, PbxFilePath); pbx.ReadFromFile(pbxPath); // Add UnityExport/Classes ProcessUnityDirectory( pbx, Path.Combine(pathToBuiltProject, "Classes"), Path.Combine(XcodeProjectRoot, ClassesProjectPath), ClassesProjectPath); // Add UnityExport/Libraries ProcessUnityDirectory( pbx, Path.Combine(pathToBuiltProject, "Libraries"), Path.Combine(XcodeProjectRoot, LibrariesProjectPath), LibrariesProjectPath); // Add UnityExport/Data var targetGuid = pbx.TargetGuidByName(XcodeProjectName); var fileGuid = pbx.AddFolderReference(Path.Combine(pathToBuiltProject, "Data"), DataProjectPath); pbx.AddFileToBuild(targetGuid, fileGuid); pbx.WriteToFile(pbxPath); }
/// <summary> /// Make necessary changes to Unity build output that enables it to be embedded into existing Xcode project. /// </summary> private static void PatchRemoveTargetMembership(string pathToBuiltProject) { var pbx2 = new PBXProject(); var pbxPath2 = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj"); pbx2.ReadFromFile(pbxPath2); var pbx = new PBXProject(); var pbxPath = Path.Combine(flutterAppPath, "Runner.xcodeproj/project.pbxproj"); pbx.ReadFromFile(pbxPath); // Add unityLibrary/Data var targetGuid = pbx2.TargetGuidByName("UnityFramework"); var fileGuid = pbx.AddFolderReference(Path.Combine(pathToBuiltProject, "Data"), "Data"); string appTargetGUID = pbx.TargetGuidByName("Runner"); Debug.Log(appTargetGUID); pbx.AddFrameworkToProject(appTargetGUID, "UnityFramework", false); // pbx.AddFileToBuild(targetGuid, fileGuid); pbx.WriteToFile(pbxPath); Debug.Log("Build mang console"); }
static void AddReferenceObjectAssetToResourceGroup(ARReferenceObjectAsset arro, string parentFolderFullPath, string projectRelativePath, PBXProject project) { ARReferenceObjectResourceContents resourceContents = new ARReferenceObjectResourceContents(); resourceContents.info = new ARResourceInfo(); resourceContents.info.author = "unity"; resourceContents.info.version = 1; resourceContents.objects = new ARResourceFilename[1]; resourceContents.objects [0] = new ARResourceFilename(); resourceContents.objects [0].idiom = "universal"; //add folder for reference image string folderToCreate = arro.objectName + ".arreferenceobject"; string folderFullPath = Path.Combine(parentFolderFullPath, folderToCreate); string projectRelativeFolder = Path.Combine(projectRelativePath, folderToCreate); Directory.CreateDirectory(folderFullPath); project.AddFolderReference(folderFullPath, projectRelativeFolder); //copy file from texture asset string objectPath = AssetDatabase.GetAssetPath(arro.referenceObject); string objectFilename = Path.GetFileName(objectPath); var dstPath = Path.Combine(folderFullPath, objectFilename); File.Copy(objectPath, dstPath, true); project.AddFile(dstPath, Path.Combine(projectRelativeFolder, objectFilename)); resourceContents.objects [0].filename = objectFilename; //add contents.json file string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json"); File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(resourceContents, true)); project.AddFile(contentsJsonPath, Path.Combine(projectRelativeFolder, "Contents.json")); }
/// <summary> /// 添加本地化程序名等配置 /// </summary> static void AddLocaleConfig(PBXProject pbxProject, string targetGuid, string projectPath) { string localePath = projectPath + "/Unity-iPhone"; var cfg = BundleLocaleConfig.ReadConfig(); var dirs = cfg.CreateFiles(localePath); foreach (var dir in dirs) { var guid = pbxProject.AddFolderReference(dir, Path.GetFileName(dir)); pbxProject.AddFileToBuild(targetGuid, guid); } }
/// <summary> /// We need to add the Data folder to the UnityFramework framework /// </summary> private static void UpdateUnityProjectFiles(string pathToBuiltProject) { var pbx = new PBXProject(); var pbxPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj"); pbx.ReadFromFile(pbxPath); // Add UnityExport/Data var targetGuid = pbx.TargetGuidByName("UnityFramework"); var fileGuid = pbx.AddFolderReference(Path.Combine(pathToBuiltProject, "Data"), "Data"); pbx.AddFileToBuild(targetGuid, fileGuid); pbx.WriteToFile(pbxPath); }
/// <summary> /// Enumerates Unity output files and add necessary files into Xcode project file. /// It only add a reference entry into project.pbx file, without actually copy it. /// Xcode pre-build script will copy files into correct location. /// </summary> private static void UpdateUnityProjectFiles(string pathToBuiltProject) { var pbx = new PBXProject(); var pbxPath = Path.Combine(XcodeProjectRoot, PbxFilePath); pbx.ReadFromFile(pbxPath); // Add UnityExport/Classes ProcessUnityDirectory( pbx, Path.Combine(pathToBuiltProject, "Classes"), Path.Combine(XcodeProjectRoot, ClassesProjectPath), ClassesProjectPath); // Add UnityExport/Libraries ProcessUnityDirectory( pbx, Path.Combine(pathToBuiltProject, "Libraries"), Path.Combine(XcodeProjectRoot, LibrariesProjectPath), LibrariesProjectPath); var targetGuid = pbx.TargetGuidByName(XcodeProjectName); // Add UnityExport/Data var fileGuid = pbx.AddFolderReference(Path.Combine(pathToBuiltProject, "Data"), DataProjectPath); pbx.AddFileToBuild(targetGuid, fileGuid); // Add UnityExport/Vuforia dir(if exists) var vuforiaDataDir = Path.Combine(pathToBuiltProject, "Data/Raw/Vuforia"); if (Directory.Exists(vuforiaDataDir)) //check if vuforia exists in the data folder. { pbx.AddFileToBuild(targetGuid, pbx.AddFolderReference(vuforiaDataDir, VuforiaDataProjectPath)); } pbx.WriteToFile(pbxPath); }
public static void OnPostProcess(BuildTarget buildTarget, string buildPath) { if (buildTarget != BuildTarget.iOS) { return; } //creating instance of scriptable object to get file path var instance = CreateInstance <QuickActionsIconsPostProcess>(); var iconSet = instance.ImageFolder; DestroyImmediate(instance); if (iconSet == null) { return; } //get all files in given directory var filesInDirectory = Directory.GetFiles(AssetDatabase.GetAssetPath(iconSet), "*.png", SearchOption.TopDirectoryOnly); //get all needed paths var projectPath = PBXProject.GetPBXProjectPath(buildPath); var xCodeProject = new PBXProject(); xCodeProject.ReadFromFile(projectPath); var targetName = PBXProject.GetUnityTargetName(); var targetGUID = xCodeProject.TargetGuidByName(targetName); var destinationPath = buildPath + "/"; //copy each file in directory to xCode project foreach (var file in filesInDirectory) { var nameAndExtension = file.Split('/').LastOrDefault(); var assetLocation = AssetDatabase.GetAssetPath(iconSet) + "/" + nameAndExtension; var assetDestination = destinationPath + nameAndExtension; FileUtil.CopyFileOrDirectory(assetLocation, assetDestination); var grGUID = xCodeProject.AddFolderReference(destinationPath + nameAndExtension, nameAndExtension); xCodeProject.AddFileToBuild(targetGUID, grGUID); } xCodeProject.WriteToFile(projectPath); }
static void AddReferenceImageToResourceGroup(ARReferenceImage arri, string parentFolderFullPath, string projectRelativePath, PBXProject project) { ARResourceContents resourceContents = new ARResourceContents(); resourceContents.info = new ARResourceInfo(); resourceContents.info.author = "xcode"; resourceContents.info.version = 1; resourceContents.images = new ARResourceImage[1]; resourceContents.images [0] = new ARResourceImage(); resourceContents.images [0].idiom = "universal"; resourceContents.properties = new ARResourceProperties(); resourceContents.properties.width = arri.physicalSize; //add folder for reference image string folderToCreate = arri.imageName + ".arreferenceimage"; string folderFullPath = Path.Combine(parentFolderFullPath, folderToCreate); string projectRelativeFolder = Path.Combine(projectRelativePath, folderToCreate); Directory.CreateDirectory(folderFullPath); project.AddFolderReference(folderFullPath, projectRelativeFolder); //copy file from texture asset string imagePath = AssetDatabase.GetAssetPath(arri.imageTexture); string imageFilename = Path.GetFileName(imagePath); var dstPath = Path.Combine(folderFullPath, imageFilename); File.Copy(imagePath, dstPath, true); project.AddFile(dstPath, Path.Combine(projectRelativeFolder, imageFilename)); resourceContents.images [0].filename = imageFilename; //add contents.json file string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json"); File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(resourceContents, true)); project.AddFile(contentsJsonPath, Path.Combine(projectRelativeFolder, "Contents.json")); }
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject) { // merge plist var plistPath = Path.Combine(pathToBuiltProject, "Info.plist"); var onePath = Path.Combine(Application.dataPath, "Plugins/iOS/vendors/one/Info.plist"); ExecuteCommand(string.Format("/usr/libexec/PlistBuddy -x -c 'Merge {0}' {1}", onePath, plistPath)); // write sdkconfig var sdkPath = Path.Combine(pathToBuiltProject, "ejoysdk"); var jsonPath = Path.Combine(sdkPath, "sdkconfig.json"); ExecuteCommand("mkdir -p " + sdkPath); string json = @"{""sdks"":[{""class"":""SDKProxyOne""}],""meta"":{}, ""tag"": ""cocoisland""}"; var sr = File.CreateText(jsonPath); sr.WriteLine(json); sr.Close(); //xcode setting string projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(projectPath)); string target = pbxProject.TargetGuidByName("Unity-iPhone"); var guid = pbxProject.AddFolderReference("ejoysdk", "ejoysdk"); pbxProject.AddFileToBuild(target, guid); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-lz"); pbxProject.AddFrameworkToProject(target, "WebKit.framework", false); File.WriteAllText(projectPath, pbxProject.WriteToString()); }
/// <summary> /// List through all the files in the directory, get path to these files /// and add them to 'Copy resources' inside XCode project /// </summary> public static void CopyAllFilesFromDirectory(DefaultAsset defaultAsset, string buildPath, PBXProject project, string target) { if (defaultAsset == null) { return; } var files = Directory.GetFiles(AssetDatabase.GetAssetPath(defaultAsset)); var destinationPath = buildPath + "/"; foreach (var file in files) { var nameAndExtension = file.Split('/').LastOrDefault(); if (nameAndExtension != null && nameAndExtension.ToLower().Contains(".meta")) { continue; } var assetLocation = AssetDatabase.GetAssetPath(defaultAsset) + "/" + nameAndExtension; var assetDestination = destinationPath + nameAndExtension; FileUtil.CopyFileOrDirectory(assetLocation, assetDestination); var grGUID = project.AddFolderReference(destinationPath + nameAndExtension, nameAndExtension); project.AddFileToBuild(target, grGUID); } }
static void AddReferenceImagesSetToAssetCatalog(ARReferenceImagesSet aris, string pathToBuiltProject, PBXProject project) { List <ARReferenceImage> processedImages = new List <ARReferenceImage> (); ARResourceGroupContents groupContents = new ARResourceGroupContents(); groupContents.info = new ARResourceGroupInfo(); groupContents.info.author = "xcode"; groupContents.info.version = 1; string folderToCreate = "Unity-iPhone/Images.xcassets/" + aris.resourceGroupName + ".arresourcegroup"; string folderFullPath = Path.Combine(pathToBuiltProject, folderToCreate); Directory.CreateDirectory(folderFullPath); project.AddFolderReference(folderFullPath, folderToCreate); foreach (ARReferenceImage arri in aris.referenceImages) { if (!processedImages.Contains(arri)) { processedImages.Add(arri); //get rid of dupes AddReferenceImageToResourceGroup(arri, folderFullPath, folderToCreate, project); } } groupContents.resources = new ARResourceGroupResource[processedImages.Count]; int index = 0; foreach (ARReferenceImage arri in processedImages) { groupContents.resources [index] = new ARResourceGroupResource(); groupContents.resources [index].filename = arri.imageName + ".arreferenceimage"; index++; } string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json"); File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(groupContents, true)); project.AddFile(contentsJsonPath, Path.Combine(folderToCreate, "Contents.json")); }
static void AddGoogleMapsBundleToProjectResources(PBXProject project, string targetGUID, string sourcePath, string destPath) { var addFolderReference = project.AddFolderReference(sourcePath, destPath, PBXSourceTree.Source); project.AddFileToBuild(targetGUID, addFolderReference); }
private static void LocalizeUserTrackingDescription(string buildPath, PBXProject project, string targetGuid, CASEditorSettings settings) { const string LegacyResourcesDirectoryName = "Resources"; const string CASResourcesDirectoryName = "CASUResources"; if (settings.userTrackingUsageDescription.Length < 2) { return; } // Use the legacy resources directory name if the build is being appended (the "Resources" directory already exists if it is an incremental build). var resourcesDirectoryName = Directory.Exists(Path.Combine(buildPath, LegacyResourcesDirectoryName)) ? LegacyResourcesDirectoryName : CASResourcesDirectoryName; var resourcesDirectoryPath = Path.Combine(buildPath, resourcesDirectoryName); for (int i = 0; i < settings.userTrackingUsageDescription.Length; i++) { var keyValue = settings.userTrackingUsageDescription[i]; var description = keyValue.value; var localeCode = keyValue.key; if (string.IsNullOrEmpty(localeCode)) { continue; } var localeSpecificDirectoryName = localeCode + ".lproj"; var localeSpecificDirectoryPath = Path.Combine(resourcesDirectoryPath, localeSpecificDirectoryName); var infoPlistStringsFilePath = Path.Combine(localeSpecificDirectoryPath, "InfoPlist.strings"); // Check if localization has been disabled between builds, and remove them as needed. if (string.IsNullOrEmpty(description)) { if (File.Exists(infoPlistStringsFilePath)) { File.Delete(infoPlistStringsFilePath); } continue; } // Create intermediate directories as needed. if (!Directory.Exists(resourcesDirectoryPath)) { Directory.CreateDirectory(resourcesDirectoryPath); } if (!Directory.Exists(localeSpecificDirectoryPath)) { Directory.CreateDirectory(localeSpecificDirectoryPath); } var localizedDescriptionLine = "\"NSUserTrackingUsageDescription\" = \"" + description + "\";\n"; // File already exists, update it in case the value changed between builds. if (File.Exists(infoPlistStringsFilePath)) { var output = new List <string>(); var lines = File.ReadAllLines(infoPlistStringsFilePath); var keyUpdated = false; foreach (var line in lines) { if (line.Contains("NSUserTrackingUsageDescription")) { output.Add(localizedDescriptionLine); keyUpdated = true; } else { output.Add(line); } } if (!keyUpdated) { output.Add(localizedDescriptionLine); } File.WriteAllText(infoPlistStringsFilePath, string.Join("\n", output.ToArray()) + "\n"); } // File doesn't exist, create one. else { File.WriteAllText(infoPlistStringsFilePath, "/* Localized versions of Info.plist keys - Generated by CAS plugin */\n" + localizedDescriptionLine); } var guid = project.AddFolderReference(localeSpecificDirectoryPath, Path.Combine(resourcesDirectoryName, localeSpecificDirectoryName)); project.AddFileToBuild(targetGuid, guid); } }
public static void OnPostprocessiOSBuild(BuildTarget target, string iBuiltProjectPath) { UtilsLog.Info("PostProcessor", "OnPostprocessiOSBuild()::Target:{0} ProPath:{1}", target.ToString(), iBuiltProjectPath); #if UNITY_EDITOR if (target != BuildTarget.iOS) { return; } const string funcBlock = "PostProcessor.OnPostprocessiOSBuild()"; BuildLogger.OpenBlock(funcBlock); const string TargetProjectName = "Unity-iPhone"; BuildSettings _buildSetting = BuildSettings.GetInstance(BuildSettings.AssetFileDir); if (null == _buildSetting) { return; } // 取得设定情报列表 XCSettingItem[] settings = _buildSetting.GetXCSettingInfo(TargetProjectName); if ((settings == null) || (settings.Length <= 0)) { BuildLogger.CloseBlock(); return; } string pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string targetGUID = project.TargetGuidByName(TargetProjectName); // BuildMode(debug/release/store) string debugConfigGUID = project.BuildConfigByName(targetGUID, "Debug"); string releaseConfigGUID = project.BuildConfigByName(targetGUID, "Release"); foreach (XCSettingItem item in settings) { switch (item.Type) { case TXCSettingInfoType.ReplaceSource: { foreach (string value in item.Value.LValue) { ReplaceSource(iBuiltProjectPath, value); BuildLogger.LogMessage("Replace Source {0} -> {1}", value, iBuiltProjectPath); } } break; case TXCSettingInfoType.FrameWorks: { foreach (string frameWork in item.Value.LValue) { #if UNITY_2017_1_OR_NEWER if (project.ContainsFramework(targetGUID, frameWork) == false) { #else if (project.HasFramework(frameWork) == false) { #endif project.AddFrameworkToProject(targetGUID, frameWork, false); BuildLogger.LogMessage("Add FrameWork -> {0}", frameWork); } } } break; case TXCSettingInfoType.Libraries: { foreach (string library in item.Value.LValue) { string fileGuid = project.AddFile("usr/lib/" + library, "Frameworks/" + library, PBXSourceTree.Sdk); project.AddFileToBuild(targetGUID, fileGuid); BuildLogger.LogMessage("Add Library -> {0}", library); } } break; case TXCSettingInfoType.IncludeFiles: { foreach (string file in item.Value.LValue) { string addFilePath = null; PreSetFileToProject(iBuiltProjectPath, file, ref addFilePath); if (string.IsNullOrEmpty(addFilePath) == false) { string fileGUID = project.AddFile(addFilePath, addFilePath, PBXSourceTree.Source); project.AddFileToBuild(targetGUID, fileGUID); BuildLogger.LogMessage("Add File -> {0}", file); } } } break; case TXCSettingInfoType.IncludeFolders: { foreach (string folder in item.Value.LValue) { string copyTo = null; string addDirReference = null; PreSetFolderToProject(iBuiltProjectPath, folder, ref copyTo, ref addDirReference); if ((string.IsNullOrEmpty(copyTo) == false) && (string.IsNullOrEmpty(addDirReference) == false)) { project.AddFolderReference(copyTo, addDirReference, PBXSourceTree.Source); BuildLogger.LogMessage("Add Folder -> {0}", folder); } } } break; case TXCSettingInfoType.Bool: { // Debug if (TXCBool.Yes == item.Debug.BValue) { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.BValue.ToString()); // Release if (TXCBool.Yes == item.Release.BValue) { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Release) -> Key:{0} Value:{1}", item.Key, item.Release.BValue.ToString()); } break; case TXCSettingInfoType.String: { // Debug project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, item.Debug.SValue); BuildLogger.LogMessage("Add String(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.SValue); // Release project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, item.Release.SValue); BuildLogger.LogMessage("Add String(Release) -> Key:{0} Value:{1}", item.Key, item.Release.SValue); } break; case TXCSettingInfoType.List: { // Debug foreach (string value in item.Debug.LValue) { project.AddBuildPropertyForConfig(debugConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Debug) -> Key:{0} Item:{1}", item.Key, value); } // Release foreach (string value in item.Release.LValue) { project.AddBuildPropertyForConfig(releaseConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Release) -> Key:{0} Item:{1}", item.Key, value); } } break; default: break; } } File.WriteAllText(pbxprojPath, project.WriteToString()); BuildLogger.CloseBlock(); #endif }
private static void AddUserTrackingDescriptionLocalizedString(string localizedUserTrackingDescription, string localeCode, string buildPath, PBXProject project, string targetGuid) { const string resourcesDirectoryName = "BalasoLocalizationResources"; var resourcesDirectoryPath = Path.Combine(buildPath, resourcesDirectoryName); var localeSpecificDirectoryName = localeCode + ".lproj"; var localeSpecificDirectoryPath = Path.Combine(resourcesDirectoryPath, localeSpecificDirectoryName); var infoPlistStringsFilePath = Path.Combine(localeSpecificDirectoryPath, "InfoPlist.strings"); if (!SettingsInspector.Settings.UseLocalizationValues) { if (!File.Exists(infoPlistStringsFilePath)) { return; } File.Delete(infoPlistStringsFilePath); return; } // Create intermediate directories as needed. if (!Directory.Exists(resourcesDirectoryPath)) { Directory.CreateDirectory(resourcesDirectoryPath); } if (!Directory.Exists(localeSpecificDirectoryPath)) { Directory.CreateDirectory(localeSpecificDirectoryPath); } var localizedDescriptionLine = "\"NSUserTrackingUsageDescription\" = \"" + localizedUserTrackingDescription + "\";\n"; // File already exists, update it in case the value changed between builds. if (File.Exists(infoPlistStringsFilePath)) { var output = new List <string>(); var lines = File.ReadAllLines(infoPlistStringsFilePath); var keyUpdated = false; foreach (var line in lines) { if (line.Contains("NSUserTrackingUsageDescription")) { output.Add(localizedDescriptionLine); keyUpdated = true; } else { output.Add(line); } } if (!keyUpdated) { output.Add(localizedDescriptionLine); } File.WriteAllText(infoPlistStringsFilePath, string.Join("\n", output.ToArray()) + "\n"); } // File doesn't exist, create one. else { File.WriteAllText(infoPlistStringsFilePath, "/* Localized versions of Info.plist keys */\n" + localizedDescriptionLine); } var guid = project.AddFolderReference(localeSpecificDirectoryPath, Path.Combine(resourcesDirectoryName, localeSpecificDirectoryName), PBXSourceTree.Source); project.AddFileToBuild(targetGuid, guid); }
private static void LocalizeUserTrackingDescriptionIfNeeded(string localizedUserTrackingDescription, string localeCode, string buildPath, PBXProject project, string targetGuid) { const string resourcesDirectoryName = "Resources"; var resourcesDirectoryPath = Path.Combine(buildPath, resourcesDirectoryName); var localeSpecificDirectoryName = localeCode + ".lproj"; var localeSpecificDirectoryPath = Path.Combine(resourcesDirectoryPath, localeSpecificDirectoryName); var infoPlistStringsFilePath = Path.Combine(localeSpecificDirectoryPath, "InfoPlist.strings"); // Check if localization has been disabled between builds, and remove them as needed. var settings = AppLovinSettings.Instance; if (!settings.ConsentFlowEnabled || !settings.UserTrackingUsageLocalizationEnabled || string.IsNullOrEmpty(localizedUserTrackingDescription)) { if (!File.Exists(infoPlistStringsFilePath)) { return; } File.Delete(infoPlistStringsFilePath); return; } // Create intermediate directories as needed. if (!Directory.Exists(resourcesDirectoryPath)) { Directory.CreateDirectory(resourcesDirectoryPath); } if (!Directory.Exists(localeSpecificDirectoryPath)) { Directory.CreateDirectory(localeSpecificDirectoryPath); } var localizedDescriptionLine = "\"NSUserTrackingUsageDescription\" = \"" + localizedUserTrackingDescription + "\";\n"; // File already exists, update it in case the value changed between builds. if (File.Exists(infoPlistStringsFilePath)) { var output = new List <string>(); var lines = File.ReadAllLines(infoPlistStringsFilePath); var keyUpdated = false; foreach (var line in lines) { if (line.Contains("NSUserTrackingUsageDescription")) { output.Add(localizedDescriptionLine); keyUpdated = true; } else { output.Add(line); } } if (!keyUpdated) { output.Add(localizedDescriptionLine); } File.WriteAllText(infoPlistStringsFilePath, string.Join("\n", output.ToArray()) + "\n"); } // File doesn't exist, create one. else { File.WriteAllText(infoPlistStringsFilePath, "/* Localized versions of Info.plist keys - Generated by AL MAX plugin */\n" + localizedDescriptionLine); } var guid = project.AddFolderReference(localeSpecificDirectoryPath, Path.Combine(resourcesDirectoryName, localeSpecificDirectoryName)); project.AddFileToBuild(targetGuid, guid); }
public static void OnPostprocessiOSBuild(BuildTarget iTarget, string iBuiltProjectPath) { Loger.BuildStart("PostProcessor::OnPostprocessiOSBuild()"); Loger.Info($"Target:{iTarget} ProPath:{iBuiltProjectPath}"); // iOS if (iTarget != BuildTarget.iOS) { Loger.BuildEnd(); return; } const string targetProjectName = "Unity-iPhone"; var buildSetting = BuildSettings.GetInstance(BuildSettings.AssetFileDir); if (null == buildSetting) { return; } // 取得设定情报列表 var settings = buildSetting.GetXcSettingInfo(targetProjectName); if (settings == null || settings.Length <= 0) { Loger.BuildEnd(); return; } var pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath); var project = new PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); var targetGuid = project.TargetGuidByName(targetProjectName); // BuildMode(debug/release/store) var debugGuid = project.BuildConfigByName(targetGuid, "Debug"); var releaseGuid = project.BuildConfigByName(targetGuid, "Release"); var releaseForProfilingGuid = project.BuildConfigByName(targetGuid, "ReleaseForProfiling"); var releaseForRunningGuid = project.BuildConfigByName(targetGuid, "ReleaseForRunning"); foreach (var item in settings) { switch (item.type) { case TxcSettingInfoType.ReplaceSource: { var list = item.Value.Values; if (list != null) { foreach (var value in list) { ReplaceSource(iBuiltProjectPath, Convert.ToString(value)); Loger.BuildLog($"Replace Source {value} -> {iBuiltProjectPath}"); } } } break; case TxcSettingInfoType.FrameWorks: { var list = item.Value.Values; if (list != null) { foreach (var frameWork in list) { var strTmp = Convert.ToString(frameWork); #if UNITY_2017_1_OR_NEWER if (project.ContainsFramework(targetGuid, strTmp) == false) { #else if (project.HasFramework(strTmp) == false) { #endif project.AddFrameworkToProject(targetGuid, strTmp, false); Loger.BuildLog($"Add FrameWork -> {strTmp}"); } } } } break; case TxcSettingInfoType.Libraries: { var list = item.Value.Values; if (list != null) { foreach (var library in list) { var strTmp = Convert.ToString(library); var fileGuid = project.AddFile("usr/lib/" + strTmp, "Frameworks/" + strTmp, PBXSourceTree.Sdk); project.AddFileToBuild(targetGuid, fileGuid); Loger.BuildLog($"Add Library -> {strTmp}"); } } } break; case TxcSettingInfoType.IncludeFiles: { var list = item.Value.Values; if (list != null) { foreach (var file in list) { var strTmp = Convert.ToString(file); string addFilePath = null; PreSetFileToProject(iBuiltProjectPath, strTmp, ref addFilePath); if (string.IsNullOrEmpty(addFilePath)) { continue; } var fileGuid = project.AddFile(addFilePath, addFilePath); project.AddFileToBuild(targetGuid, fileGuid); Loger.BuildLog($"Add File -> {strTmp}"); } } } break; case TxcSettingInfoType.IncludeFolders: { var list = item.Value.Values; if (list != null) { foreach (var folder in list) { var strTmp = Convert.ToString(folder); string copyTo = null; string addDirReference = null; PreSetFolderToProject(iBuiltProjectPath, strTmp, ref copyTo, ref addDirReference); if (string.IsNullOrEmpty(copyTo) || string.IsNullOrEmpty(addDirReference)) { continue; } project.AddFolderReference(copyTo, addDirReference); Loger.BuildLog($"Add Folder -> {strTmp}"); } } } break; case TxcSettingInfoType.Bool: { var debugValue = (TxcBool)item.Debug.Value; // Debug project.SetBuildPropertyForConfig(debugGuid, item.key, TxcBool.Yes == debugValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(Debug) -> Key:{item.key} Value:{(TxcBool.Yes == debugValue ? "YES" : "NO")}"); // Release var releaseValue = (TxcBool)item.Release.Value; project.SetBuildPropertyForConfig(releaseGuid, item.key, TxcBool.Yes == releaseValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(Release) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); // ReleaseForProfiling var releaseForProfilingValue = (TxcBool)item.ReleaseForProfiling.Value; project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, TxcBool.Yes == releaseForProfilingValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(ReleaseForProfiling) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); // ReleaseForRunning var releaseForRunningValue = (TxcBool)item.ReleaseForRunning.Value; project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, TxcBool.Yes == releaseForRunningValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(ReleaseForRunning) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); } break; case TxcSettingInfoType.Enum: { // Debug var debugValue = $"{item.Debug.Value}"; if (false == string.IsNullOrEmpty(debugValue)) { project.SetBuildPropertyForConfig(debugGuid, item.key, debugValue); Loger.BuildLog($"Add String(Debug) -> Key:{item.key} Value:{debugValue}"); } // Release var releaseValue = $"{item.Release.Value}"; if (false == string.IsNullOrEmpty(releaseValue)) { project.SetBuildPropertyForConfig(releaseGuid, item.key, releaseValue); Loger.BuildLog($"Add String(Release) -> Key:{item.key} Value:{releaseValue}"); } // ReleaseForProfiling var releaseForProfilingValue = $"{item.ReleaseForProfiling.Value}"; if (false == string.IsNullOrEmpty(releaseForProfilingValue)) { project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, releaseForProfilingValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForProfilingValue}"); } // ReleaseForRunning var releaseForRunningValue = $"{item.ReleaseForRunning.Value}"; if (false == string.IsNullOrEmpty(releaseForRunningValue)) { project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, releaseForRunningValue); Loger.BuildLog($"Add String(ReleaseForRunning) -> Key:{item.key} Value:{releaseForRunningValue}"); } } break; case TxcSettingInfoType.String: { // Debug var debugValue = item.Debug.Value as string; if (false == string.IsNullOrEmpty(debugValue)) { project.SetBuildPropertyForConfig(debugGuid, item.key, debugValue); Loger.BuildLog($"Add String(Debug) -> Key:{item.key} Value:{debugValue}"); } // Release var releaseValue = item.Release.Value as string; if (false == string.IsNullOrEmpty(releaseValue)) { project.SetBuildPropertyForConfig(releaseGuid, item.key, releaseValue); Loger.BuildLog($"Add String(Release) -> Key:{item.key} Value:{releaseValue}"); } // ReleaseForProfiling var releaseForProfilingValue = item.ReleaseForProfiling.Value as string; if (false == string.IsNullOrEmpty(releaseForProfilingValue)) { project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, releaseForProfilingValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForProfilingValue}"); } // ReleaseForRunning var releaseForRunningValue = item.ReleaseForRunning.Value as string; if (false == string.IsNullOrEmpty(releaseForRunningValue)) { project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, releaseForRunningValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForRunningValue}"); } } break; case TxcSettingInfoType.List: { // Debug var debugValue = item.Debug.Value as List <string>; if (null != debugValue) { foreach (var value in debugValue) { project.AddBuildPropertyForConfig(debugGuid, item.key, value); Loger.BuildLog($"Add List(Debug) -> Key:{item.key} Item:{value}"); } } // Release var releaseValue = item.Release.Value as List <string>; if (null != releaseValue) { foreach (var value in releaseValue) { project.AddBuildPropertyForConfig(releaseGuid, item.key, value); Loger.BuildLog($"Add List(Release) -> Key:{item.key} Item:{value}"); } } // ReleaseForProfiling var releaseForProfilingValue = item.ReleaseForProfiling.Value as List <string>; if (null != releaseForProfilingValue) { foreach (var value in releaseForProfilingValue) { project.AddBuildPropertyForConfig(releaseForProfilingGuid, item.key, value); Loger.BuildLog($"Add List(ReleaseForProfiling) -> Key:{item.key} Item:{value}"); } } // ReleaseForRunning var releaseForRunningValue = item.ReleaseForRunning.Value as List <string>; if (null != releaseForRunningValue) { foreach (var value in releaseForRunningValue) { project.AddBuildPropertyForConfig(releaseForRunningGuid, item.key, value); Loger.BuildLog($"Add List(ReleaseForRunning) -> Key:{item.key} Item:{value}"); } } } break; case TxcSettingInfoType.None: break; default: Loger.BuildEnd(); throw new ArgumentOutOfRangeException(); } } File.WriteAllText(pbxprojPath, project.WriteToString()); Loger.BuildEnd(); }