TargetGuidByName() 공개 메소드

public TargetGuidByName ( string name ) : string
name string
리턴 string
예제 #1
1
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            string projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj = new PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName("Unity-iPhone");

            // システムのフレームワークを追加
            proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false);

            // 自前のフレームワークを追加
            CopyAndReplaceDirectory("Assets/Lib/mylib.framework", Path.Combine(path, "Frameworks/mylib.framework"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/mylib.framework", "Frameworks/mylib.framework", PBXSourceTree.Source));

            // ファイルを追加
            var fileName = "my_file.xml";
            var filePath = Path.Combine("Assets/Lib", fileName);
            File.Copy(filePath, Path.Combine(path, fileName));
            proj.AddFileToBuild(target, proj.AddFile(fileName, fileName, PBXSourceTree.Source));

            // Yosemiteでipaが書き出せないエラーに対応するための設定
            proj.SetBuildProperty(target, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");

            // フレームワークの検索パスを設定・追加
            proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // 書き出し
            File.WriteAllText(projPath, proj.WriteToString());
        }
    }
예제 #2
0
        private static void UpdatePbxProject(string projectPath, string buildPath)
        {
            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projectPath));

            string[] frameworks = {
                "CFNetwork.framework",
                "CoreGraphics.framework",
                "Foundation.framework",
                "MobileCoreServices.framework",
                "Security.framework",
                "SystemConfiguration.framework",
                "UIKit.framework",
                "CoreTelephony.framework",
                "CoreLocation.framework",
                "CoreData.framework",
                "UserNotifications.framework"
            };

            string[] targets = {
                proj.TargetGuidByName(PBXProject.GetUnityTargetName()),
                proj.TargetGuidByName(PBXProject.GetUnityTestTargetName())
            };

            string airshipConfig = Path.Combine(buildPath, "AirshipConfig.plist");
            if (File.Exists(airshipConfig)) {
                File.Delete(airshipConfig);
            }

            File.Copy(Path.Combine(Application.dataPath, "Plugins/iOS/AirshipConfig.plist"), airshipConfig);
            string airshipGUID = proj.AddFile("AirshipConfig.plist", "AirshipConfig.plist", PBXSourceTree.Source);

            foreach (string target in targets)
            {
                proj.AddBuildProperty(target, "OTHER_LDFLAGS", "$(inherited)");
                proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC -lz -lsqlite3");
                proj.AddFileToBuild(target, airshipGUID);

                foreach (string framework in frameworks)
                {
                    proj.AddFrameworkToProject(target, framework, false);
                    UnityEngine.Debug.Log ("Adding framework: " + framework);

                }
            }

            File.WriteAllText(projectPath, proj.WriteToString());
        }
	private static void onPostProcessBuildPlayer(BuildTarget target, string pathToBuiltProject) {
#if UNITY_4_X
		if (target == BuildTarget.iPhone) {
#else
		if (target == BuildTarget.iOS) {
#endif

#if UNITY_EDITOR_OSX
			UnityEngine.Debug.Log ("Path to built project: " + pathToBuiltProject);

			string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
			UnityEngine.Debug.Log ("Project Path: " + projPath);

			PBXProject proj = new PBXProject();
			proj.ReadFromString(File.ReadAllText(projPath));
			string projTarget = proj.TargetGuidByName("Unity-iPhone");
			UnityEngine.Debug.Log ("Project Target: " + projTarget);

			proj.AddFrameworkToProject(projTarget, "Security.framework", false);
			proj.AddBuildProperty(projTarget, "OTHER_LDFLAGS", "-ObjC -lz -lstdc++");

			File.WriteAllText(projPath, proj.WriteToString());
#endif
		}
		
		if (target == BuildTarget.WP8Player) {
			postProcessWP8Build(pathToBuiltProject);
		}
	}
 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);
 }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target != BuildTarget.iOS)
        {
            Debug.Log("Target is not iOS. JoypacXCodeBuildEditor will not run.");
            return;
        }

        // Read.
        string projectPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(path);

        UnityEditor.iOS.Xcode.PBXProject project = new UnityEditor.iOS.Xcode.PBXProject();
        project.ReadFromString(File.ReadAllText(projectPath));

#if UNITY_2019_3_OR_NEWER
        string xcodeTarget = project.GetUnityFrameworkTargetGuid();
#else
        string xcodeTarget = project.TargetGuidByName("Unity-iPhone");
#endif
        //string targetFrameworkGUID = project.GetUnityFrameworkTargetGuid();
        //string targetMainGUID = project.GetUnityMainTargetGuid();


        AddFrameworks(project, xcodeTarget);
        AddBuildProperties(project, xcodeTarget);

        EditorPlist(path);



        // Write.
        File.WriteAllText(projectPath, project.WriteToString());
    }
		public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
		{
			#if UNITY_4_6
			if (buildTarget == BuildTarget.iPhone)
			#else
			if (buildTarget == BuildTarget.iOS)
			#endif
			{
				string projPath = PBXProject.GetPBXProjectPath(path);

				// Fix on 4.6.x
				#if UNITY_4_6
				if(!projPath.Contains("Unity-iPhone.xcodeproj"))
				{
					projPath = projPath.Replace("Unity-iPhone", "Unity-iPhone.xcodeproj");
				}
				#endif

				PBXProject proj = new PBXProject();
				proj.ReadFromString(File.ReadAllText(projPath));

				string targetName = PBXProject.GetUnityTargetName();
				string target = proj.TargetGuidByName(targetName);

				proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", PBXSourceTree.Sdk));
				proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));
				proj.AddFileToBuild(target, proj.AddFile("Frameworks/AdSupport.framework", "Frameworks/AdSupport.framework", PBXSourceTree.Sdk));

				File.WriteAllText(projPath, proj.WriteToString());
			}
		}
	private static void ProcessPostBuild (BuildTarget buildTarget, string path)
	{
    string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

    PBXProject proj = new PBXProject();
    proj.ReadFromString(File.ReadAllText(projPath));

    string target = proj.TargetGuidByName("Unity-iPhone");
    //
    //Required Frameworks
    proj.AddFrameworkToProject(target, "AudioToolbox.framework", false);
    proj.AddFrameworkToProject(target, "AVFoundation.framework", false);
    proj.AddFrameworkToProject(target, "CoreGraphics.framework", false);
    proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);
    proj.AddFrameworkToProject(target, "CoreMedia.framework", false);
    proj.AddFrameworkToProject(target, "EventKit.framework", false);
    proj.AddFrameworkToProject(target, "EventKitUI.framework", false);
    proj.AddFrameworkToProject(target, "MediaPlayer.framework", false);
    proj.AddFrameworkToProject(target, "MessageUI.framework", false);
    proj.AddFrameworkToProject(target, "QuartzCore.framework", false);
    proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);

    proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.1.2.5.dylib", "Frameworks/libz.1.2.5.dylib", PBXSourceTree.Sdk));

    //Optional Frameworks
    proj.AddFrameworkToProject(target, "AdSupport.framework", true);
    proj.AddFrameworkToProject(target, "Social.framework", true);
    proj.AddFrameworkToProject(target, "StoreKit.framework", true);
    proj.AddFrameworkToProject(target, "Webkit.framework", true);

    File.WriteAllText(projPath, proj.WriteToString());
	}
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        #if UNITY_5
        var expectedTarget = BuildTarget.iOS;
        #else
        var expectedTarget = BuildTarget.iPhone;
        #endif
        if (buildTarget == expectedTarget) {
            var projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            var project = new PBXProject();
            project.ReadFromString(File.ReadAllText(projectPath));

            var target = project.TargetGuidByName("Unity-iPhone");

            foreach (var frameworkName in StrongFrameworks) {
                project.AddFrameworkToProject(target, frameworkName + ".framework", false);
            }
            foreach (var frameworkName in WeakFrameworks) {
                project.AddFrameworkToProject(target, frameworkName + ".framework", true);
            }
            foreach (var flag in LDFlags) {
                project.AddBuildProperty(target, "OTHER_LDFLAGS", flag);
            }
            foreach (var libraryName in Libraries) {
                project.AddBuildProperty(target, "OTHER_LDFLAGS", "-l" + libraryName);
            }

            File.WriteAllText(projectPath, project.WriteToString());
        }
    }
예제 #9
0
        static void runPodUpdate(string path)
        {
            // Copy the podfile into the project.
            string podfile = "Assets/GoogleMobileAds/Editor/Podfile";
            string destpodfile = path + "/Podfile";
            if(!System.IO.File.Exists(destpodfile))
            {
                FileUtil.CopyFileOrDirectory(podfile, destpodfile);
            }

            try
            {
                CocoaPodHelper.Update(path);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log("Could not create a new Xcode project with CocoaPods: " +
                    e.Message);
            }

            #if UNITY_5
                string pbxprojPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
                PBXProject project = new PBXProject();
                project.ReadFromString(File.ReadAllText(pbxprojPath));
                string target = project.TargetGuidByName("Unity-iPhone");

                project.SetBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
                project.AddBuildProperty(target, "OTHER_LDFLAGS", "$(inherited)");

                File.WriteAllText(pbxprojPath, project.WriteToString());
            #else
                UnityEngine.Debug.Log("Unable to modify build settings in XCode project. Build " +
                        "settings must be set manually");
            #endif
        }
예제 #10
0
	public static void OnPostProcessBuild(BuildTarget target, string path)
	{

		if (target == BuildTarget.iOS)
		{
			// Get target for Xcode project
			string projPath = PBXProject.GetPBXProjectPath(path);
			PBXProject proj = new PBXProject();
			proj.ReadFromString(File.ReadAllText(projPath));

			string targetName = PBXProject.GetUnityTargetName();
			string projectTarget = proj.TargetGuidByName(targetName);

			// Add dependencies
			proj.AddFrameworkToProject(projectTarget, "AssetsLibrary.framework", false);
			proj.AddFrameworkToProject(projectTarget, "CoreText.framework", false);
			proj.AddFrameworkToProject(projectTarget, "MobileCoreServices.framework", false);
			proj.AddFrameworkToProject(projectTarget, "QuickLook.framework", false);
			proj.AddFrameworkToProject(projectTarget, "Security.framework", false);

			File.WriteAllText(projPath, proj.WriteToString());

			InsertAuthCodeIntoControllerClass(path);
			InsertUILoadedCallbackIntoControllerClass(path);
		}
	}
예제 #11
0
    public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        Debug.LogWarning("IphoneX Fiter");
        if (target != BuildTarget.iOS)
        {
            Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
            return;
        }
        // Create a new project object from build target
        UnityEditor.iOS.Xcode.PBXProject project = new UnityEditor.iOS.Xcode.PBXProject();
        string configFilePath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(pathToBuiltProject);

        project.ReadFromFile(configFilePath);
        string targetGuid = project.TargetGuidByName("Unity-iPhone");
        string debug      = project.BuildConfigByName(targetGuid, "Debug");
        string release    = project.BuildConfigByName(targetGuid, "Release");

        project.AddBuildPropertyForConfig(debug, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");
        project.AddBuildPropertyForConfig(release, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");

        project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", true);
        project.AddFrameworkToProject(targetGuid, "Security.framework", true);
        project.AddFrameworkToProject(targetGuid, "libz.tbd", true);
        project.AddFrameworkToProject(targetGuid, "libc++.tbd", true);

        project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");

        project.WriteToFile(configFilePath);

        EditSuitIpXCode(pathToBuiltProject);
    }
예제 #12
0
    private static void OnPostprocessBuildIOS(string pathToBuiltProject)
    {
        // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module
#if UNITY_IOS
        //Handle plist
        string        plistPath = pathToBuiltProject + "/Info.plist";
        PlistDocument plist     = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
        PlistElementDict rootDict = plist.root;

        rootDict.SetString("CFBundleVersion", "1.0.67");
        rootDict.SetString("NSPhotoLibraryUsageDescription", "Use Photo");
        rootDict.SetString("NSPhotoLibraryAddUsageDescription", "Use Photo 11");
        rootDict.SetString("NSCameraUsageDescription", "Use Camera");

        File.WriteAllText(plistPath, plist.WriteToString());

        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "CoreImage.framework", false);
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "Accelerate.framework", false);
        string target = proj.TargetGuidByName("Unity-iPhone");
        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity"));

        string[] filesToCopy = new string[]
        {
        };

        for (int i = 0; i < filesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine("../PluginSource/source", filesToCopy[i]);
            var dstLocalPath = "Libraries/" + filesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        File.WriteAllText(projPath, proj.WriteToString());

        CopyFile("GestureFile/libpaddle_capi_layers.a", "libpaddle_capi_layers.a", pathToBuiltProject);
        CopyFile("pose/pose.bin", "pose.bin", pathToBuiltProject);
        //  CopyFile("pose/opencv2.framework.zip", "opencv2.framework.zip", pathToBuiltProject);
        // CopyFile("IOS_Pose/libpaddle_capi_layers.a" ,pathToBuiltProject);
#endif
    }
    public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject) {
      if (buildTarget != BuildTarget.iOS) {
        return;
      }

      PBXProject project = new PBXProject();
      string pbxProjectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
      project.ReadFromString(File.ReadAllText(pbxProjectPath));

      string target = project.TargetGuidByName(PBXProject.GetUnityTargetName());
      string testTarget = project.TargetGuidByName(PBXProject.GetUnityTestTargetName());

      // Linker flags.
      project.SetBuildProperty(target, "ARCHS", "$(ARCHS_STANDARD)");
      project.SetBuildProperty(testTarget, "ARCHS", "$(ARCHS_STANDARD)");
      project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
      project.AddBuildProperty(testTarget, "OTHER_LDFLAGS", "-ObjC");
      project.AddBuildProperty(target, "OTHER_LDFLAGS", "-lz");
      project.AddBuildProperty(testTarget, "OTHER_LDFLAGS", "-lz");

      // Search paths.
      project.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
      project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

      // Framework dependencies.
      project.AddFrameworkToProject(target, "AVFoundation.framework", true);
      project.AddFrameworkToProject(target, "Accelerate.framework", true);
      project.AddFrameworkToProject(target, "CFNetwork.framework", true);
      project.AddFrameworkToProject(target, "CoreBluetooth.framework", true);
      project.AddFrameworkToProject(target, "CoreText.framework", true);
      project.AddFrameworkToProject(target, "MediaPlayer.framework", true);
      project.AddFrameworkToProject(target, "MediaToolbox.framework", true);
      project.AddFrameworkToProject(target, "Metal.framework", true);
      project.AddFrameworkToProject(target, "Security.framework", true);
      project.AddFrameworkToProject(target, "SystemConfiguration.framework", true);

      // Dynamic library dependencies.
      string sqlite3dylibGuid = project.AddFile("usr/lib/libsqlite3.dylib",
                                                "usr/lib/libsqlite3.dylib", PBXSourceTree.Sdk);
      project.AddFileToBuild(target, sqlite3dylibGuid);
      string libCppdylibGuid = project.AddFile("usr/lib/libc++.dylib",
                                               "usr/lib/libc++.dylib", PBXSourceTree.Sdk);
      project.AddFileToBuild(target, libCppdylibGuid);

      File.WriteAllText(pbxProjectPath, project.WriteToString());
    }
예제 #14
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        UnityEngine.Debug.Log("OnPostprocessBuild "+buildTarget+" "+path);

        if (buildTarget == BuildTarget.iOS) {

            string projectPath = PBXProject.GetPBXProjectPath(path);

            PBXProject project = new PBXProject();
            project.ReadFromFile(projectPath);

            UnityEngine.Debug.Log(PBXProject.GetUnityTargetName());
            string target = project.TargetGuidByName(PBXProject.GetUnityTargetName());

            UnityEngine.Debug.Log(target);

            // Add build settings for CocoaPods
            project.AddBuildProperty(target, "HEADER_SEARCH_PATHS", "$(inherited)");
            project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            project.AddBuildProperty(target, "OTHER_CFLAGS", "$(inherited)");
            project.AddBuildProperty(target, "OTHER_LDFLAGS", "$(inherited)");

            // Disable Bitcode
            project.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

            // Copy Podfile into project
            string unityProjectRootPath = Path.GetFullPath("./").Normalize();
            UnityEngine.Debug.Log(unityProjectRootPath);

            // Default src location is the project root
            FileUtil.ReplaceFile("Assets/DeltaDNAAds/Editor/iOS/Podfile", path + "/Podfile");

            // Set Podfile platform version to match Unity
            #if UNITY_5_5_OR_NEWER
            var targetOSVersion = PlayerSettings.iOS.targetOSVersionString;
            string iosPlatform = targetOSVersion.ToString();
            UnityEngine.Debug.Log(iosPlatform);
            #else
            var targetOSVersion = PlayerSettings.iOS.targetOSVersion;
            string iosPlatform = targetOSVersion.ToString().Substring(4).Replace('_', '.');
            #endif

            var podfile = new List<string>(File.ReadAllLines(path + "/Podfile"));
            podfile = new List<string>(podfile.Select(e => e.StartsWith("platform") ? string.Format("platform :ios, '{0}'", iosPlatform) : e).AsEnumerable());
            File.WriteAllLines(path + "/Podfile", podfile.ToArray());

            // Update the XCode project on disk
            project.WriteToFile(projectPath);

            // Run pod update
            Process proc = new Process();
            proc.StartInfo.FileName = "/usr/local/bin/pod";
            proc.StartInfo.Arguments = "install --project-directory=\""+path+"\"";
            proc.StartInfo.UseShellExecute = false;
            proc.Start();
            proc.WaitForExit();
        }
    }
        private static void configureSwiftBuild(string targetPath)
        {
            var projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(targetPath);
            var proj     = new UnityEditor.iOS.Xcode.PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));

#if UNITY_2019_3_OR_NEWER
            var targetGuid = proj.GetUnityFrameworkTargetGuid();
#else
            var targetGuid = proj.TargetGuidByName("Unity-iPhone");
#endif

            proj.SetBuildProperty(targetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");

            proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0");
#if UNITY_2019_3_OR_NEWER
            string podFilePath        = Path.Combine(targetPath, "Podfile");
            string podFileContents    = File.ReadAllText(podFilePath);
            string targetUnityiPhone  = "\ntarget 'Unity-iPhone' do";
            string inheritSearchPaths = "\n inherit! :search_paths";

            if (podFileContents.Contains("Unity-iPhone"))
            {
                podFileContents =
                    podFileContents.Replace(targetUnityiPhone, targetUnityiPhone + inheritSearchPaths);
                File.WriteAllText(podFilePath, podFileContents);
            }
            else
            {
                File.AppendAllText(podFilePath, targetUnityiPhone + inheritSearchPaths + "\nend");
            }

            File.AppendAllText(podFilePath,
                               "\npost_install do |installer|\n   installer.pods_project.targets.each do |target|\n     target.build_configurations.each do |config|\n       if ['RxSwift', 'Willow'].include? target.name\n         config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'\n       end\n     end\n   end\n end");

            var iphoneGuid = proj.GetUnityMainTargetGuid();
            proj.SetBuildProperty(iphoneGuid, "SWIFT_OBJC_BRIDGING_HEADER",
                                  "Libraries/ScaleMonk Ads/Plugins/iOS/SMAds-Bridging-Header.h");
#else
            proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/ScaleMonk Ads/Plugins/iOS/SMAds-Bridging-Header.h");

            using (var sw = File.AppendText(targetPath + "/Podfile"))
            {
                sw.WriteLine("\npost_install do |installer|\n   installer.pods_project.targets.each do |target|\n     target.build_configurations.each do |config|\n       if ['RxSwift', 'Willow'].include? target.name\n         config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'\n       end\n     end\n   end\n end");
            }
#endif



            proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
            proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            File.WriteAllText(projPath, proj.WriteToString());
        }
 public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
 {
     if (buildTarget == BuildTarget.iOS) {
         string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
         PBXProject proj = new PBXProject();
         proj.ReadFromString(File.ReadAllText(projPath));
         string target = proj.TargetGuidByName("Unity-iPhone");
         proj.AddFrameworkToProject(target, "WebKit.framework", false);
         File.WriteAllText(projPath, proj.WriteToString());
     }
 }
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        string projPath = Path.Combine(path, "Unity-iPhone.xcodeproj/project.pbxproj");
        PBXProject proj = new PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        string target = proj.TargetGuidByName("Unity-iPhone");

        proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.1.2.5.tbd", "Frameworks/libz.1.2.5.tbd", PBXSourceTree.Sdk));

        File.WriteAllText(projPath, proj.WriteToString());
    }
예제 #18
0
    private static void OnPostprocessBuildIOS(string pathToBuiltProject)
    {
        // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module
                #if UNITY_IOS
        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        string target = proj.TargetGuidByName("Unity-iPhone");

        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity"));

        string[] filesToCopy = new string[]
        {
            "gldefine.h",
            "PlatformBase.h",
            "RenderAPI_Metal.mm",
            "RenderAPI_OpenGLCoreES.cpp",
            "RenderAPI.cpp",
            "RenderAPI.h",
            "RenderingPlugin.cpp",
            "Unity/IUnityInterface.h",
            "Unity/IUnityGraphics.h",
            "Unity/IUnityGraphicsMetal.h",
            "Impl/CMeshGLCoreES.cpp",
            "Impl/CMeshGLCoreES.h",
            "Impl/CMeshPartGLCoreES.cpp",
            "Impl/CMeshPartGLCoreES.h",
            "Impl/CVertexAttribBindingGLCoreES.cpp",
            "Impl/CVertexAttribBindingGLCoreES.h",

            "Impl/CMeshMetal.h",
            "Impl/CMeshMetal.mm",
            "Impl/CMeshPartMetal.h",
            "Impl/CMeshPartMetal.mm",
        };

        for (int i = 0; i < filesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine("../PluginSource/source", filesToCopy[i]);
            var dstLocalPath = "Libraries/NativeRendering/" + filesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/NativeRendering/"));
            Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/NativeRendering/Unity/"));
            Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/NativeRendering/Impl/"));
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        File.WriteAllText(projPath, proj.WriteToString());
                #endif // #if UNITY_IOS
    }
예제 #19
0
    private static void fixPbxproject(string path)
    {
#if UNITY_IOS
        UnityEditor.iOS.Xcode.PBXProject pbxProj = new UnityEditor.iOS.Xcode.PBXProject();
        pbxProj.ReadFromFile(path);

        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");
        pbxProj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");

        pbxProj.WriteToFile(path);

        AddDynamicFrameworksForUnity5(path);
#endif
    }
    private static void AddGrowthbeatDependencyFramework(string path)
    {
        string projectPath = PBXProject.GetPBXProjectPath(path);
        PBXProject pbxProject = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(projectPath));
        string target = pbxProject.TargetGuidByName("Unity-iPhone");

        pbxProject.AddFrameworkToProject(target, "AdSupport.framework", false);
        pbxProject.AddFrameworkToProject(target, "SafariServices.framework", false);
        pbxProject.AddFrameworkToProject(target, "Security.framework", false);

        File.WriteAllText(projectPath, pbxProject.WriteToString());
    }
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        #if UNITY_5
        if (buildTarget == BuildTarget.iOS)
        #else
        if (buildTarget == BuildTarget.iPhone)
        #endif
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));

            string target = proj.TargetGuidByName("Unity-iPhone");

            // Add custom system frameworks. Duplicate frameworks are ignored.
            // needed by our native plugin in Assets/Plugins/iOS
            proj.AddFrameworkToProject(target, "Security.framework", false /*not weak*/);
            proj.AddFrameworkToProject(target, "Social.framework", false /*not weak*/);
            proj.AddFrameworkToProject(target, "Accounts.framework", false /*not weak*/);
            proj.AddFrameworkToProject(target, "MediaPlayer.framework", false /*not weak*/);
            proj.AddFrameworkToProject(target, "MessageUI.framework", false /*not weak*/);
            proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false /*not weak*/);

            proj.AddFrameworkToProject(target, "libc++.dylib", false /*not weak*/);

            // Add our framework directory to the framework include path
            //proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            //proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // Set a custom link flag
            proj.AddBuildProperty(target, "GCC_PREPROCESSOR_DEFINITIONS", "$(CONFIGURATION) $(inherited)");
            proj.AddBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");

            File.WriteAllText(projPath, proj.WriteToString());
        }

        // edit Info.plist
        /*var plistPath = Path.Combine(path, "Info.plist");

        var plist = new PlistDocument();

        plist.ReadFromFile(plistPath);

        plist.root.SetString("UIBackgroundModes", "voip");

        plist.WriteToFile(plistPath);*/
    }
예제 #22
0
    public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        #if UNITY_IOS
        string temp = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj = new PBXProject();
        proj.ReadFromString(File.ReadAllText(temp));

        string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
        proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
        proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-lc++");
        proj.AddBuildProperty(target, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");
        proj.AddBuildProperty(target, "CLANG_ENABLE_MODULES","YES");

        File.WriteAllText(temp, proj.WriteToString());
        #endif
    }
	public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
	{
		if (buildTarget == BuildTarget.iOS)
		{
			string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

			PBXProject proj = new PBXProject();
			proj.ReadFromString(File.ReadAllText(projPath));

			string target = proj.TargetGuidByName("Unity-iPhone");

			proj.AddFileToBuild(target, proj.AddFile("usr/lib/Security.framework", "Frameworks/Security.framework", PBXSourceTree.Sdk));
			proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");

			File.WriteAllText(projPath, proj.WriteToString());
		}
	}
예제 #24
0
    //设置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();//写入文件保存
    }
예제 #25
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
    #if UNITY_IPHONE
        if (buildTarget == BuildTarget.iOS)
        {
            Debug.Log("DisableBitCodePostProcessor - start");
            string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
            UnityEditor.iOS.Xcode.PBXProject pbxProject = new UnityEditor.iOS.Xcode.PBXProject();
            pbxProject.ReadFromFile(projectPath);

            string target = pbxProject.TargetGuidByName("Unity-iPhone");
            pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

            pbxProject.WriteToFile(projectPath);
            Debug.Log("DisableBitCodePostProcessor - done");
        }
    #endif
    }
		public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
		{
			if (buildTarget == BuildTarget.iOS)
			{
				string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
				
				PBXProject proj = new PBXProject();
				proj.ReadFromString(File.ReadAllText(projPath));
				
				string target = proj.TargetGuidByName("Unity-iPhone");
				
				proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", PBXSourceTree.Sdk));
				proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));
				proj.AddFileToBuild(target, proj.AddFile("Frameworks/AdSupport.framework", "Frameworks/AdSupport.framework", PBXSourceTree.Sdk));
				
				File.WriteAllText(projPath, proj.WriteToString());
			}
		}
예제 #27
0
파일: XcodeSetting.cs 프로젝트: li5414/Usdk
 private static void SetEmbedFrameworks(PBXProject proj, string filePath, string fileGuid)
 {
     if (embedFrameworksTable != null)
     {
         string    fileName = Path.GetFileName(filePath);
         string    target   = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
         ArrayList addList  = embedFrameworksTable["+"] as ArrayList;
         if (addList != null)
         {
             foreach (string i in addList)
             {
                 if (fileName == i)
                 {
                     PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
                 }
             }
         }
     }
 }
    private static string GetUnityIPhoneTargetGuid(string path)
    {
        var proj = new UnityEditor.iOS.Xcode.PBXProject();

        proj.ReadFromString(File.ReadAllText(path));
        string mainTargetGuid = null;

        var unityMainTargetGuidMethod = proj.GetType().GetMethod("GetUnityMainTargetGuid");

        if (unityMainTargetGuidMethod != null)
        {
            mainTargetGuid = (string)unityMainTargetGuidMethod.Invoke(proj, null);
        }
        else
        {
            mainTargetGuid = proj.TargetGuidByName("Unity-iPhone");
        }
        return(mainTargetGuid);
    }
    public static void OnPostProcessBuildIOS(string pathToBuiltProject)
    {
#if UNITY_IOS
        string     projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "Photos.framework", false);
        File.WriteAllText(projPath, proj.WriteToString());

        string plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
        var    plist     = new PlistDocument();
        plist.ReadFromFile(plistPath);

        const string key         = "NSPhotoLibraryUsageDescription";
        const string description = "Camera roll access permission is necessary for saving an image.";
        plist.root.SetString(key, description);

        plist.WriteToFile(plistPath);
#endif //UNITY_IOS
    }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        #if UNITY_IPHONE
            if (target != BuildTarget.iOS) return;

            string buildName = Path.GetFileNameWithoutExtension(path);
            string pbxprojPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();

            proj.ReadFromString(File.ReadAllText(pbxprojPath));

            string buildTarget = proj.TargetGuidByName("Unity-iPhone");

            DirectoryInfo projectParent = Directory.GetParent(Application.dataPath);

            char divider = Path.DirectorySeparatorChar;

            DirectoryInfo destinationFolder =
                new DirectoryInfo(path + divider + "Frameworks");

            foreach(DirectoryInfo file in destinationFolder.GetDirectories()) {
                string filePath = "Frameworks/"+ file.Name;
                proj.AddFile(filePath, filePath, PBXSourceTree.Source);
                proj.AddFrameworkToProject (buildTarget, file.Name, false);
            }

            proj.SetBuildProperty(
                buildTarget, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Frameworks"
            );
            proj.AddBuildProperty(
                buildTarget, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"
            );
            proj.SetBuildProperty(buildTarget, "CLANG_ENABLE_MODULES", "YES");

            File.WriteAllText(pbxprojPath, proj.WriteToString());
        #endif
    }
예제 #31
0
파일: XcodeSetting.cs 프로젝트: li5414/Usdk
 //设置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);
             }
         }
     }
 }
예제 #32
0
파일: XcodeSetting.cs 프로젝트: li5414/Usdk
 //设置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);
             }
         }
     }
 }
예제 #33
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS) {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));

            string target = proj.TargetGuidByName("Unity-iPhone");

            // Add user packages to project. Most other source or resource files and packages
            // can be added the same way.
            /*
            CopyAndReplaceDirectory("NativeAssets/TestLib.bundle", Path.Combine(path, "Frameworks/TestLib.bundle"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.bundle",
                                                     "Frameworks/TestLib.bundle", PBXSourceTree.Source));

            CopyAndReplaceDirectory("NativeAssets/TestLib.framework", Path.Combine(path, "Frameworks/TestLib.framework"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.framework",
                                                     "Frameworks/TestLib.framework", PBXSourceTree.Source));
            */
            // Add custom system frameworks. Duplicate frameworks are ignored.
            // needed by our native plugin in Assets/Plugins/iOS

            proj.AddFrameworkToProject(target, "MessageUI.framework", false /*not weak*/);

            // Add our framework directory to the framework include path
            proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // Set a custom link flag
            proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");

            File.WriteAllText(projPath, proj.WriteToString());
        }
    }
예제 #34
0
    static void _AddDeviceCapabilities(string path)
    {
        string pbxprojPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        
        PBXProject project = new PBXProject();
        project.ReadFromString(File.ReadAllText(pbxprojPath));
        string target = project.TargetGuidByName("Unity-iPhone");

        project.AddFrameworkToProject(target, "AdSupport.framework", false);
        project.AddFrameworkToProject(target, "AudioToolbox.framework", false);
        project.AddFrameworkToProject(target, "AVFoundation.framework", false);
        project.AddFrameworkToProject(target, "CoreGraphics.framework", false);
        project.AddFrameworkToProject(target, "CoreTelephony.framework", false);
        project.AddFrameworkToProject(target, "EventKit.framework", false);
        project.AddFrameworkToProject(target, "EventKitUI.framework", false);
        project.AddFrameworkToProject(target, "MessageUI.framework", false);
        project.AddFrameworkToProject(target, "StoreKit.framework", false);
        project.AddFrameworkToProject(target, "SystemConfiguration.framework", false);

        project.SetBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");

        File.WriteAllText(pbxprojPath, project.WriteToString());

        string infoPlistPath = Path.Combine(path, "./Info.plist");
        PlistDocument plist = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(infoPlistPath));

        PlistElementDict rootDict = plist.root;
        PlistElementArray deviceCapabilityArray = rootDict.CreateArray("UIRequiredDeviceCapabilities");
        deviceCapabilityArray.AddString("armv7");
        deviceCapabilityArray.AddString("gamekit"); 

        rootDict.SetBoolean("UIRequiresFullScreen", true);

        File.WriteAllText(infoPlistPath, plist.WriteToString());
    }
	public static void PatchXcodeProject (string pathToBuiltProject)
	{
		PBXProject project = new PBXProject();
		
		string projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);

		projectPath = checkPBXProjectPath(projectPath);

		project.ReadFromFile(projectPath);
		
		string guid = project.TargetGuidByName("Unity-iPhone");
		project.AddFrameworkToProject(guid, "ExternalAccessory.framework", false);
		
		// The following settings lead to a quicker build
		string releaseConfig = project.BuildConfigByName(guid, "Release");
		project.SetBuildPropertyForConfig(releaseConfig, "DEBUG_INFORMATION_FORMAT", "dwarf");
		project.SetBuildPropertyForConfig(releaseConfig, "ONLY_ACTIVE_ARCH", "YES");
		// XCode7 enables BitCode for all projects by default.  Neither the Structure SDK nor Unity support BitCode at this time
		project.SetBuildPropertyForConfig(releaseConfig, "ENABLE_BITCODE", "NO");
		string debugConfig = project.BuildConfigByName(guid, "Debug");
		project.SetBuildPropertyForConfig(debugConfig, "ENABLE_BITCODE", "NO"); 
		project.WriteToFile(projectPath);
	}
예제 #36
0
		static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
		{
			#if UNITY_5
			if (target == BuildTarget.WSAPlayer || target == BuildTarget.WP8Player)
			#else
			if (target == BuildTarget.MetroPlayer || target == BuildTarget.WP8Player)
			#endif
			{
				#if UNITY_WP8 || UNITY_5
				var productName = PlayerSettings.productName.Replace(" ", "").Replace("_", "");
				#else
				var productName = PlayerSettings.productName;
				#endif
				
				#if UNITY_5
				if (EditorUserBuildSettings.wsaSDK == WSASDK.UniversalSDK81 && EditorUserBuildSettings.activeBuildTarget != BuildTarget.WP8Player)
				#else
				if (EditorUserBuildSettings.metroSDK == MetroSDK.UniversalSDK81 && EditorUserBuildSettings.activeBuildTarget != BuildTarget.WP8Player)
				#endif
				{
					var projPath = string.Format("{0}/{1}/{1}.Shared/{1}.Shared.projItems", pathToBuiltProject, productName);
					Debug.Log("Modifying Proj: " + projPath);
					var doc = XDocument.Load(projPath);
					addPostProjectReferences(doc, pathToBuiltProject, string.Format("/{0}.Shared", productName), productName, "$(MSBuildThisFileDirectory)");
					doc.Save(projPath);

					projPath = string.Format("{0}/{1}/{1}.Windows/{1}.Windows.csproj", pathToBuiltProject, productName);
					Debug.Log("Modifying Proj: " + projPath);
					doc = XDocument.Load(projPath);
					addPostProjectCompilerDirectives(doc);
					doc.Save(projPath);

					projPath = string.Format("{0}/{1}/{1}.WindowsPhone/{1}.WindowsPhone.csproj", pathToBuiltProject, productName);
					Debug.Log("Modifying Proj: " + projPath);
					doc = XDocument.Load(projPath);
					addPostProjectCompilerDirectives(doc);
					doc.Save(projPath);
				}
				else
				{
					var projPath = string.Format("{0}/{1}/{1}.csproj", pathToBuiltProject, productName);
					Debug.Log("Modifying Proj: " + projPath);

					var doc = XDocument.Load(projPath);
					addPostProjectCompilerDirectives(doc);
					addPostProjectReferences(doc, pathToBuiltProject, "", productName, "");
					doc.Save(projPath);
				}
			}
			#if UNITY_IOS && UNITY_5
			else if (target == BuildTarget.iOS)
			{
				string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

				var proj = new PBXProject();
				proj.ReadFromString(File.ReadAllText (projPath));

				string targetID = proj.TargetGuidByName ("Unity-iPhone");

				// set custom link flags
				proj.AddBuildProperty (targetID, "OTHER_LDFLAGS", "-all_load");
				proj.AddBuildProperty (targetID, "OTHER_LDFLAGS", "-ObjC");

				// add frameworks
				proj.AddFrameworkToProject(targetID, "AdSupport.framework", true);
				proj.AddFrameworkToProject(targetID, "CoreTelephony.framework", true);
				proj.AddFrameworkToProject(targetID, "EventKit.framework", true);
				proj.AddFrameworkToProject(targetID, "EventKitUI.framework", true);
				proj.AddFrameworkToProject(targetID, "iAd.framework", true);
				proj.AddFrameworkToProject(targetID, "MessageUI.framework", true);
				proj.AddFrameworkToProject(targetID, "StoreKit.framework", true);
				proj.AddFrameworkToProject(targetID, "Security.framework", true);
				proj.AddFrameworkToProject(targetID, "GameKit.framework", true);
				proj.AddFrameworkToProject(targetID, "GoogleMobileAds.framework", false);

				// change GoogleMobileAds to use reletive path
				string projData = proj.WriteToString();
				projData = projData.Replace
				(
					@"/* GoogleMobileAds.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleMobileAds.framework; path = System/Library/Frameworks/GoogleMobileAds.framework; sourceTree = SDKROOT; };",
					@"/* GoogleMobileAds.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleMobileAds.framework; path = Frameworks/GoogleMobileAds.framework; sourceTree = ""<group>""; };"
					//@"/* GoogleMobileAds.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleMobileAds.framework; path = """ + pathToBuiltProject+"/Frameworks/GoogleMobileAds.framework" + @"""; sourceTree = ""<absolute>""; };"
				);

				// change framework search path to include local framework directory
				projData = projData.Replace
				(
					@"FRAMEWORK_SEARCH_PATHS = ""$(inherited)"";",
					@"FRAMEWORK_SEARCH_PATHS = (""$(inherited)"", ""$(PROJECT_DIR)/Frameworks"",);"
				);

				// save proj data
				File.WriteAllText(projPath, projData);

				// create Frameworks folder if one doesn't exists
				if (!Directory.Exists(pathToBuiltProject+"/Frameworks/")) Directory.CreateDirectory(pathToBuiltProject+"/Frameworks/");

				// extract GoogleMobileAds.framework.zip to xcode framework path
				if (!Directory.Exists(pathToBuiltProject+"/Frameworks/GoogleMobileAds.framework/"))
				{
					var startInfo = new System.Diagnostics.ProcessStartInfo();
					startInfo.Arguments = @"""" + Application.dataPath+"/Plugins/IOS/GoogleMobileAds.framework.zip" + @""" -d """ + pathToBuiltProject+@"/Frameworks/""";
					startInfo.FileName = "unzip";
					startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
					startInfo.CreateNoWindow = true;
					using (var process = System.Diagnostics.Process.Start(startInfo))
					{
						process.WaitForExit();
						int exitCode = process.ExitCode;
						if (exitCode != 0) Debug.LogError("Failed to unzip GoogleMobileAds.framework.zip with ErrorCode: " + exitCode);
					}
				}
			}
			#endif
    	}
    private static void OnPostprocessBuildIOS(string pathToBuiltProject)
    {
        // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module
                #if UNITY_IOS
        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "AssetsLibrary.framework", false);
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "Accelerate.framework", false);
        string target = proj.TargetGuidByName("Unity-iPhone");

        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Sturfee/Plugins/iOS/Shared"));

        string[] sturGLoaderfilesToCopy = new string[]
        {
            "PlatformBase.hpp",
            "UnityInterface.hpp",
        };

        string[] sharedFilesToCopy = new string[]
        {
            "SturgProcesser.hpp",
            "SFDataStream.hpp",
            "SFLogger.hpp",
        };

        string[] indiosFilesToCopy = new string[]
        {
            "IndiosUnityInterface.hpp",
            "Indios.hpp"
        };

        for (int i = 0; i < sturGLoaderfilesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine(Path.Combine(Application.dataPath, "Sturfee/Plugins/iOS/SturGLoader/Include"), sturGLoaderfilesToCopy[i]);
            var dstLocalPath = "Libraries/Sturfee/Plugins/iOS/SturGLoader/Include/" + sturGLoaderfilesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        for (int i = 0; i < sharedFilesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine(Path.Combine(Application.dataPath, "Sturfee/Plugins/iOS/Shared"), sharedFilesToCopy[i]);
            var dstLocalPath = "Libraries/Sturfee/Plugins/iOS/Shared/" + sharedFilesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        for (int i = 0; i < indiosFilesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine(Path.Combine(Application.dataPath, "Sturfee/Plugins/iOS/Indios/Include"), indiosFilesToCopy[i]);
            var dstLocalPath = "Libraries/Sturfee/Plugins/iOS/Indios/Include/" + indiosFilesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        File.WriteAllText(projPath, proj.WriteToString());
                #endif // #if UNITY_IOS
    }
        /// <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());
        }
예제 #39
0
	public static void OnPostProcessBuild (BuildTarget buildTarget, string path)
	{
		#if UNITY_ANDROID

		#elif UNITY_IPHONE
		string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
		PBXProject pbxProj = new PBXProject ();
		pbxProj.ReadFromFile (projPath);
		string target = pbxProj.TargetGuidByName (PBXProject.GetUnityTargetName ());

		pbxProj.AddFrameworkToProject (target, "AssetsLibrary.framework", false);
		pbxProj.AddFrameworkToProject (target, "AudioToolbox.framework", false);
		pbxProj.AddFrameworkToProject (target, "AVFoundation.framework", false);
		pbxProj.AddFrameworkToProject (target, "CFNetwork.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreAudio.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreLocation.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreMedia.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreTelephony.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreVideo.framework", false);
		pbxProj.AddFrameworkToProject (target, "CoreGraphics.framework", false);
		pbxProj.AddFrameworkToProject (target, "ImageIO.framework", false);

		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libc++.dylib", "Frameworks/libc++.dylib", PBXSourceTree.Sdk));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libc++abi.dylib", "Frameworks/libc++abi.dylib", PBXSourceTree.Sdk));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", PBXSourceTree.Sdk));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libstdc++.dylib", "Frameworks/libstdc++.dylib", PBXSourceTree.Sdk));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libxml2.dylib", "Frameworks/libxml2.dylib", PBXSourceTree.Sdk));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile ("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));

		pbxProj.AddFrameworkToProject (target, "MapKit.framework", false);
		pbxProj.AddFrameworkToProject (target, "OpenGLES.framework", false);
		pbxProj.AddFrameworkToProject (target, "QuartzCore.framework", false);
		pbxProj.AddFrameworkToProject (target, "SystemConfiguration.framework", false);
		pbxProj.AddFrameworkToProject (target, "UIKit.framework", false);

		DirectoryInfo di = new DirectoryInfo (Application.dataPath);
		string rongCloudLibFloder = Path.Combine (di.Parent.FullName, "RongCloudLib");




		CopyAndReplaceDirectory(Path.Combine (rongCloudLibFloder, "RongIMLib.framework"), Path.Combine(path, "Frameworks/RongIMLib.framework"));
		pbxProj.AddFileToBuild(target, pbxProj.AddFile("Frameworks/RongIMLib.framework", "Frameworks/RongIMLib.framework", PBXSourceTree.Source));


//		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (rongCloudLibFloder, "RongIMLib.framework"), "Frameworks/RongIMLib.framework", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/RongCloudBinding.m"), "Libraries/RongCloudBinding.m", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/RongCloudManager.m"), "Libraries/RongCloudManager.m", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/RongCloudManager.h"), "Libraries/RongCloudManager.h", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/GroupOperationMessage.h"), "Libraries/GroupOperationMessage.h", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/GroupOperationMessage.m"), "Libraries/GroupOperationMessage.m", PBXSourceTree.Absolute));

		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/GroupRequestMessage.h"), "Libraries/GroupRequestMessage.h", PBXSourceTree.Absolute));
		pbxProj.AddFileToBuild (target, pbxProj.AddFile (Path.Combine (Application.dataPath, "Editor/RongCloud/iOS/GroupRequestMessage.m"), "Libraries/GroupRequestMessage.m", PBXSourceTree.Absolute));



		pbxProj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
		pbxProj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

		pbxProj.WriteToFile (projPath);
		PlistDocument plist = new PlistDocument ();
		string plistPath = Path.Combine (path, "Info.plist");
		plist.ReadFromFile (plistPath);
		var deviceCapabilities = plist.root ["UIRequiredDeviceCapabilities"].AsArray ();
		deviceCapabilities.AddString ("front-facing-camera");
		deviceCapabilities.AddString ("video-camera");
//		plist.root.SetBoolean ("LSHasLocalizedDisplayName", true);

		plist.WriteToFile (plistPath);
		#endif

	}
예제 #40
0
    public static void OnPostProcessBuildFirst(BuildTarget bt, string path)
    {
        if(bt == BuildTarget.WebGL){
            moveResources("levels",false);
        }else{
            moveResources("webLevels",false);
        }
        if(bt == BuildTarget.iOS || bt == BuildTarget.StandaloneOSXUniversal){
            moveResources("achievementIcons",false);
        }
        AssetDatabase.Refresh();
        switch(lastPlatform){
            case platform.osx:
                if(PlayerSettings.useMacAppStoreValidation){
                    runShell("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_osx/fixAndSign.sh");
                }else{
                    runShell("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_osx/fixSignAndOpen.sh");
                }
                break;
            case platform.ios:
                //I know I should make the paths relative but you can't tell me what to do
                runShell("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_ios/build.sh");

                //find project
                string projectPath = "/Volumes/Jesper Ext/unity/ZeGame/ZeGame_ios/xcode/Unity-iPhone.xcodeproj/project.pbxproj";
                PBXProject project = new PBXProject();
                project.ReadFromFile(projectPath);
                string targetGuid = project.TargetGuidByName("Unity-iPhone");

                //add cloudkit framework (this is still easy)
                project.AddFrameworkToProject(targetGuid,"CloudKit.framework",false);

                //copy the entitlements file, you should generate this once
                //using xcode, then put it somewhere on your disk so
                //you can copy it to this location later
                File.Copy("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_ios/ZeGame.entitlements","/Volumes/Jesper Ext/unity/ZeGame/ZeGame_ios/xcode/Unity-iPhone/ZeGame.entitlements");

                //now this is where it gets messy, because the PBXProject
                //class doesn't support enabling iCloud so you'll
                //have to change the string manually
                //I suggest you build your xcode project once (without
                //playing it automatically, so you'll have to remove
                // BuildOptions.AutoRunPlayer; from the buildoptions
                //then duplicate your xcode project folder and enable
                //iCloud in one of them. You can then use a site like
                //https://www.diffnow.com/ to find the difference
                //between the two projects.
                //not all differences have to be included but these are
                //the ones I found that are necessary.

                string projectString = project.WriteToString();

                //add entitlements file
                projectString = projectString.Replace("/* Begin PBXFileReference section */",
                    "/* Begin PBXFileReference section */\n\t\t244C317F1B8BE5CF00F39B20 /* ZeGame.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = ZeGame.entitlements; path = \"Unity-iPhone/ZeGame.entitlements\"; sourceTree = \"<group>\"; };");

                //add entitlements file (again)
                projectString = projectString.Replace("/* CustomTemplate */ = {\n			isa = PBXGroup;\n			children = (",
                    "/* CustomTemplate */ = {\n			isa = PBXGroup;\n			children = (\n				244C317F1B8BE5CF00F39B20 /* ZeGame.entitlements */,");

                //add some kind of entitlements command
                projectString = projectString.Replace("CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;",
                    "CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;\n\t\t\t\tCODE_SIGN_ENTITLEMENTS = \"Unity-iPhone/ZeGame.entitlements\";");

                //add development team you'll have to replace ****
                //with your own development string, which you can find
                //in your project.pbxproj file after enabling icloud
                projectString = projectString.Replace("TargetAttributes = {",
                    "TargetAttributes = {\n					1D6058900D05DD3D006BFB54 = {\n						DevelopmentTeam = ******;\n					};");

                //save the file
                File.WriteAllText(projectPath, projectString);

                break;
            case platform.windows:
                lastPlatform = platform.windows64;
                buildLast();
                break;
            case platform.windows64:
                lastPlatform = platform.windows;
                File.Delete("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_windows/64/player_win_x64_s.pdb");
                File.Delete("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_windows/64/player_win_x64.pdb");
                File.Delete("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_windows/32/player_win_x86_s.pdb");
                File.Delete("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_windows/32/player_win_x86.pdb");
                break;
            case platform.linux:
                runShell("/Volumes/Jesper Ext/unity/ZeGame/ZeGame_linux/build.sh");
                break;
        }
    }
        /// <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());
        }
예제 #42
0
        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());
        }
예제 #43
0
 public static void OnPostProcessBuild(BuildTarget platform, string projectPath)
 {
     if (platform != BuildTarget.iOS) {
       return;
     }
     string pbxFile = PBXProject.GetPBXProjectPath(projectPath);
     PBXProject pbxProject = new PBXProject();
     pbxProject.ReadFromFile(pbxFile);
     string target = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
     pbxProject.AddFrameworkToProject(target, "Security.framework", false);
     pbxProject.AddFrameworkToProject(target, "GLKit.framework", false);
     pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
     pbxProject.WriteToFile(pbxFile);
 }
    private static void OnPostprocessBuildIOS(string pathToBuiltProject)
    {
        // We use UnityEditor.iOS.Xcode API which only exists in iOS editor module
                #if UNITY_IOS
        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        UnityEditor.iOS.Xcode.PBXProject proj = new UnityEditor.iOS.Xcode.PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "ARKit.framework", false);
        string target = proj.TargetGuidByName("Unity-iPhone");
        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, "Libraries/Unity"));

        // Check UnityARKitPluginSettings
        UnityARKitPluginSettings ps = LoadSettings();
        string        plistPath     = Path.Combine(pathToBuiltProject, "Info.plist");
        PlistDocument plist         = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
        PlistElementDict rootDict = plist.root;

        // Get or create array to manage device capabilities
        const string      capsKey = "UIRequiredDeviceCapabilities";
        PlistElementArray capsArray;
        PlistElement      pel;
        if (rootDict.values.TryGetValue(capsKey, out pel))
        {
            capsArray = pel.AsArray();
        }
        else
        {
            capsArray = rootDict.CreateArray(capsKey);
        }
        // Remove any existing "arkit" plist entries
        const string arkitStr = "arkit";
        capsArray.values.RemoveAll(x => arkitStr.Equals(x.AsString()));
        if (ps.AppRequiresARKit)
        {
            // Add "arkit" plist entry
            capsArray.AddString(arkitStr);
        }
        File.WriteAllText(plistPath, plist.WriteToString());

        foreach (ARReferenceImagesSet ar in imageSets)
        {
            AddReferenceImagesSetToAssetCatalog(ar, pathToBuiltProject, proj);
        }

        //TODO: remove this when XCode actool is able to handles ARResources despite deployment target
        if (imageSets.Count > 0)
        {
            proj.SetBuildProperty(target, "IPHONEOS_DEPLOYMENT_TARGET", "11.3");
        }

        // Add or replace define for facetracking
        UpdateDefinesInFile(pathToBuiltProject + "/Classes/Preprocessor.h", new Dictionary <string, bool>()
        {
            { "ARKIT_USES_FACETRACKING", ps.m_ARKitUsesFacetracking }
        });

        string[] filesToCopy = new string[]
        {
        };

        for (int i = 0; i < filesToCopy.Length; ++i)
        {
            var srcPath      = Path.Combine("../PluginSource/source", filesToCopy[i]);
            var dstLocalPath = "Libraries/" + filesToCopy[i];
            var dstPath      = Path.Combine(pathToBuiltProject, dstLocalPath);
            File.Copy(srcPath, dstPath, true);
            proj.AddFileToBuild(target, proj.AddFile(dstLocalPath, dstLocalPath));
        }

        File.WriteAllText(projPath, proj.WriteToString());
                #endif // #if UNITY_IOS
    }
예제 #45
0
    /**
     * Private post-export method
     * --------------------------
     *
     * This is being executed in two separate fashions as seen above,
     * based on whether or not the build is occurring in the Cloud.
     *
     * - Path parameter points to root XCode project directory
     *     where xcodeproj file is located
     * - Uses XCode Manipulation API to:
     *   - Force Debug configuration before XCode build step is executed
     *   - Disable ENABLE_BITCODE to prevent large app filesizes
     **/
    private static void ProcessPostBuild(BuildTarget buildTarget, string path)
    {
        // Restricting post-export behavior to only builds where specific Scene is active
        if (buildTarget == BuildTarget.iOS && IsSceneActive ("Assets/Scenes/CounterScene.unity"))
        {
            // Initialize build settings
            var buildSettings = new BuildSettings {
                configuration = "Debug"
            };

            /**
             * Manual manipulation of .xcscheme file
             * -------------------------------------
             *
             * .xcscheme file contains all information related to build schemes as seen
             * in Project -> Schemes -> Edit Schemes dialog in XCode. In this case, we
             * are forcing Debug configuration.
             **/

            // Access xcscheme file and ingest xml
            string schemePath = path + "/Unity-iPhone.xcodeproj/xcshareddata/xcschemes/Unity-iPhone.xcscheme";
            var schemeReader = new StreamReader (schemePath);
            var xDoc = XDocument.Load(schemeReader);
            schemeReader.Close();

            Debug.Log(string.Format("Loaded scheme file: {0}", schemePath));

            // Set debug configuration for launch action
            foreach (XElement element in xDoc.Descendants("LaunchAction")) {
                element.SetAttributeValue("buildConfiguration", buildSettings.configuration);
                Debug.Log(string.Format("Set launch configuration to {0}", buildSettings.configuration));
            }

            // Write file back out
            xDoc.Save(schemePath);
            Debug.Log(string.Format("Saved scheme file: {0}", schemePath));

            /**
             * XCode Project manipulation examples
             * -----------------------------------
             *
             * .pbxproj file contains information related to frameworks, build properties
             * and other settings within an XCode project. See the Manipulation API docs:
             *
             * http://docs.unity3d.com/ScriptReference/iOS.Xcode.PBXProject.html
             **/

            // Access pbxproj file to add frameworks and build properties
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName("Unity-iPhone");

            // Add user packages to project. Most other source or resource files and packages
            // can be added the same way.
              //CopyAndReplaceDirectory ("NativeAssets/TestLib.bundle", Path.Combine (path, "Frameworks/TestLib.bundle"));
              //proj.AddFileToBuild (target, proj.AddFile ("Frameworks/TestLib.bundle",
              //                                       "Frameworks/TestLib.bundle", PBXSourceTree.Source));

              //CopyAndReplaceDirectory ("NativeAssets/TestLib.framework", Path.Combine (path, "Frameworks/TestLib.framework"));
              //proj.AddFileToBuild (target, proj.AddFile ("Frameworks/TestLib.framework",
              //                                       "Frameworks/TestLib.framework", PBXSourceTree.Source));

            // Add custom system frameworks. Duplicate frameworks are ignored.
            // needed by our native plugin in Assets/Plugins/iOS
              //proj.AddFrameworkToProject (target, "AssetsLibrary.framework", false /*not weak*/);

            // Add our framework directory to the framework include path
              //proj.SetBuildProperty (target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
              //proj.AddBuildProperty (target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // Set a custom link flag
              //proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");

            // Write changes back to file
            File.WriteAllText(projPath, proj.WriteToString());
        }
    }