private static void SetFilesCompileFlag(PBXProject proj, Hashtable arg) { if (arg == null) { return; } string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); foreach (DictionaryEntry i in arg) { string fileProjPath = i.Key.ToString(); string fguid = proj.FindFileGuidByProjectPath(fileProjPath); if (fguid == null) { continue; } ArrayList des = i.Value as ArrayList; List <string> list = new List <string>(); foreach (var flag in des) { list.Add(flag.ToString()); } proj.SetCompileFlagsForFile(target, fguid, list); } }
//设置Capabilities void SetCapabilities(string pathToBuildProject) { string projPath = pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; //项目路径,这个路径在mac上默认是不显示的,需要右键->显示包内容才能看到。unity到处的名字就是这个。 UnityEditor.iOS.Xcode.PBXProject pbxProj = new UnityEditor.iOS.Xcode.PBXProject(); //创建xcode project类 pbxProj.ReadFromString(File.ReadAllText(projPath)); //xcode project读入 string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName()); //获得Target名 //设置BuildSetting pbxProj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC"); pbxProj.SetBuildProperty(targetGuid, "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym"); //定位崩溃bug pbxProj.SetBuildProperty(targetGuid, "EXCLUDED_ARCHS", "armv7"); pbxProj.AddFrameworkToProject(targetGuid, "MediaPlayer.framework", false); pbxProj.AddFrameworkToProject(targetGuid, "AdSupport.framework", true); //添加资源 pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(System.Environment.CurrentDirectory + "/LTBaseSDK_Oversea/ltgame.cfg", "Resource/ltgame.cfg", PBXSourceTree.Source)); //修改编译方式 string mmfile = pbxProj.FindFileGuidByProjectPath("Classes/UnityAppController.mm"); var flags = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile); flags.Add("-fno-objc-arc"); pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags); mmfile = pbxProj.FindFileGuidByProjectPath("Libraries/Plugins/IOS/LTSDK/LTSDKNPC.mm"); flags = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile); flags.Add("-fno-objc-arc"); pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags); pbxProj.WriteToFile(projPath); string[] splits = PlayerSettings.applicationIdentifier.Split('.'); var capManager = new ProjectCapabilityManager(projPath, splits[splits.Length - 1] + ".entitlements", PBXProject.GetUnityTargetName());//创建设置Capability类 if (PlayerSettings.applicationIdentifier.Equals("com.longtugame.dzyz.longtu")) { //正式包,增加计费 capManager.AddInAppPurchase(); } capManager.AddAssociatedDomains(new[] { "applinks:dy.longtugame.com" }); capManager.WriteToFile();//写入文件保存 }
private static void removeCompatibilityLibraryFromProject(XCProject project) { string folderPath = Path.Combine(Application.dataPath, "Fyber/iOS/fyber-sdk-compat-lib"); if (Directory.Exists(folderPath)) { Debug.Log(folderPath + " exists. Deleting it"); Directory.Delete(folderPath, true); } string libPath = Path.Combine(project.projectRootPath, "Libraries/Fyber/iOS/fyber-sdk-compat-lib"); if (Directory.Exists(libPath)) { Debug.Log(libPath + " exists. Deleting it"); Directory.Delete(libPath, true); } #if UNITY_5 var compatGroup = "Libraries/Fyber/iOS/fyber-sdk-compat-lib"; string[] filesToRemove = { "FYBBannerSize.h", "FYBBannerView.h", "libFyberSDKCompat.a" }; UnityEditor.iOS.Xcode.PBXProject pbxProject = new UnityEditor.iOS.Xcode.PBXProject(); string pbxprojPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(project.projectRootPath); pbxProject.ReadFromFile(pbxprojPath); foreach (string file in filesToRemove) { var fileToRemove = compatGroup + "/" + file; if (pbxProject.ContainsFileByProjectPath(fileToRemove)) { string guid = pbxProject.FindFileGuidByProjectPath(fileToRemove); pbxProject.RemoveFile(guid); } } pbxProject.WriteToFile(pbxprojPath); #endif // UNITY_5 }
/// <summary> /// Updates the generated pbxproj to reduce manual work required by developers. Currently /// this adds the '-fobjc-arc' flag for the Play Games ObjC source file. /// </summary> /// <param name="pbxprojPath">Pbxproj path.</param> private static void UpdateGeneratedPbxproj(string pbxprojPath) { PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(pbxprojPath)); string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); string testTarget = proj.TargetGuidByName(PBXProject.GetUnityTestTargetName()); proj.AddBuildProperty(target, "OTHER_LDFLAGS", "$(inherited)"); proj.AddBuildProperty(testTarget, "OTHER_LDFLAGS", "$(inherited)"); proj.AddBuildProperty(target, "HEADER_SEARCH_PATHS", "$(inherited)"); proj.AddBuildProperty(testTarget, "HEADER_SEARCH_PATHS", "$(inherited)"); proj.AddBuildProperty(target, "OTHER_CFLAGS", "$(inherited)"); proj.AddBuildProperty(testTarget, "OTHER_CFLAGS", "$(inherited)"); string fileGuid = proj.FindFileGuidByProjectPath("Libraries/Plugins/iOS/GPGSAppController.mm"); List<string> list = new List<string>(); list.Add("-fobjc-arc"); proj.SetCompileFlagsForFile(target, fileGuid, list); File.WriteAllText(pbxprojPath, proj.WriteToString()); }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { #if UNITY_5 if (target != BuildTarget.iOS) { if (!GPGSProjectSettings.Instance.GetBool(GPGSUtil.ANDROIDSETUPDONEKEY, false)) { EditorUtility.DisplayDialog("Google Play Games not configured!", "Warning!! Google Play Games was not configured, Game Services will not work correctly.", "OK"); } return; } #else if (target != BuildTarget.iPhone) { return; } #endif #if UNITY_IOS #if NO_GPGS string[] filesToRemove = { "Libraries/Plugins/IOS/GPGSAppController.mm", "Libraries/Plugins/iOS/GPGSAppController.mm", "Libraries/GPGSAppController.mm", "Libraries/Plugins/IOS/GPGSAppController.h", "Libraries/Plugins/iOS/GPGSAppController.h", "Libraries/GPGSAppController.h", "Libraries/Plugins/IOS/CustomWebViewApplication.h", "Libraries/Plugins/iOS/CustomWebViewApplication.h", "Libraries/CustomWebViewApplication.h", "Libraries/Plugins/IOS/CustomWebViewApplication.mm", "Libraries/Plugins/iOS/CustomWebViewApplication.mm", "Libraries/CustomWebViewApplication.mm" }; string pbxprojPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(pbxprojPath)); foreach(string name in filesToRemove) { string fileGuid = proj.FindFileGuidByProjectPath(name); if (fileGuid != null) { Debug.Log ("Removing " + name + " from xcode project"); proj.RemoveFile(fileGuid); } } File.WriteAllText(pbxprojPath, proj.WriteToString()); #else if (!GPGSProjectSettings.Instance.GetBool(GPGSUtil.IOSSETUPDONEKEY, false)) { EditorUtility.DisplayDialog("Google Play Games not configured!", "Warning!! Google Play Games was not configured, Game Services will not work correctly.", "OK"); } if (GetBundleId() == null) { UnityEngine.Debug.LogError("The iOS bundle ID has not been set up through the " + "'iOS Setup' submenu of 'Google Play Games' - the generated xcode project will " + "not work properly."); return; } UpdateGeneratedInfoPlistFile(pathToBuiltProject + "/Info.plist"); UpdateGeneratedPbxproj(pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"); UnityEngine.Debug.Log("Adding URL Types for authentication using PlistBuddy."); #endif #endif }
/// <summary> /// Updates the generated pbxproj to reduce manual work required by developers. Currently /// this adds the '-fobjc-arc' flag for the Play Games ObjC source file. /// </summary> /// <param name="pbxprojPath">Pbxproj path.</param> private static void UpdateGeneratedPbxproj(string pbxprojPath) { PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(pbxprojPath)); string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); string fileGuid = proj.FindFileGuidByProjectPath("Libraries/Plugins/iOS/GPGSAppController.mm"); if (fileGuid == null) { // look in the legacy location fileGuid = proj.FindFileGuidByProjectPath("Libraries/GPGSAppController.mm"); } List<string> list = new List<string>(); list.Add("-fobjc-arc"); proj.SetCompileFlagsForFile(target, fileGuid, list); File.WriteAllText(pbxprojPath, proj.WriteToString()); }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { #if UNITY_5 if (target != BuildTarget.iOS) { return; } #else if (target != BuildTarget.iPhone) { return; } #endif #if NO_GPGS string[] filesToRemove = { "Libraries/Plugins/iOS/GPGSAppController.mm", "Libraries/GPGSAppController.mm", "Libraries/Plugins/iOS/GPGSAppController.h", "Libraries/GPGSAppController.h", "Libraries/Plugins/iOS/CustomWebViewApplication.h", "Libraries/CustomWebViewApplication.h", "Libraries/Plugins/iOS/CustomWebViewApplication.mm", "Libraries/CustomWebViewApplication.mm" }; string pbxprojPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString(File.ReadAllText(pbxprojPath)); foreach(string name in filesToRemove) { string fileGuid = proj.FindFileGuidByProjectPath(name); if (fileGuid != null) { Debug.Log ("Removing " + name + " from xcode project"); proj.RemoveFile(fileGuid); } } File.WriteAllText(pbxprojPath, proj.WriteToString()); #else if (GetBundleId() == null) { UnityEngine.Debug.LogError("The iOS bundle ID has not been set up through the " + "'iOS Setup' submenu of 'Google Play Games' - the generated xcode project will " + "not work properly."); return; } //Copy the podfile into the project. string podfile = "Assets/GooglePlayGames/Editor/Podfile.txt"; string destpodfile = pathToBuiltProject + "/Podfile"; if (!System.IO.File.Exists(destpodfile)) { FileUtil.CopyFileOrDirectory(podfile, destpodfile); } GPGSInstructionWindow w = EditorWindow.GetWindow<GPGSInstructionWindow>( true, "Building for IOS", true); w.minSize = new Vector2(400, 300); w.UsingCocoaPod = CocoaPodHelper.Update(pathToBuiltProject); UnityEngine.Debug.Log("Adding URL Types for authentication using PlistBuddy."); UpdateGeneratedInfoPlistFile(pathToBuiltProject + "/Info.plist"); UpdateGeneratedPbxproj(pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj"); #endif }
public static void OnPostProcessBuild(BuildTarget target, string path) { #if UNITY_IPHONE || UNITY_IOS #if UNITY_5 if (target == BuildTarget.iOS) #else if (target == BuildTarget.iPhone) #endif // UNITY_5 { string folderPath = Path.Combine(Application.dataPath, "Fyber/iOS/fyber-sdk-compat-lib"); if (Directory.Exists(folderPath)) { Directory.Delete(folderPath, true); } XCProject project = new XCProject(path); string libPath = Path.Combine(project.projectRootPath, "Libraries/Fyber/iOS/fyber-sdk-compat-lib"); if (Directory.Exists(libPath)) { Directory.Delete(libPath, true); } // Find and run through all projmods files to patch the project string projModPath = System.IO.Path.Combine(Application.dataPath, "Fyber/iOS"); string[] files = System.IO.Directory.GetFiles(projModPath, "*.projmods", System.IO.SearchOption.AllDirectories); foreach (var file in files) { project.ApplyMod(Application.dataPath, file); if (file.Contains("NativeX")) { string unityVersionPlist = "<plist><key>name</key><string>Nativex</string><key>settings</key><dict><key>FYBNativeXUnityBuildFlag</key><true /></dict></plist>"; PlistUpdater.UpdatePlist(project.projectRootPath, unityVersionPlist); } } project.Save(); #if UNITY_5 var compatGroup = "Libraries/Fyber/iOS/fyber-sdk-compat-lib"; string[] filesToRemove = { "FYBBannerSize.h", "FYBBannerView.h", "libFyberSDKCompat.a" }; UnityEditor.iOS.Xcode.PBXProject pbxProject = new UnityEditor.iOS.Xcode.PBXProject(); string pbxprojPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path); pbxProject.ReadFromFile(pbxprojPath); foreach (string file in filesToRemove) { var fileToRemove = compatGroup + "/" + file; if (pbxProject.ContainsFileByProjectPath(fileToRemove)) { string guid = pbxProject.FindFileGuidByProjectPath(fileToRemove); pbxProject.RemoveFile(guid); } } pbxProject.WriteToFile(pbxprojPath); #endif // UNITY_5 } #endif //UNITY_IPHONE || UNITY_IOS }
private static void ModifyProject(string projectPath) { // Create PBXProject PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(projectPath)); if (!AppboyConfig.IOSAutomatesIntegration) { // Remove AppboyAppDelegate.mm from PBXProject Debug.Log("Removing AppboyAppDelegate.mm from " + AppboyAppDelegatePath); string appboyAppDelegateGuid = project.FindFileGuidByProjectPath(AppboyAppDelegatePath); project.RemoveFile(appboyAppDelegateGuid); } else { // Get project targets using Unity's default app target names string[] targets = { project.TargetGuidByName(PBXProject.GetUnityTargetName()), project.TargetGuidByName(PBXProject.GetUnityTestTargetName()) }; string[] requiredFrameworks = { "SystemConfiguration.framework", "QuartzCore.framework", "libz.tbd", "CoreImage.framework", "CoreText.framework" }; string[] optionalFrameworks = { "CoreTelephony.framework", "Social.framework", "Accounts.framework", "AdSupport.framework", "StoreKit.framework", "CoreLocation.framework", // optional for location tracking "ImageIO.framework" // required by SDWebImage }; foreach (string target in targets) { // Modify build properties project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "./Frameworks/Plugins/iOS"); project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "./Libraries/Plugins/iOS"); project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "./Libraries"); // Add required frameworks // Note: Unity's documentation for PBXProject.AddFrameworkToProject says that the boolean parameter // should be true if required and false if optional, but actual behavior appears to be the exact opposite. foreach (string framework in requiredFrameworks) { project.AddFrameworkToProject(target, framework, false); } foreach (string framework in optionalFrameworks) { project.AddFrameworkToProject(target, framework, true); } } } // Write changes to XCode project File.WriteAllText(projectPath, project.WriteToString()); }
private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath) { //iOS以外にビルドしている場合は更新処理を行わないように if (buildTarget != BuildTarget.iOS){ return; } //Xcodeの設定データを読み込む XcodeProjectSetting setting = Resources.Load<XcodeProjectSetting>(SETTING_DATA_PATH); if(setting == null){ Debug.Log ("Resources/" + SETTING_DATA_PATH + "がありません!"); return; } //Xcodeプロジェクトの読み込み string pbxProjPath = PBXProject.GetPBXProjectPath(buildPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(pbxProjPath)); //ターゲットのID取得 string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName()); //指定ディレクトリ内のファイルを全てコピーする if(!string.IsNullOrEmpty(setting.CopyDirectoryPath)){ DirectoryProcessor.CopyAndAddBuildToXcode (pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, ""); } //コンパイラフラグの設定 foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList) { foreach (string targetPath in compilerFlagsSet.TargetPathList) { if(!pbxProject.ContainsFileByProjectPath(targetPath)){ Debug.Log (targetPath + "が無いのでコンパイラフラグが設定できませんでした"); continue; } string fileGuid = pbxProject.FindFileGuidByProjectPath(targetPath); List<string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid); flagsList.Add(compilerFlagsSet.Flags); pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList); } } //システムのフレームワークを追加 foreach (string framework in setting.FrameworkList) { pbxProject.AddFrameworkToProject(targetGuid, framework, false); } //Linker Flagの設定 pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null); //フレームワークがあるディレクトリへのパス設定 pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null); //BitCodeの設定 pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO"); //プロジェクトファイル書き出し File.WriteAllText(pbxProjPath, pbxProject.WriteToString()); //URLスキームの設定 List<string> urlSchemeList = new List<string>(setting.URLSchemeList); InfoPlistProcessor.SetURLSchemes (buildPath, setting.URLIdentifier, urlSchemeList); //デフォルトで設定されているスプラッシュ画像の設定を消す if(setting.NeedToDeleteLaunchiImagesKey){ InfoPlistProcessor.DeleteLaunchiImagesKey (buildPath); } //ATSの設定 InfoPlistProcessor.SetATS (buildPath, setting.EnableATS); //ステータスバーの設定 InfoPlistProcessor.SetStatusBar (buildPath, setting.EnableStatusBar); }