Beispiel #1
29
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        #if UNITY_IPHONE
        string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject project = new PBXProject();

        project.ReadFromString(File.ReadAllText(projectPath));

        // This is the project name that Unity generates for iOS, isn't editable until after post processing
        string target = project.TargetGuidByName(PBXProject.GetUnityTargetName());

        #if UNITY_5_0
        project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/Plugins/iOS");
        #else
        CopyAndReplaceDirectory("Assets/Plugins/iOS/FiksuSDK.bundle", Path.Combine(path, "Frameworks/FiksuSDK.bundle"));
        project.AddFileToBuild(target, project.AddFile("Frameworks/FiksuSDK.bundle", "Frameworks/FiksuSDK.bundle", PBXSourceTree.Source));

        CopyAndReplaceDirectory("Assets/Plugins/iOS/FiksuSDK.framework", Path.Combine(path, "Frameworks/FiksuSDK.framework"));
        project.AddFileToBuild(target, project.AddFile("Frameworks/FiksuSDK.framework", "Frameworks/FiksuSDK.framework", PBXSourceTree.Source));

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

        project.AddFrameworkToProject(target, "AdSupport.framework", true);
        project.AddFrameworkToProject(target, "StoreKit.framework", true);
        project.AddFrameworkToProject(target, "Security.framework", true);
        project.AddFrameworkToProject(target, "SystemConfiguration.framework", false);
        project.AddFrameworkToProject(target, "MessageUI.framework", false);

        File.WriteAllText(projectPath, project.WriteToString());
        #endif
    }
        void ApplyMod(PBXProject project, string modFile)
        {
            var json                = File.ReadAllText(modFile);
            var mod                 = JsonUtility.FromJson <ProjMod>(json);
            var sourceDir           = Directory.GetParent(modFile).FullName;
            var targetGroup         = "Libraries/" + mod.group;
            var sourcesTargetGuid   = GetSourcesTargetGuid(project);
            var resourcesTargetGuid = GetResourcesTargetGuid(project);
            var dirProject          = Directory.GetParent(PBXProject.GetPBXProjectPath(m_buildPath)).FullName;

            foreach (var file in mod.files)
            {
                var filename = Path.GetFileName(file);
                var fileGuid = project.AddFile(FileUtils.FixPath(FileUtils.MakeRelativePath(dirProject, sourceDir + "/" + file)), targetGroup + "/" + filename, PBXSourceTree.Source);
                if (filename.EndsWith(".h"))
                {
                    continue;
                }

                var targetGuid = IsSourceFile(filename) ? sourcesTargetGuid : resourcesTargetGuid;
                project.AddFileToBuild(targetGuid, fileGuid);
            }
            foreach (var framework in mod.frameworks)
            {
                project.AddFrameworkToProject(sourcesTargetGuid, framework, false);
            }
        }
    private static void ProcessPostBuild(BuildTarget buildTarget, string path)
    {
        string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

#if UNITY_IOS
        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());
#endif
    }
        /// <summary>
        /// 添加tbd
        /// </summary>
        /// <param name="lib"></param>
        public void AddLibrary(string lib)
        {
            string fileGuid = mProj.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);

            mProj.AddFileToBuild(mTargetGuid, fileGuid);
            Debug.Log(string.Format("Adding library : {0}", lib));
        }
Beispiel #5
0
        protected virtual void AddFiles()
        {
            string _target = Path.GetDirectoryName(projPath);

            _target = Path.GetDirectoryName(_target);
            _target = Utility.MakeUnifiedDirectory(_target) + "/";
            string _source = Path.GetDirectoryName(Application.dataPath) + "/ios";

            _source = Utility.MakeUnifiedDirectory(_source) + "/";

            //copy文件
            string[] _all = Directory.GetFiles(_source, "*", SearchOption.AllDirectories);
            for (int i = 0; i < _all.Length; i++)
            {
                string _one  = Utility.MakeUnifiedDirectory(_all[i]);
                string _file = _one.Replace(_source, string.Empty);
                string _dirs = Path.GetDirectoryName(_target + _file);
                if (!Directory.Exists(_dirs))
                {
                    Directory.CreateDirectory(_dirs);
                }
                File.Copy(_one, _target + _file);
            }
            //引用组
            customPaths = Directory.GetDirectories(_source);
            for (int i = 0; i < customPaths.Length; i++)
            {
                string _one = Path.GetFileNameWithoutExtension(customPaths[i]);
                proj.AddFileToBuild(target, proj.AddFile(_one, _one, PBXSourceTree.Source));
            }
        }
Beispiel #6
0
        private static void UpdateProject(BuildTarget buildTarget, string projectPath)
        {
#if UNITY_IOS
            PBXProject project = new PBXProject();
            project.ReadFromString(File.ReadAllText(projectPath));

            string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());

            // Required Frameworks
            project.AddFrameworkToProject(targetId, "AdSupport.framework", false);
            project.AddFrameworkToProject(targetId, "AudioToolbox.framework", false);
            project.AddFrameworkToProject(targetId, "AVFoundation.framework", false);
            project.AddFrameworkToProject(targetId, "CoreMedia.framework", false);
            project.AddFrameworkToProject(targetId, "CoreTelephony.framework", false);
            project.AddFrameworkToProject(targetId, "JavaScriptCore.framework", false);
            project.AddFrameworkToProject(targetId, "MessageUI.framework", false);
            project.AddFrameworkToProject(targetId, "MobileCoreServices.framework", false);
            project.AddFrameworkToProject(targetId, "SystemConfiguration.framework", false);

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

            // Optional Frameworks
            project.AddFrameworkToProject(targetId, "Social.framework", true);
            project.AddFrameworkToProject(targetId, "StoreKit.framework", true);
            project.AddFrameworkToProject(targetId, "WatchConnectivity.framework", true);
            project.AddFrameworkToProject(targetId, "Webkit.framework", true);

            // For 3.0 MP classes
            project.AddBuildProperty(targetId, "OTHER_LDFLAGS", "-ObjC -fobjc-arc");

            File.WriteAllText(projectPath, project.WriteToString());
#endif
        }
Beispiel #7
0
        protected static void AddFrameworksToProject(string[] frameworks, string buildPath, PBXProject project, string target)
        {
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
            string frameworksDir       = Path.Combine(Directory.GetCurrentDirectory(), "Assets/" + fabricPluginsPath);
            string pluginFrameworksDir = "Frameworks/" + fabricPluginsPath + "/";

            foreach (string framework in frameworks)
            {
                string pluginFrameworkDir = pluginFrameworksDir + framework;
                if (!Directory.Exists(Path.Combine(buildPath, pluginFrameworkDir)))
                {
                    Utils.Log("Adding {0} to Xcode project", framework);

                    AddFrameworkToProject(project, target, Path.Combine(frameworksDir, framework), buildPath,
                                          pluginFrameworkDir);
                }
            }
#else
            foreach (string framework in FabricManager.Frameworks)
            {
                string srcPath = Path.Combine(FabricManager.SDKPath, framework);                                //Framework所在原路径(绝对路径)
                string dstPath = Path.Combine(BuildTools.GetXcodeFrameworkFullPath(buildPath), framework);      //复制Framework的目标路径(绝对路径)
                BuildTools.CopyAndReplaceDirectory(srcPath, dstPath);
                string fullPath = Path.Combine(BuildTools.FrameworkXcodeRoot, framework);                       //添加到Xcode工程的文件路径(相对路径)
                project.AddFileToBuild(target, project.AddFile(fullPath, fullPath, PBXSourceTree.Source));
            }
#endif
        }
    //添加 xcodeModel.frameworks 中指定的 framework shareSDK子平台的framework
    private static void AddXcodeModelFrameworks(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath)
    {
        foreach (MOBPathModel pathModel in xcodeModel.frameworks)
        {
            if (pathModel.filePath.Contains(".framework") && !pathModel.filePath.Contains("MOBFoundation.framework"))
            {
                string frameworkPath = pathModel.filePath.Replace(pathModel.rootPath, "");
                //			Debug.Log("frameworkPath" + frameworkPath);
                string savePath = xcodeTargetPath + frameworkPath;

                int tempIndex = frameworkPath.LastIndexOf("/");

                string saveFrameworkPath = frameworkPath.Substring(0, tempIndex);

                //将 framework copy到指定目录
                DirectoryInfo frameworkInfo     = new DirectoryInfo(pathModel.filePath);
                DirectoryInfo saveFrameworkInfo = new DirectoryInfo(savePath);
                CopyAll(frameworkInfo, saveFrameworkInfo);
                //将 framework 加入 proj中
                xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + frameworkPath, PBXSourceTree.Sdk));
                //将 build setting 设置
                xcodeProj.AddBuildProperty(xcodeTargetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)" + saveFrameworkPath);
            }
            else
            {
                Debug.LogWarning(pathModel.filePath + " no framework");
            }
        }
    }
Beispiel #9
0
 //-------------------------------------------------------------------------
 static void _addLibs(PBXProject proj, string target)
 {
     foreach (var i in mListLibs)
     {
         proj.AddFileToBuild(target, proj.AddFile(i, i, PBXSourceTree.Source));
     }
 }
Beispiel #10
0
    private static void WriteModuleToFramework(
        PBXProject proj,
        string targetGUID,
        string pbxProjectPath,
        string pluginRelativePathInUnity,
        string pluginRelativePathInXCode
        )
    {
        // Add a module map reference to the XCode project
        string moduleMapDestRelativePath = Path.Combine(pluginRelativePathInXCode, MODULE_MAP_FILENAME);

        Debug.Log("[UnityCoreHapticsPostProcessor] Adding properties to XCode framework. Module path : " + moduleMapDestRelativePath);
        string file_guid = proj.AddFile(moduleMapDestRelativePath, moduleMapDestRelativePath, PBXSourceTree.Source);

        proj.AddFileToBuild(targetGUID, file_guid);
        proj.WriteToFile(pbxProjectPath);

        // Copy the module file from Unity to XCode
        string sourcePath = Path.Combine(Application.dataPath, pluginRelativePathInUnity, MODULE_MAP_FILENAME);
        string destPath   = Path.Combine(Path.GetDirectoryName(pbxProjectPath), "..", moduleMapDestRelativePath);

        if (!Directory.Exists(Path.GetDirectoryName(destPath)))
        {
            Debug.Log("[UnityCoreHapticsPostProcessor] Creating directory " + destPath);
            Directory.CreateDirectory(Path.GetDirectoryName(destPath));
        }
        Debug.Log("[UnityCoreHapticsPostProcessor] Copy module file to project : " + sourcePath + " -> " + destPath);
        File.Copy(sourcePath, destPath);
    }
		public static void OnPostProcessBuild( BuildTarget buildTarget, string buildPath )
		{
			#if UNITY_5
			if (buildTarget == BuildTarget.iOS)
			#else
			if (buildTarget == BuildTarget.iPhone)
			#endif
			{
				var projPath = PBXProject.GetPBXProjectPath( buildPath );
				PBXProject proj = new PBXProject();
				proj.ReadFromString( File.ReadAllText( projPath ) );
				var targetGuid = proj.TargetGuidByName( "Unity-iPhone" );

				var instance = ScriptableObject.CreateInstance<ICadePluginPath>(); 
				var pluginPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath( MonoScript.FromScriptableObject( instance ) ) );
				ScriptableObject.DestroyImmediate( instance );

				var targetPath = Path.Combine( "Libraries", pluginPath.Substring( 7 ) );
				Directory.CreateDirectory( Path.Combine( buildPath, targetPath ) );

				foreach (var fileName in sourceFiles)
				{
					var sourcePath = Path.Combine( pluginPath, fileName );
					var targetFile = Path.Combine( targetPath, fileName );
					File.Copy( sourcePath, Path.Combine( buildPath, targetFile ), true );
					proj.AddFileToBuild( targetGuid, proj.AddFile( targetFile, targetFile, PBXSourceTree.Source ) );
				}

				File.WriteAllText( projPath, proj.WriteToString() );
			}
		}
Beispiel #12
0
    public static void AddGoogleServicesFile(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
                        #if UNITY_IOS
            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, "SystemConfiguration.framework", false);

            try {
                //FileUtil.DeleteFileOrDirectory(path + "/" + googleFileName);
                FileUtil.ReplaceFile("Assets/" + googleInfoPlistFilePath, path + "/" + googleFileName);
                proj.AddFileToBuild(target, proj.AddFile(googleFileName, googleFileName, PBXSourceTree.Source));
                File.WriteAllText(projPath, proj.WriteToString());
            }
            catch {
                Debug.LogError("LCGoogleSignIn Failed to copy latest google services info plist file to project directory. Verify manually that google login has no error");
            }
                        #endif
        }
    }
        static void AddAppEntitlements(string projectPath, PBXProject project, string target)
        {
            var existingEntitlementsFiles = project.GetBuildPropertyValues(target, "CODE_SIGN_ENTITLEMENTS");

            if (existingEntitlementsFiles.Count == 0)
            {
                project.AddFileToBuild(target,
                                       project.AddFile("app.entitlements", "app.entitlements", PBXSourceTree.Source));
                project.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "app.entitlements");
                existingEntitlementsFiles.Add("app.entitlements");
            }
            foreach (var entitlementsSetting in existingEntitlementsFiles)
            {
                var entitlementsFilePath = Path.Combine(projectPath, entitlementsSetting);
                var entitlements         = new PlistDocument();
                if (File.Exists(entitlementsFilePath))
                {
                    entitlements.ReadFromFile(entitlementsFilePath);
                }

                if (GetSocialSettings.IsRichPushNotificationsEnabled && GetSocialSettings.IsIosPushEnabled)
                {
                    ConfigureAppGroups(entitlements);
                }
                ConfigureAssociatedDomains(entitlements);
                ConfigurePushNotifications(entitlements);

                entitlements.WriteToFile(entitlementsFilePath);
            }
        }
Beispiel #14
0
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target == BuildTarget.iOS)
        {
            // Read.
            string     projectPath = PBXProject.GetPBXProjectPath(path);
            PBXProject project     = new PBXProject();
            project.ReadFromString(File.ReadAllText(projectPath));
            string targetName = PBXProject.GetUnityTargetName();
            string targetGUID = project.TargetGuidByName(targetName);

            project.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO");
            project.SetBuildProperty(targetGUID, "SWIFT_VERSION", "4");
            project.SetBuildProperty(targetGUID, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/Plugins/iOS/ZarinpalUnityPlugin-Bridging-Header.h");
            project.SetBuildProperty(targetGUID, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "ZarinpalUnityPlugin-Swift.h");
            project.AddBuildProperty(targetGUID, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            string storyboardFilePath = Application.dataPath +
                                        "/Zarinpal/Templates/IOS/PaymentBoard.storyboard";
            var id = project.AddFile(storyboardFilePath,
                                     "/Libraries/Plugins/IOS/PaymentBoard.storyboard");
            project.AddFileToBuild(targetGUID, id);

            // Write.
            File.WriteAllText(projectPath, project.WriteToString());
        }
    }
    private static void AddFrameworks(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");

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

        // add frameworks
        proj.AddFrameworkToProject(target, "AdSupport.framework", true);
        proj.AddFrameworkToProject(target, "AddressBook.framework", true);
        proj.AddFrameworkToProject(target, "libsqlite3.0.dylib", false);


        string[] plistFiles = Directory.GetFiles(Application.dataPath, "GoogleService-Info.plist", SearchOption.AllDirectories);
        foreach (string customPlistPath in plistFiles)
        {
            proj.AddFileToBuild(target, proj.AddFile(customPlistPath, "GoogleService-Info.plist", PBXSourceTree.Source));
        }

        File.WriteAllText(projPath, proj.WriteToString());
    }
Beispiel #16
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        var        projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromFile(projPath);
#if UNITY_2019_3_OR_NEWER
        string guid = proj.GetUnityFrameworkTargetGuid();
#else
        string guid = proj.TargetGuidByName("Unity-iPhone");
#endif

        proj.AddBuildProperty(guid, "OTHER_LDFLAGS", "-ObjC");
        proj.AddFrameworkToProject(guid, "VideoToolbox.framework", false);
        proj.AddFrameworkToProject(guid, "GLKit.framework", false);
        proj.AddFrameworkToProject(guid, "Network.framework", false);
        // libwebrtc.a には新しい libvpx が、libiPhone-lib.a には古い libvpx が入っていて、
        // デフォルトのリンク順序だと古い libvpx が使われてしまう。
        // それを回避するために libiPhone-lib.a を削除して新しく追加し直すことで
        // リンク順序を変えてやる。
        string fileGuid = proj.FindFileGuidByProjectPath("Libraries/libiPhone-lib.a");
        proj.RemoveFileFromBuild(guid, fileGuid);
        proj.AddFileToBuild(guid, fileGuid);

        proj.WriteToFile(projPath);
    }
    //添加 bundle
    private static void AddBundle(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        SearchOption searchOption;

        if (secondFilePath.Contains("/ShareSDK/"))          //shareSDK
        {
            searchOption = SearchOption.TopDirectoryOnly;
        }
        else
        {
            searchOption = SearchOption.AllDirectories;
        }
        string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.bundle", searchOption);
        foreach (string lastFilePath in secondDirectories)
        {
            if (secondFilePath.EndsWith("SDK/ShareSDK") && lastFilePath.Contains("Support/PlatformSDK"))
            {
                continue;
            }
//			Debug.Log("lastFilePath" + lastFilePath);
            string bundlePath = lastFilePath.Replace(pathModel.rootPath, "");
//			Debug.Log("bundlePath" + bundlePath);
            string savePath = xcodeTargetPath + bundlePath;
            //将 framework copy到指定目录
            DirectoryInfo bundleInfo     = new DirectoryInfo(lastFilePath);
            DirectoryInfo saveBundleInfo = new DirectoryInfo(savePath);
            CopyAll(bundleInfo, saveBundleInfo);
            //将 framework 加入 proj中
            xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + bundlePath, PBXSourceTree.Sdk));
        }
    }
Beispiel #18
0
    //添加 .a文件
    private static void AddStaticLibrary(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        string[] secondDirectories = Directory.GetFiles(secondFilePath, "*.a", SearchOption.AllDirectories);
        foreach (string lastFilePath in secondDirectories)
        {
//			Debug.Log("lastFilePath" + lastFilePath);
            string staticLibraryPath = lastFilePath.Replace(pathModel.rootPath, "");
            int    index             = staticLibraryPath.LastIndexOf("/");
            //项目目录
            string saveStaticLibraryPath = staticLibraryPath.Substring(0, index);
            //存放的本地目录
            string saveDirectory = xcodeTargetPath + saveStaticLibraryPath;
            if (!Directory.Exists(saveDirectory))
            {
                Directory.CreateDirectory(saveDirectory);
            }
            //将.a copy到指定目录
            FileInfo fileInfo = new FileInfo(lastFilePath);
            string   savePath = xcodeTargetPath + staticLibraryPath;
            fileInfo.CopyTo(savePath, true);
            //将.a 加入 proj中
            xcodeProj.AddFileToBuild(xcodeTargetGuid, xcodeProj.AddFile(savePath, "MOB" + staticLibraryPath, PBXSourceTree.Sdk));
            //将 build setting 设置
            xcodeProj.AddBuildProperty(xcodeTargetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)" + saveStaticLibraryPath);
        }
    }
        private static void AddFileToEmbedFrameworks(PBXProject project, string target, string unityPath, string xcodePath)
        {
            string frameworkPath = project.AddFile(unityPath, xcodePath, PBXSourceTree.Source);

            project.AddFileToBuild(target, frameworkPath);
            project.AddFileToEmbedFrameworks(target, frameworkPath);
        }
Beispiel #20
0
    /*
     * Our iOS xCode project needs an extra bundle called "Settings.bundle" so that
     * a few preferences appear in the iOS system preferences window.
     *
     * This function ensures that the generated XCode project has that bundle.
     *
     * For details of the structure of the Settings.bundle, see
     * https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html
     */
    public static void UpdateXCodeProject(string pathToBuiltProject)
    {
        var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);

        // Read in the xcode project
        var proj = new PBXProject();

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

        // See if it already has the Settings.bundle file
        var target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

        if (!proj.ContainsFileByProjectPath(SETTINGS_BUNDLE))
        {
            // If not, add a reference to the file, which is in the repo
            var fileGuid = proj.AddFile(PathToSettingsBundle, SETTINGS_BUNDLE, PBXSourceTree.Absolute);
            proj.AddFileToBuild(target, fileGuid);
            File.WriteAllText(projPath, proj.WriteToString());
            Debug.Log("Wrote " + SETTINGS_BUNDLE + " projPath");
        }
        else
        {
            Debug.Log(SETTINGS_BUNDLE + " already found in " + projPath);
        }
    }
Beispiel #21
0
        private static void PrepareProject(string buildPath)
        {
            var projPath = Path.Combine(buildPath, "Unity-iPhone.xcodeproj/project.pbxproj");
            var project  = new PBXProject();

            project.ReadFromString(File.ReadAllText(projPath));
            var target = project.TargetGuidByName("Unity-iPhone");

            foreach (var lib in PlatformLibs)
            {
                string libGUID = project.AddFile("usr/lib/" + lib, "Libraries/" + lib, PBXSourceTree.Sdk);
                project.AddFileToBuild(target, libGUID);
            }

            var fileGuid = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/MoPubSDKFramework.framework");

#if UNITY_2017_1_OR_NEWER
            project.AddFileToEmbedFrameworks(target, fileGuid);
#endif
            project.SetBuildProperty(
                target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

            project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
            project.AddBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
            project.AddBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
            project.AddBuildProperty(target, "ENABLE_BITCODE", "NO");

            File.WriteAllText(projPath, project.WriteToString());
        }
        private static void updateProject(BuildTarget buildTarget, string projectPath)
        {
            Debug.Log("IronSource - Update project for IronSource");

            PBXProject project = new PBXProject();

            project.ReadFromString(File.ReadAllText(projectPath));

            string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());

            // Required System Frameworks
            project.AddFrameworkToProject(targetId, "Foundation.framework", false);
            project.AddFrameworkToProject(targetId, "AVFoundation.framework", false);
            project.AddFrameworkToProject(targetId, "Security.framework", false);
            project.AddFrameworkToProject(targetId, "WebKit.framework", false);
            project.AddFrameworkToProject(targetId, "StoreKit.framework", false);
            project.AddFrameworkToProject(targetId, "AdSupport.framework", false);
            project.AddFrameworkToProject(targetId, "CoreMedia.framework", false);
            project.AddFrameworkToProject(targetId, "CoreVideo.framework", false);
            project.AddFrameworkToProject(targetId, "CoreLocation.framework", false);
            project.AddFrameworkToProject(targetId, "CoreTelephony.framework", false);
            project.AddFrameworkToProject(targetId, "CoreGraphics.framework", false);
            project.AddFrameworkToProject(targetId, "QuartzCore.framework", false);
            project.AddFrameworkToProject(targetId, "SystemConfiguration.framework", false);
            project.AddFrameworkToProject(targetId, "CFNetwork.framework", false);
            project.AddFrameworkToProject(targetId, "MobileCoreServices.framework", false);
            project.AddFrameworkToProject(targetId, "AudioToolbox.framework", false);

            project.AddFileToBuild(targetId, project.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));

            // Custom Link Flag
            project.AddBuildProperty(targetId, "OTHER_LDFLAGS", "-ObjC");

            File.WriteAllText(projectPath, project.WriteToString());
        }
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
#if UNITY_IPHONE
            // 修改xcode工程
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName("Unity-iPhone");

            proj.AddFrameworkToProject(target, "libz.tbd", false);
            proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);

            string fileName = Application.dataPath.Replace("Assets", "iOS/XunFeiSR");
            XcodeModifyGeneral.CopyAndReplaceDirectory(fileName, Path.Combine(path, "XunFeiSR"));
            List <string> filePaths = new List <string>();
            XcodeModifyGeneral.AddFilesToBuild(ref filePaths, path, "XunFeiSR");
            foreach (var filepath in filePaths)
            {
                proj.AddFileToBuild(target, proj.AddFile(filepath, filepath));
            }

            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/XunFeiSR");
            proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");

            proj.WriteToFile(projPath);
#endif
        }
    }
Beispiel #24
0
    static void AddResToProject(PBXProject pbxProj, string targetGuid, string pathToBuiltProject, string srcPath, string dstPath)
    {
        string frameworksPath = Application.dataPath + "/" + srcPath;

        string[] directories = Directory.GetDirectories(frameworksPath, "*", SearchOption.TopDirectoryOnly);
        for (int i = 0; i < directories.Length; i++)
        {
            string path = directories[i];

            string name        = path.Replace(frameworksPath + "/", "");
            string destDirName = pathToBuiltProject + "/" + dstPath + "/" + name;

            if (Directory.Exists(destDirName))
            {
                Directory.Delete(destDirName, true);
            }

            Debug.Log("copy: " + path + " => " + destDirName);
            CopyDirectory(path, destDirName, new string[] { ".meta", ".framework", ".mm", ".c", ".m", ".h", ".xib", ".a", ".plist", ".org", ".json", ".png", "" }, false);

            foreach (string file in Directory.GetFiles(destDirName, "*.*", SearchOption.AllDirectories))
            {
                pbxProj.AddFileToBuild(targetGuid
                                       , pbxProj.AddFile(file, file.Replace(pathToBuiltProject + "/", ""), PBXSourceTree.Source)
                                       );
            }
        }
    }
Beispiel #25
0
    static void EditProj(string pathToBuiltProject, string path)
    {
        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject pbxProj = new PBXProject();

        pbxProj.ReadFromFile(projPath);
#if UNITY_2019_3_OR_NEWER
        string targetGuid = pbxProj.GetUnityFrameworkTargetGuid();
#else
        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");
#endif
        pbxProj.AddFrameworkToProject(targetGuid, "libz.1.dylib", false);
        CopyAndAddFile(pbxProj, targetGuid, path, "Sdkds/Plugins/iOS/kfmt.dat", "Libraries/Plugins/iOS/SDKDSlaySDK");
        CopyAndAddFile(pbxProj, targetGuid, path, "Sdkds/Plugins/iOS/sdkdsSupport.dat", "Libraries/Plugins/iOS/SDKDSlaySDK");
        string resourcesDirectoryPath = pathToBuiltProject + "/Frameworks/Sdkds/Plugins/iOS/Resources";
        if (Directory.Exists(resourcesDirectoryPath) == false)
        {
            Debug.Log("copy SDKDSPromotion.bundle");
            CopyAndAddBundleToBuild(pbxProj, targetGuid, path, "Sdkds/Plugins/iOS/Resources", "Frameworks/Sdkds/Plugins/iOS/Resources", "SDKDSPromotion");
        }
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("/usr/lib/libz.1.dylib", "Frameworks/libz.1.dylib", PBXSourceTree.Absolute));
        pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");

        pbxProj.WriteToFile(projPath);
    }
Beispiel #26
0
    static void CopyAndAddBundleToBuild(PBXProject pbxProj, string targetGuid, string pathToBuiltProject, string relativeSrcPath, string relativeDstPath, string bundleName)
    {
        string fullSrcPath = Application.dataPath + "/" + relativeSrcPath;
        string fullDesPath = pathToBuiltProject + "/" + relativeDstPath;

        CopyDirectory(fullSrcPath, fullDesPath, new string[] {
            ".framework",
            ".mm",
            ".c",
            ".m",
            ".h",
            ".xib",
            ".a",
            ".plist",
            ".org",
            ".json",
            ".png",
            ".dat",
            ".strings",
            ".lproj",
            ".pic",
            ".meta",
            ""
        }, false);
        if (bundleName.Contains(".bundle") == false)
        {
            bundleName = bundleName + ".bundle";
        }
        string bundleFullPath = fullDesPath + "/" + bundleName;
        string projectPath    = relativeDstPath + "/" + bundleName;

        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(bundleFullPath, projectPath, PBXSourceTree.Absolute));
    }
Beispiel #27
0
    /// <summary>
    /// Enumerates Unity output files and add necessary files into Xcode project file.
    /// It only add a reference entry into project.pbx file, without actually copy it.
    /// Xcode pre-build script will copy files into correct location.
    /// </summary>
    private static void UpdateUnityProjectFiles(string pathToBuiltProject)
    {
        var pbx     = new PBXProject();
        var pbxPath = Path.Combine(XcodeProjectRoot, PbxFilePath);

        pbx.ReadFromFile(pbxPath);

        // Add UnityExport/Classes
        ProcessUnityDirectory(
            pbx,
            Path.Combine(pathToBuiltProject, "Classes"),
            Path.Combine(XcodeProjectRoot, ClassesProjectPath),
            ClassesProjectPath);

        // Add UnityExport/Libraries
        ProcessUnityDirectory(
            pbx,
            Path.Combine(pathToBuiltProject, "Libraries"),
            Path.Combine(XcodeProjectRoot, LibrariesProjectPath),
            LibrariesProjectPath);

        // Add UnityExport/Data
        var targetGuid = pbx.TargetGuidByName(XcodeProjectName);
        var fileGuid   = pbx.AddFolderReference(Path.Combine(pathToBuiltProject, "Data"), DataProjectPath);

        pbx.AddFileToBuild(targetGuid, fileGuid);

        pbx.WriteToFile(pbxPath);
    }
    private static void CopyFileToBuild(string fileName, string unityPath, string physicalPath)
    {
        CopyRawFileToXCode(fileName, unityPath, physicalPath);
        string fileGUID = pbxProject.AddFile(physicalPath + "/Libraries/" + unityPath + fileName, "Libraries/" + unityPath + fileName, PBXSourceTree.Source);

        pbxProject.AddFileToBuild(pbxGUID, fileGUID);
    }
Beispiel #29
0
        public void WriteAndAddToPBXProject(PBXProject project, string pathToBuiltProject)
        {
            var unityTargetName            = "Unity-iPhone";
            var relativePathToAssetCatalog = Path.Combine(unityTargetName, name + ".xcassets");
            var fullPathToAssetCatalog     = Path.Combine(pathToBuiltProject, relativePathToAssetCatalog);

            // Create the asset catalog, destroying an existing one.
            if (Directory.Exists(fullPathToAssetCatalog))
            {
                Directory.Delete(fullPathToAssetCatalog, true);
            }
            Directory.CreateDirectory(fullPathToAssetCatalog);

            // Add it to Xcode's build
            var folderGuid = project.AddFile(relativePathToAssetCatalog, relativePathToAssetCatalog);

#if UNITY_2019_3_OR_NEWER
            var targetGuid = project.GetUnityMainTargetGuid();
#else
            var targetGuid = project.TargetGuidByName(unityTargetName);
#endif
            project.AddFileToBuild(targetGuid, folderGuid);

            foreach (var resourceGroup in m_ResourceGroups)
            {
                resourceGroup.Write(fullPathToAssetCatalog);
            }
        }
Beispiel #30
0
    /// <summary>
    /// Update pbx project file by adding src files and removing extra files that
    /// exists in dest but not in src any more.
    ///
    /// This method only updates the pbx project file. It does not copy or delete
    /// files in Swift Xcode project. The Swift Xcode project will do copy and delete
    /// during build, and it should copy files if contents are different, regardless
    /// of the file time.
    /// </summary>
    /// <param name="pbx">The pbx project.</param>
    /// <param name="src">The directory where Unity project is built.</param>
    /// <param name="dest">The directory of the Swift Xcode project where the
    /// Unity project is embedded into.</param>
    /// <param name="projectPathPrefix">The prefix of project path in Swift Xcode
    /// project for Unity code files. E.g. "DempApp/Unity/Classes" for all files
    /// under Classes folder from Unity iOS build output.</param>
    private static void ProcessUnityDirectory(PBXProject pbx, string src, string dest, string projectPathPrefix)
    {
        var targetGuid = pbx.TargetGuidByName(XcodeProjectName);

        string[] newFiles, extraFiles;
        CompareDirectories(src, dest, out newFiles, out extraFiles);

        foreach (var f in newFiles)
        {
            var projPath = Path.Combine(projectPathPrefix, f);
            if (!pbx.ContainsFileByProjectPath(projPath))
            {
                var guid = pbx.AddFile(projPath, projPath);
                pbx.AddFileToBuild(targetGuid, guid);

                Debug.LogFormat("Added file to pbx: '{0}'", projPath);
            }
        }

        foreach (var f in extraFiles)
        {
            var projPath = Path.Combine(projectPathPrefix, f);
            if (pbx.ContainsFileByProjectPath(projPath))
            {
                var guid = pbx.FindFileGuidByProjectPath(projPath);
                pbx.RemoveFile(guid);

                Debug.LogFormat("Removed file from pbx: '{0}'", projPath);
            }
        }
    }
Beispiel #31
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
        {
#if UNITY_5
            if (buildTarget == BuildTarget.iOS)
#else
            if (buildTarget == BuildTarget.iOS)
#endif
            {
                var        projPath = PBXProject.GetPBXProjectPath(buildPath);
                PBXProject proj     = new PBXProject();
                proj.ReadFromString(File.ReadAllText(projPath));
                var targetGuid = proj.TargetGuidByName("Unity-iPhone");

                var instance   = ScriptableObject.CreateInstance <ICadePluginPath>();
                var pluginPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(instance)));
                ScriptableObject.DestroyImmediate(instance);

                var targetPath = Path.Combine("Libraries", pluginPath.Substring(7));
                Directory.CreateDirectory(Path.Combine(buildPath, targetPath));

                foreach (var fileName in sourceFiles)
                {
                    var sourcePath = Path.Combine(pluginPath, fileName);
                    var targetFile = Path.Combine(targetPath, fileName);
                    File.Copy(sourcePath, Path.Combine(buildPath, targetFile), true);
                    proj.AddFileToBuild(targetGuid, proj.AddFile(targetFile, targetFile, PBXSourceTree.Source));
                }

                File.WriteAllText(projPath, proj.WriteToString());
            }
        }
Beispiel #32
0
        private static void EditProject(string pathToBuild)
        {
            // Edit Unity-iPhone proj
            var pbx     = new PBXProject();
            var pbxPath = Path.Combine(pathToBuild, "Unity-iPhone.xcodeproj/project.pbxproj");

            if (!File.Exists(pbxPath))
            {
                Debug.LogWarning($"PBX not found, skipping EditProject. Path: {pbxPath}");
                return;
            }

            pbx.ReadFromFile(pbxPath);

            var guidUnityFrameworkTarget = pbx.GetUnityFrameworkTargetGuid();
            var guidFile = pbx.AddFolderReference(Path.Combine(pathToBuild, "Data"), "Data");

            pbx.AddFileToBuild(guidUnityFrameworkTarget, guidFile);

            pbx.SetBuildProperty(guidUnityFrameworkTarget, "ENABLE_BITCODE", "NO");
            pbx.UpdateBuildProperty(guidUnityFrameworkTarget, "OTHER_LDFLAGS", new[]
            {
                "-Wl,-U,_FlutterUnityPluginOnMessage"
            }, null);

            pbx.WriteToFile(pbxPath);

            Debug.Log("Editing build settings completed");
        }