private static void EditXcodeProject(string buildFolder) { PBXProject project = new PBXProject(); string path = Path.Combine(buildFolder, FileUtil.NiceWinPath("Unity-iPhone.xcodeproj/project.pbxproj")); project.ReadFromFile(path); string targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName()); if (AdvertisementSettings.enabled && AdvertisementSettings.IsPlatformEnabled(RuntimePlatform.IPhonePlayer)) { string target = Path.Combine(buildFolder, Path.Combine("UnityAds", "UnityAds.framework")); FileUtil.CopyDirectoryRecursive(Path.Combine(extensionPath, FileUtil.NiceWinPath("Editor/Resources/iOS/builds/UnityAds.framework")), target, true); project.AddFileToBuild(targetGuid, project.AddFile(Path.Combine("UnityAds", "UnityAds.framework"), "Frameworks/UnityAds.framework", PBXSourceTree.Source)); project.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/UnityAds"); project.AddFrameworkToProject(targetGuid, "AdSupport.framework", true); project.AddFrameworkToProject(targetGuid, "StoreKit.framework", false); project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false); } else { project.RemoveFile(project.FindFileGuidByRealPath(Path.Combine("UnityAds", "UnityAds.framework"))); string[] removeValues = new string[] { "$(SRCROOT)/UnityAds" }; project.UpdateBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", null, removeValues); string str5 = Path.Combine(buildFolder, "UnityAds"); if (Directory.Exists(str5)) { Directory.Delete(str5, true); } } project.AddFileToBuild(targetGuid, project.AddFile("UnityAdsConfig.h", "Classes/UnityAds/UnityAdsConfig.h")); project.WriteToFile(path); }
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 }
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 }
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()); }