Beispiel #1
0
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
#if UNITY_IOS
        Debug.Log("Post Processing IOS Build...");
        //EmbedFrameworks
        var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
        var proj     = new PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        var targetGuid = proj.TargetGuidByName("Unity-iPhone");
        // EmbedFrameworks cannot be added in Unity 5.6.5

#if UNITY_2017_2_OR_NEWER
        const string defaultLocationInProj = "Plugins/iOS";
        const string coreFrameworkName     = "Placenote.framework";
        var          framework             = Path.Combine(defaultLocationInProj, coreFrameworkName);
        var          fileGuid = proj.AddFile(framework, "Frameworks/Placenote/" + framework, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
        proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
#endif

        proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
        proj.WriteToFile(projPath);
        //EmbedFrameworks end

        // remove any .meta files from the project build directory which may reside their due to the inclusion of the framework inside the Unity project itself.
        DeleteMetaFilesInFramework(Path.Combine(pathToBuiltProject, "Frameworks/Placenote/", framework));
#endif
    }
        public static void ModifyProject(BuildTarget buildTarget, string path)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            string     projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
            PBXProject project     = new PBXProject();

            project.ReadFromFile(projectPath);

#if UNITY_2019_3_OR_NEWER
            string targetGuid = project.GetUnityMainTargetGuid();
#else
            string targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
            string fileGuid = project.FindFileGuidByProjectPath("Frameworks/Plugins/RenderHeads/AVProMovieCapture/Runtime/Plugins/iOS/AVProMovieCapture.framework");
            if (fileGuid != null)
            {
                PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, fileGuid);
            }
            else
            {
                Debug.LogWarning("Failed to find AVProMovieCapture.framework in the generated project. You will need to manually set AVProMovieCapture.framework to 'Embed & Sign' in the Xcode project's framework list.");
            }
            project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            project.WriteToFile(projectPath);
        }
Beispiel #3
0
 public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
 {
     #if UNITY_IOS
     Debug.Log("Post Processing IOS Build...");
     //EmbedFrameworks
     var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
     var proj     = new PBXProject();
     proj.ReadFromString(File.ReadAllText(projPath));
     // var targetGuid = proj.TargetGuidByName ("Unity-iPhone");
     var projectGuid         = proj.ProjectGuid();                 // Added by Dalton Bohning
     var mainTargetGuid      = proj.GetUnityMainTargetGuid();      // Added by Dalton Bohning
     var frameworkTargetGuid = proj.GetUnityFrameworkTargetGuid(); // Added by Dalton Bohning
     // EmbedFrameworks cannot be added in Unity 5.6.5
     #if UNITY_2017_2_OR_NEWER
     const string defaultLocationInProj = "Plugins/iOS";
     const string coreFrameworkName     = "Placenote.framework";
     var          framework             = Path.Combine(defaultLocationInProj, coreFrameworkName);
     var          fileGuid = proj.AddFile(framework, "Frameworks/Placenote/" + framework, PBXSourceTree.Sdk);
     PBXProjectExtensions.AddFileToEmbedFrameworks(proj, frameworkTargetGuid, fileGuid);
     proj.SetBuildProperty(frameworkTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
     #endif
     proj.SetBuildProperty(projectGuid, "ENABLE_BITCODE", "NO");
     proj.SetBuildProperty(frameworkTargetGuid, "ENABLE_BITCODE", "NO");
     proj.SetBuildProperty(mainTargetGuid, "ENABLE_BITCODE", "NO");
     proj.WriteToFile(projPath);
     //EmbedFrameworks end
     #endif
 }
    public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            // We need to construct our own PBX project path that corrently refers to the Bridging header
            // var projPath = PBXProject.GetPBXProjectPath(buildPath);
            var projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
            var proj     = new PBXProject();
            proj.ReadFromFile(projPath);


#if UNITY_2019_3_OR_NEWER
            var targetGuid = proj.GetUnityMainTargetGuid();
#else
            var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

            //// Configure build settings
            //proj.AddBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/GarlicWebview/Plugins/iOS/GarlicWebviewUnityBridge/Classes/GarlicWebviewUnityBridge-Bridging-Header.h");
            //proj.AddBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "GarlicWebviewUnityBridge/GarlicWebviewUnityBridge-Swift.h");
            proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0");

            const string defaultLocationInProj = "GarlicWebview/Plugins/iOS/";
            const string coreFrameworkName     = "GarlicWebview.framework";
            string       framework             = Path.Combine(defaultLocationInProj, coreFrameworkName);
            string       fileGuid = proj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);
            proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
            //proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            proj.WriteToFile(projPath);
        }
    }
    public static void LinkLibraries(string path)
    {
        string     projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromFile(projPath);
        string target = GetTargetGuid(proj);


        // embedded frameworks
#if UNITY_2019_1_OR_NEWER
        target = proj.GetUnityMainTargetGuid();
#endif
        const string defaultLocationInProj        = "AgoraEngine/Plugins/iOS";
        const string AgoraRtcKitFrameworkName     = "AgoraRtcKit.framework";
        const string AgorafdkaacFrameworkName     = "Agorafdkaac.framework";
        const string AgoraSoundTouchFrameworkName = "AgoraSoundTouch.framework";

        string AgoraRtcKitFrameworkPath     = Path.Combine(defaultLocationInProj, AgoraRtcKitFrameworkName);
        string AgorafdkaacFrameworkPath     = Path.Combine(defaultLocationInProj, AgorafdkaacFrameworkName);
        string AgoraSoundTouchFrameworkPath = Path.Combine(defaultLocationInProj, AgoraSoundTouchFrameworkName);

        string fileGuid = proj.AddFile(AgoraRtcKitFrameworkPath, "Frameworks/" + AgoraRtcKitFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        fileGuid = proj.AddFile(AgorafdkaacFrameworkPath, "Frameworks/" + AgorafdkaacFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        fileGuid = proj.AddFile(AgoraSoundTouchFrameworkPath, "Frameworks/" + AgoraSoundTouchFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

        // done, write to the project file
        File.WriteAllText(projPath, proj.WriteToString());
    }
        // 添加动态库 注意路径
        public static void AddFramework(string coreFrameworkName, UnityEditor.iOS.Xcode.PBXProject proj, string target)
        {
            const string defaultLocationInProj = "Library/";
            string       framework             = Path.Combine(defaultLocationInProj, coreFrameworkName);
            string       fileGuid = proj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);

            PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
            proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
        }
Beispiel #7
0
        public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget == BuildTarget.iOS)
            {
                // var projPath = PBXProject.GetPBXProjectPath(buildPath);
                var projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
                var proj     = new PBXProject();
                proj.ReadFromFile(projPath);

                string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

                //// Configure build settings
                proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
                proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/LoomSDK/ios/LoomSDKSwift-Bridging-Header.h");
                proj.SetBuildProperty(targetGuid, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "LoomSDKSwift.h");
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Libraries/LoomSDK/Frameworks");
                proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "3.0");

                //frameworks
                DirectoryInfo projectParent     = Directory.GetParent(Application.dataPath);
                char          divider           = Path.DirectorySeparatorChar;
                DirectoryInfo destinationFolder =
                    new DirectoryInfo(buildPath + divider + "Frameworks/LoomSDK/Frameworks");

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

                    PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
                }
                proj.WriteToFile(projPath);

                //info.plist
                var plistPath = buildPath + "/Info.plist";
                var plist     = new PlistDocument();
                plist.ReadFromFile(plistPath);
                // Update value
                PlistElementDict rootDict = plist.root;
                //rootDict.SetString("CFBundleIdentifier","$(PRODUCT_BUNDLE_IDENTIFIER)");
                PlistElementArray urls   = rootDict.CreateArray("CFBundleURLTypes");
                PlistElementDict  dic    = urls.AddDict();
                PlistElementArray scheme = dic.CreateArray("CFBundleURLSchemes");
                scheme.AddString(PlayerSettings.applicationIdentifier);
                dic.SetString("CFBundleURLName", "auth0");
                // Write plist
                File.WriteAllText(plistPath, plist.WriteToString());
            }
        }
        static void AddEmbededFrameworks(PBXProject proj, string targetGuid)
        {
            foreach (var framework in ISD_Settings.Instance.EmbededFrameworks)
            {
                string fileGuid   = proj.AddFile(framework.AbsoluteFilePath, "Frameworks/" + framework.FileName, PBXSourceTree.Source);
                string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10");
                proj.AddFileToBuildSection(targetGuid, embedPhase, fileGuid);
#if UNITY_2017_4_OR_NEWER
                PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
#endif
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
                //proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/PATH_TO_FRAMEWORK/");
            }
        }
Beispiel #9
0
    //添加动态库
    private static void AddEmbedFarmeworks(PBXProject proj, string target, string fileGuid, string projPath)
    {
        ArrayList embeds = _table.SGet <ArrayList>("embeds");

        if (embeds != null)
        {
            foreach (string embed in embeds)
            {
                if (projPath.Contains(embed))
                {
                    PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
                }
            }
        }
    }
        public static void EmbedPilgrimInAppTarget(BuildTarget buildTarget, string pathToBuiltProject)
        {
            var project = new PBXProject();

            project.ReadFromFile(PBXProject.GetPBXProjectPath(pathToBuiltProject));

            string targetGuid = project.GetUnityMainTargetGuid();

            project.SetBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Frameworks");

            string fileGuid = project.FindFileGuidByProjectPath("Frameworks/Pilgrim.framework");

            PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, fileGuid);

            project.WriteToFile(PBXProject.GetPBXProjectPath(pathToBuiltProject));
        }
    static void AddDynamicFrameworksForUnity5(string path)
    {
        UnityEditor.iOS.Xcode.Custom.PBXProject pbxProj = new UnityEditor.iOS.Xcode.Custom.PBXProject();
        pbxProj.ReadFromFile(path);

        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");

        const string defaultLocationInProj = "Frameworks/AdDeals/Plugins/iOS";
        const string exampleFrameworkName  = "AdDeals.framework";

        string framework = Utils.PathCombine(defaultLocationInProj, exampleFrameworkName);
        string fileGuid  = pbxProj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);

        PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProj, targetGuid, fileGuid);
        pbxProj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
        pbxProj.WriteToFile(path);
    }
Beispiel #12
0
    public static void OnPostprocessBuild(BuildTarget target, string path)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        string     projectPath = PBXProject.GetPBXProjectPath(path);
        PBXProject proj        = new PBXProject();

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

        // Disable bitcode
        UnityEngine.Debug.Log("Bitcode will be disabled. IndoorAtlas.framework uses processor optimized assembly functions, so it is not possible to enable Bitcode.");
#if UNITY_2019_3_OR_NEWER
        string mainGUID = proj.GetUnityMainTargetGuid();
        proj.AddBuildProperty(proj.GetUnityFrameworkTargetGuid(), "ENABLE_BITCODE", "false");
        proj.AddFrameworkToProject(proj.GetUnityFrameworkTargetGuid(), "CoreLocation.framework", false);
#else
        string mainGUID = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
        proj.AddBuildProperty(proj.TargetGuidByName("UnityFramework"), "ENABLE_BITCODE", "false");
        proj.AddFrameworkToProject(proj.TargetGuidByName("UnityFramework"), "CoreLocation.framework", false);
#endif
        proj.AddBuildProperty(mainGUID, "ENABLE_BITCODE", "false");

        // Add IndoorAtlas.framework
        // proj.AddFrameworkToProject(mainGUID, "Plugins/IndoorAtlas/iOS/IndoorAtlas.framework", false);
        string frameworkGUID = proj.FindFileGuidByProjectPath("Frameworks/Plugins/IndoorAtlas/iOS/IndoorAtlas.framework");
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, mainGUID, frameworkGUID);
        proj.WriteToFile(projectPath);

        // Add NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
        string        plistPath = path + "/Info.plist";
        string        locationUsageDescription = "IndoorAtlas demo project needs access to device location";
        PlistDocument plist = new PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
        plist.root.SetString("NSLocationAlwaysUsageDescription", locationUsageDescription);
        plist.root.SetString("NSLocationWhenInUseUsageDescription", locationUsageDescription);
        plist.root.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", locationUsageDescription);
        plist.root.SetString("NSBluetoothAlwaysUsageDescription", "Needed for accurate positioning");
        plist.root.SetString("NSBluetoothPeripheralUsageDescription", "Needed for accurate positioning");
        plist.root.SetString("NSMotionUsageDescription", "Needed for accurate positioning");
        File.WriteAllText(plistPath, plist.WriteToString());
    }
        private static void Setup(PBXProject project, string fileGuidToRemove, string pathToRemove, string fileGuid)
        {
            string targetGuid = project.GetUnityMainTargetGuid();

            // Remove simulator/device framework
            if (!string.IsNullOrEmpty(fileGuidToRemove))
            {
                project.RemoveFrameworkFromProject(fileGuidToRemove, FRAMEWORK_NAME);
                project.RemoveFile(fileGuidToRemove);
            }

            // Delete simulator/device framework
            if (Directory.Exists(pathToRemove))
            {
                Directory.Delete(pathToRemove, true);
            }

            // Add device/simulator framework
            PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, fileGuid);
        }
 private void AddDynamicFrameworkToEmbed(string pathToBuiltProject, PBXProject proj, string targetId, DirectoryInfo[] dirs)
 {
     if (dirs != null)
     {
         foreach (DirectoryInfo dir in dirs)
         {
             if (dir.Name.Contains(".framework"))
             {
                 var output = string.Format("file {0}/Frameworks/{1}/{2}", pathToBuiltProject, dir.Name, dir.Name.Split('.')[0]).Bash();
                 if (output.Contains("dynamically"))
                 {
                     PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetId, proj.FindFileGuidByProjectPath("Frameworks/" + dir.Name));
                 }
             }
             else
             {
                 AddDynamicFrameworkToEmbed(pathToBuiltProject, proj, targetId, new DirectoryInfo(dir.FullName).GetDirectories());
             }
         }
     }
 }
        public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                UnityEngine.Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
                return;
            }
            // Open Project
            string     projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
            PBXProject proj     = new PBXProject();

            proj.ReadFromFile(projPath);
            string targetName = "Unity-iPhone";
            string targetGuid = proj.TargetGuidByName(targetName);
            // Embed SixDegreesSDK.framework
            const string defaultLocationInProj = "Plugins/iOS";
            const string coreFrameworkName     = "SixDegreesSDK.framework";
            string       framework             = Path.Combine(defaultLocationInProj, coreFrameworkName);
            string       fileGuid = proj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);

            PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
            proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            // Disable Bitcode
            proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
            // Prevent Encryption Compliance Info in AppStoreConnect
            string        plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
            PlistDocument plist     = new PlistDocument();

            plist.ReadFromFile(plistPath);
            PlistElementDict rootDict = plist.root;

            rootDict.SetString("ITSAppUsesNonExemptEncryption", "false");
            File.WriteAllText(plistPath, plist.WriteToString());
            // Include SixDegreesSDK.plist
            FileUtil.ReplaceFile("Assets/Plugins/iOS/SixDegreesSDK.plist", pathToBuiltProject + "/SixDegreesSDK.plist");
            proj.AddFileToBuild(targetGuid, proj.AddFile("SixDegreesSDK.plist", "SixDegreesSDK.plist"));
            // Write updated project file
            proj.WriteToFile(projPath);
        }
Beispiel #16
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            // Read Xcode project contents.
            string projectPath     = PBXProject.GetPBXProjectPath(path);
            string projectContents = File.ReadAllText(projectPath);

            // Parse Xcode project.
            PBXProject project = new PBXProject();
            project.ReadFromString(projectContents);

            // Retrieve target identifier.
            string targetName = PBXProject.GetUnityTargetName();
            string targetGuid = project.TargetGuidByName(targetName);
            string target     = project.TargetGuidByName("Unity-iPhone");

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

            // Retrieve MiraRemote.framework identifier.
            string frameworkGuid     = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/MiraRemote.framework");
            string wikiFrameworkGuid = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/Wikitude/WikitudeMiraSDK.framework");
            // Embed framework in app's bundle.
            PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, frameworkGuid);
            PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, wikiFrameworkGuid);

            // Update search paths to include embedded frameworks directory.
            foreach (string name in project.BuildConfigNames())
            {
                string guid = project.BuildConfigByName(targetGuid, name);
                project.SetBuildPropertyForConfig(guid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            }

            project.WriteToFile(projectPath);
        }
    }
    static void AddFileToEmbedFrameworks(PBXProject proj, string targetGuid, string framework)
    {
        string fileGuid = proj.AddFile(framework, framework, UnityEditor.iOS.Xcode.PBXSourceTree.Sdk);

        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, targetGuid, fileGuid);
    }
        public static void ModifyProject(BuildTarget target, string path)
        {
            if (target != BuildTarget.iOS && target != BuildTarget.tvOS)
            {
                return;
            }

            Debug.Log("[AVProVideo] Post-processing Xcode project.");
            Platform platform = Platform.GetPlatformForTarget(target);

            if (platform == null)
            {
                Debug.LogWarningFormat("[AVProVideo] Unknown build target: {0}", target.ToString());
                return;
            }

            string     projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
            PBXProject project     = new PBXProject();

            project.ReadFromFile(projectPath);

            // Attempt to find the plugin path
            string pluginPath = PluginPathForPlatform(platform);

            if (pluginPath.Length > 0)
            {
#if UNITY_2019_3_OR_NEWER
                string targetGuid = project.GetUnityMainTargetGuid();
#else
                string targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

                string frameworkPath = ConvertPluginAssetPathToXcodeProjectFrameworkPath(pluginPath);
                string fileGuid      = project.FindFileGuidByProjectPath(frameworkPath);
                if (fileGuid != null)
                {
                    // Make sure the plugin binary has execute permissions set.
                    // For reasons unknown these are being lost somewhere between the plugin package being built and imported from the asset store.
                    string binaryPath = System.IO.Path.Combine(path, frameworkPath, "AVProVideo");
                    SetFileExecutePermission(binaryPath);

                    Debug.LogFormat("[AVProVideo] Adding 'AVProVideo.framework' to the list of embedded frameworks");
                    PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGuid, fileGuid);

                    Debug.LogFormat("[AVProVideo] Setting 'LD_RUNPATH_SEARCH_PATHS' to '$(inherited) @executable_path/Frameworks'");
                    project.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
                }
                else
                {
                    Debug.LogWarningFormat("[AVProVideo] Failed to find {0} in the generated project. You will need to manually set {0} to 'Embed & Sign' in the Xcode project's framework list.", PluginName);
                }

                // See if we need to enable embedding of Swift binaries
                if (platform.targetOSVersion < Version._12_2)
                {
                    Debug.LogFormat("[AVProVideo] Target OS version '{0}' is < 12.2, setting 'ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES' to 'YES'", platform.targetOSVersion);
                    project.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
                }

                Debug.LogFormat("[AVProVideo] Writing out Xcode project file");
                project.WriteToFile(projectPath);
            }
            else
            {
                Debug.LogErrorFormat("Failed to find '{0}' for '{1}' in the Unity project. Something is horribly wrong, please reinstall AVPro Video.", PluginName, platform);
            }
        }
Beispiel #19
0
        void SetCeliaOverseaSDK()
        {
            string     path     = GetXcodeProjectPath(option.PlayerOption.locationPathName);
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();

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

            // BuildSetting修改
            proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
            proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
            proj.SetBuildProperty(target, "EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE", "YES");   //FB需要
            proj.SetBuildProperty(target, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); //FB需要

            #region 添加XCode引用的Framework

            // SDK依赖 --AIHelp
            proj.AddFrameworkToProject(target, "libsqlite3.tbd", false);
            proj.AddFrameworkToProject(target, "libresolv.tbd", false);
            proj.AddFrameworkToProject(target, "WebKit.framework", false);
            // SDK依赖 --Google
            proj.AddFrameworkToProject(target, "LocalAuthentication.framework", false);
            proj.AddFrameworkToProject(target, "SafariServices.framework", false);
            proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false);
            proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);
            // SDK依赖 --Apple
            proj.AddFrameworkToProject(target, "storekit.framework", false);
            proj.AddFrameworkToProject(target, "AuthenticationServices.framework", false);
            proj.AddFrameworkToProject(target, "gamekit.framework", false);
            // SDK依赖 --Adjust
            proj.AddFrameworkToProject(target, "AdSupport.framework", false);
            proj.AddFrameworkToProject(target, "iAd.framework", false);

            //EmbedFrameworks --Add to Embedded Binaries
            string   defaultLocationInProj = "Plugins/iOS/SDK";
            string[] frameworkNames        = { "FaceBookSDK/FBSDKCoreKit.framework", "FaceBookSDK/FBSDKLoginKit.framework", "FaceBookSDK/FBSDKShareKit.framework", "AdjustSDK/AdjustSdk.framework" };
            foreach (var str in frameworkNames)
            {
                string framework = Path.Combine(defaultLocationInProj, str);
                string fileGuid  = proj.AddFile(framework, "Frameworks/" + framework, PBXSourceTree.Sdk);
                PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
            }
            proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

            #endregion 添加XCode引用的Framework

            string        plistPath = Path.Combine(path, "Info.plist");
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            PlistElementDict rootDict = plist.root;

            #region 修改Xcode工程Info.plist

            /* 从iOS9开始所有的app对外http协议默认要求改成https 若需要添加http协议支持需要额外添加*/
            // Add value of NSAppTransportSecurity in Xcode plist
            PlistElementDict dictTmp = rootDict.CreateDict("NSAppTransportSecurity");
            dictTmp.SetBoolean("NSAllowsArbitraryLoads", true);
            //AIHelp-权限配置
            rootDict.SetString("NSCameraUsageDescription", "是否允许访问相机?");
            rootDict.SetString("NSMicrophoneUsageDescription", "是否允许使用麦克风?");
            rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许添加照片?");
            rootDict.SetString("NSMicrophoneUsageDescription", "是否允许访问相册?");
            rootDict.SetString("NSLocationUsageDescription", "App需要您的同意,才能访问位置");
            rootDict.SetString("NSLocationWhenInUseUsageDescription", "App需要您的同意,才能在使用期间访问位置");
            rootDict.SetString("NSLocationAlwaysUsageDescription", "App需要您的同意,才能始终访问位置");

            rootDict.SetString("CFBundleDevelopmentRegion", "zh_TW");
            //rootDict.SetString("CFBundleVersion", "1");
            // SDK相关参数设置
            rootDict.SetString("FacebookAppID", "949004278872387");
            rootDict.SetString("GoogleClientID", "554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn.apps.googleusercontent.com");
            rootDict.SetString("FacebookAppDisplayName", "少女的王座");
            rootDict.SetString("AIHelpAppID", "elextech_platform_15ce9b10-f784-4ab5-8ee4-45efab40bd6a");
            rootDict.SetString("AIHelpAppKey", "ELEXTECH_app_50dd4661c57843778d850769a02f8a09");
            rootDict.SetString("AIHelpDomain", "*****@*****.**");
            rootDict.SetString("AdjustAppToken", "1k2jm7bpansw");
            rootDict.SetString("AdjustAppSecret", "1,750848352-1884995334-181661496-1073918938");
            //文件共享
            rootDict.SetBoolean("UIFileSharingEnabled", true);
            // Set encryption usage boolean
            string encryptKey = "ITSAppUsesNonExemptEncryption";
            rootDict.SetBoolean(encryptKey, false);
            // remove exit on suspend if it exists.ios13新增
            string exitsOnSuspendKey = "UIApplicationExitsOnSuspend";
            if (rootDict.values.ContainsKey(exitsOnSuspendKey))
            {
                rootDict.values.Remove(exitsOnSuspendKey);
            }
            // URL types配置
            PlistElementArray URLTypes = rootDict.CreateArray("CFBundleURLTypes");
            //Facebook
            PlistElementDict typeRoleFB = URLTypes.AddDict();
            typeRoleFB.SetString("CFBundleTypeRole", "Editor");
            PlistElementArray urlSchemeFB = typeRoleFB.CreateArray("CFBundleURLSchemes");
            urlSchemeFB.AddString("fb949004278872387");
            //Google
            PlistElementDict typeRole = URLTypes.AddDict();
            typeRole.SetString("CFBundleTypeRole", "Editor");
            typeRole.SetString("CFBundleURLName", "com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn");
            PlistElementArray urlScheme = typeRole.CreateArray("CFBundleURLSchemes");
            urlScheme.AddString("com.googleusercontent.apps.554619719418-0hdrkdprcsksigpldvtr9n5lu2lvt5kn");

            // LSApplicationQueriesSchemes配置
            PlistElementArray LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");
            // facebook接入配置
            LSApplicationQueriesSchemes.AddString("fbapi");
            LSApplicationQueriesSchemes.AddString("fb-messenger-share-api");
            LSApplicationQueriesSchemes.AddString("fbauth2");
            LSApplicationQueriesSchemes.AddString("fbshareextension");
            // Line接入配置
            LSApplicationQueriesSchemes.AddString("lineauth");
            LSApplicationQueriesSchemes.AddString("line3rdp.$(APP_IDENTIFIER)");
            LSApplicationQueriesSchemes.AddString("line");
            // 文件追加
            var fileName = "GoogleService-Info.plist";
            var filePath = Path.Combine("Assets/Plugins/iOS/SDK/FCM/", fileName);
            File.Copy(filePath, Path.Combine(option.PlayerOption.locationPathName, "GoogleService-Info.plist"), true);
            proj.AddFileToBuild(target, proj.AddFile(fileName, fileName, PBXSourceTree.Source));

            #endregion 修改Xcode工程Info.plist

            // Capabilitise添加
            var entitlementsFileName = "tw.entitlements";
            var entitlementsFilePath = Path.Combine("Assets/Plugins/iOS/SDK/", entitlementsFileName);
            File.Copy(entitlementsFilePath, Path.Combine(option.PlayerOption.locationPathName, entitlementsFileName), true);
            proj.AddFileToBuild(target, proj.AddFile(entitlementsFileName, entitlementsFileName, PBXSourceTree.Source));
            proj.AddCapability(target, PBXCapabilityType.InAppPurchase, entitlementsFileName);
            proj.AddCapability(target, PBXCapabilityType.GameCenter);
            proj.AddCapability(target, PBXCapabilityType.PushNotifications, entitlementsFileName);
            plist.WriteToFile(plistPath);
            proj.WriteToFile(projPath);
            File.WriteAllText(projPath, proj.WriteToString());
        }
Beispiel #20
0
        public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

#if UNITY_EDITOR_OSX
            Debug.Log("##########" + pathToBuiltProject + "##########");

            string     projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
            PBXProject proj     = new PBXProject();
            proj.ReadFromFile(projPath);
            string target = proj.TargetGuidByName("Unity-iPhone");

            Debug.Log("####### target : " + target + " ############");

            string guidNVS = proj.FindFileGuidByRealPath("Frameworks/Plugins/iOS/NVS.framework", PBXSourceTree.Source);

            Debug.Log("####### NVS Guid : " + guidNVS + "###########");

            if (!string.IsNullOrEmpty(guidNVS))
            {
                //把NVS.framework放到最后去
                proj.RemoveFile(guidNVS);
                proj.RemoveFileFromBuild(target, guidNVS);
                proj.RemoveFrameworkFromProject(target, guidNVS);

                //Debug.Log ("####### add NVS : " +  "###########");
                guidNVS = proj.AddFile("Frameworks/Plugins/iOS/NVS.framework", "Frameworks/Plugins/iOS/NVS.framework");
                if (string.IsNullOrEmpty(guidNVS))
                {
                    Debug.LogError("######### addFile Error ######");
                }

                proj.AddFileToBuild(target, guidNVS);
                PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, guidNVS);
                proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            }


            string stripPath = Path.Combine(pathToBuiltProject, "strip_archs.sh");
            File.Copy(Path.Combine(pathToBuiltProject, "../strip_archs.sh"), stripPath, true);

            string guidStripArchs = proj.AddFile("strip_archs.sh", "strip_archs.sh");
            proj.AppendShellScriptBuildPhase(target, "strip_archs", "/bin/sh", "\"$PROJECT_DIR/strip_archs.sh\"");

            Debug.Log("####### guidStripArchs Guid : " + guidStripArchs + "###########");
            //增加sqlite3库
            proj.AddFrameworkToProject(target, "libsqlite3.tbd", false);
#if GC_VOICE
            proj.AddFrameworkToProject(target, "libstdc++.6.0.9.tbd", false);
            proj.AddFrameworkToProject(target, "libresolv.tbd", false);
#endif

            //设置属性
            proj.SetBuildProperty(target, "OTHER_LDFLAGS", "-weak_framework CoreMotion -weak-lSystem -ObjC");
            proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

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

            Debug.Log("@@@@@@@@@@" + pathToBuiltProject + "@@@@@@@@@@");
#endif
        }
Beispiel #21
0
        private string SetupXCodeProject(NPath pbxTemplatePath, bool dataExists)
        {
            PBXProject pbxProject = new PBXProject();

            pbxProject.ReadFromFile(pbxTemplatePath.ToString());
            var target  = pbxProject.TargetGuidByName(TinyProjectName);
            var targets = new string[] { target };

            // preparing list of libs and adding them to project
            HashSet <NPath> xCodeLibs = new HashSet <NPath>();

            ProcessLibs(this, xCodeLibs);
            foreach (var lib in xCodeLibs)
            {
                var fileGuid = pbxProject.AddFile(lib.FileName, lib.FileName);
                pbxProject.AddFileToBuild(target, fileGuid);
                if (lib.Extension == "dylib")
                {
                    PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, target, fileGuid);
                }
            }

            foreach (var r in m_supportFiles)
            {
                // skipping all subdirectories
                // TODO: subdirectories require special processing (see processing Data below)
                if (r.Path.RelativeTo(Path).Depth == 0 && r.Path.FileName != "testconfig.json")
                {
                    var fileGuid = pbxProject.AddFile(r.Path.FileName, r.Path.FileName);
                    pbxProject.AddFileToBuild(target, fileGuid);
                }
            }
            // adding Data folder
            if (dataExists)
            {
                var fileGuid = pbxProject.AddFile("Data", "Data");
                pbxProject.AddFileToBuild(target, fileGuid);
            }

            pbxProject.SetBuildProperty(targets, "PRODUCT_BUNDLE_IDENTIFIER", $"com.unity.{m_gameName.ToLower()}");
            pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Automatic");
            pbxProject.SetBuildProperty(targets, "PROVISIONING_PROFILE", "");

            /* TODO pass signing config from build settings or from env vars
             * string appleDeveloperTeamID = null;
             * string manualProvisioningProfileName = null;
             * string manualProvisioningProfileUUID = null;
             * string codeSignIdentity = null;
             *
             * appleDeveloperTeamID = Environment.GetEnvironmentVariable("TEAM_ID");
             * manualProvisioningProfileName = Environment.GetEnvironmentVariable("UNITY_IOSPROVISIONINGNAME");
             * manualProvisioningProfileUUID = Environment.GetEnvironmentVariable("UNITY_IOSPROVISIONINGUUID");
             * codeSignIdentity = Environment.GetEnvironmentVariable("UNITY_APPLECERTIFICATENAME");
             *
             * if (!string.IsNullOrEmpty(appleDeveloperTeamID))
             * {
             *  pbxProject.SetBuildProperty(targets, "DEVELOPMENT_TEAM", appleDeveloperTeamID);
             * }
             * if (string.IsNullOrEmpty(manualProvisioningProfileUUID) && string.IsNullOrEmpty(manualProvisioningProfileName))
             * {
             *  pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Automatic");
             *  pbxProject.SetBuildProperty(targets, "PROVISIONING_PROFILE", "Automatic");
             * }
             * else
             * {
             *  pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Manual");
             *  pbxProject.SetBuildProperty(targets, "PROVISIONING_PROFILE", !string.IsNullOrEmpty(manualProvisioningProfileUUID) ? manualProvisioningProfileUUID : manualProvisioningProfileName);
             *  pbxProject.SetBuildProperty(targets, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", codeSignIdentity == null ? "iPhone Developer" : codeSignIdentity);
             * }
             */
            return(pbxProject.WriteToString());
        }
Beispiel #22
0
    public static bool PostProcessIOS(string unityProjectDir, string pathToBuiltProject)
    {
        Debug.Log("XCodePostProcess: Starting to perform post build tasks for iOS platform.");
        string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);


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

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


        MSLDPostProcessCommoniOS.ChangePBProject(pathToBuiltProject, (PBXProject project, string target) => {
            project.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
            project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
            project.AddBuildProperty(target, "OTHER_LDFLAGS", "-lz");


            //添加 Embed Frameworks
            const string frameworkPath = "Frameworks/Plugins/iDreamsky/msld/iOS/libs"; //framework 存放的路径
            string[] frameworkNames    = new string[]
            {
                "MSLDAccount.framework",
                "MSLDAccountUI.framework",
                "MSLDAFNetworking.framework",
                "MSLDCoreBusiness.framework",
                "MSLDCoreFoundation.framework",
                "MSLDDLog.framework",
                "MSLDMasonry.framework",
                "MSLDMJExtension.framework",
                "MSLDPayment.framework",
                "MSLDQQPackage.framework",
                "MSLDQQShare.framework",
                "MSLDReachability.framework",
                "MSLDSDK.framework",
                "MSLDShare.framework",
                "MSLDUIKit.framework",
                "MSLDWeChatPackage.framework",
                "MSLDWeChatShare.framework",
                "MSLDJiGuangPackage.framework",
                "MSLDFeedback.framework",
            };

            foreach (string fwk in frameworkNames)
            {
                string framework = Path.Combine(frameworkPath, fwk);
                Debug.Log("[MSLDPostProcess][iOS][embedFrameworks] framework:" + framework);
                string fileGuid = project.AddFile(framework, "" + framework, PBXSourceTree.Sdk);

                PBXProjectExtensions.AddFileToEmbedFrameworks(project, target, fileGuid);
            }
            project.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");


            // 拷贝配置文件
            // 配置文件 MSLDConfig.json 需要放在Unity的 /Plugins/iDreamsky/msld/iOS/ 目录下
            File.Copy(unityProjectDir + "Assets/Plugins/iDreamsky/msld/iOS/msConfig.json",
                      pathToBuiltProject + "/Libraries/Plugins/iDreamsky/msld/iOS/msConfig.json", true);

            string fileConfig = project.AddFile("Libraries/Plugins/iDreamsky/msld/iOS/msConfig.json",
                                                "Libraries/Plugins/iDreamsky/msld/iOS/msConfig.json",
                                                PBXSourceTree.Source);
            project.AddFileToBuild(target, fileConfig);

            return(true);
        });


        if (!PostProcessControllerIOS(unityProjectDir, pathToBuiltProject))
        {
            return(false);
        }

        return(true);
    }
        private string SetupXCodeProject(NPath pbxTemplatePath)
        {
            PBXProject pbxProject = new PBXProject();

            pbxProject.ReadFromFile(pbxTemplatePath.ToString());
            var target  = pbxProject.TargetGuidByName(TinyProjectName);
            var targets = new string[] { target };

            // preparing list of libs and adding them to project
            HashSet <NPath> xCodeLibs = new HashSet <NPath>();

            ProcessLibs(this, xCodeLibs);
            foreach (var lib in xCodeLibs)
            {
                var fileGuid = pbxProject.AddFile(lib.FileName, lib.FileName);
                pbxProject.AddFileToBuild(target, fileGuid);
                if (lib.Extension == "dylib")
                {
                    PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, target, fileGuid);
                }
            }

            // processing deployable files
            var dataExists = false;

            for (int i = 0; i < Deployables.Length; ++i)
            {
                var r = Deployables[i];
                if (r is DeployableFile)
                {
                    // skipping all subdirectories
                    // TODO: subdirectories require special processing (see processing Data below)
                    var depth = (r as DeployableFile).RelativeDeployPath?.Depth;
                    if ((!depth.HasValue || depth <= 1) && r.Path.FileName != "testconfig.json") // fix this condition somehow
                    {
                        var fileGuid = pbxProject.AddFile(r.Path.FileName, r.Path.FileName);
                        pbxProject.AddFileToBuild(target, fileGuid);
                    }
                    else if (r.Path.HasDirectory("Data"))
                    {
                        dataExists = true;
                    }
                }
            }
            // adding Data folder
            if (dataExists)
            {
                var fileGuid = pbxProject.AddFile("Data", "Data");
                pbxProject.AddFileToBuild(target, fileGuid);
            }

            pbxProject.SetBuildProperty(targets, "PRODUCT_BUNDLE_IDENTIFIER", IOSAppToolchain.Config.Identifier.PackageName);
            pbxProject.SetBuildProperty(targets, "IPHONEOS_DEPLOYMENT_TARGET", IOSAppToolchain.Config.TargetSettings.TargetVersion.ToString(2));
            pbxProject.SetBuildProperty(targets, "ARCHS", IOSAppToolchain.Config.TargetSettings.GetTargetArchitecture());

            pbxProject.SetBuildProperty(targets, "SDKROOT", IOSAppToolchain.Config.TargetSettings.SdkVersion == iOSSdkVersion.DeviceSDK ? "iphoneos" : "iphonesimulator");
            pbxProject.RemoveBuildProperty(targets, "SUPPORTED_PLATFORMS");
            pbxProject.AddBuildProperty(targets, "SUPPORTED_PLATFORMS", "iphoneos");
            if (IOSAppToolchain.Config.TargetSettings.SdkVersion == iOSSdkVersion.SimulatorSDK)
            {
                pbxProject.AddBuildProperty(targets, "SUPPORTED_PLATFORMS", "iphonesimulator");
            }
            pbxProject.SetBuildProperty(targets, "TARGETED_DEVICE_FAMILY", IOSAppToolchain.Config.TargetSettings.GetTargetDeviceFamily());
            pbxProject.SetBuildProperty(targets, "DEVELOPMENT_TEAM", IOSAppToolchain.Config.SigningSettings.SigningTeamID);

            if (!IOSAppToolchain.ExportProject && !BuildConfiguration.HasComponent <iOSSigningSettings>() &&
                Environment.GetEnvironmentVariable("UNITY_TINY_IOS_PROVISIONING_PROFILE") != null)
            {
                pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Manual");
            }
            else if (!IOSAppToolchain.Config.SigningSettings.AutomaticallySign)
            {
                pbxProject.SetBuildProperty(targets, "PROVISIONING_PROFILE", IOSAppToolchain.Config.SigningSettings.ProfileID);
                pbxProject.SetBuildProperty(targets, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", IOSAppToolchain.Config.SigningSettings.CodeSignIdentityValue);
                pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Manual");
            }
            else
            {
                pbxProject.SetBuildProperty(targets, "CODE_SIGN_STYLE", "Automatic");
                // set manual profiles to nothing if automatically signing
                pbxProject.SetBuildProperty(targets, "PROVISIONING_PROFILE", "");
            }
            return(pbxProject.WriteToString().Replace("**ORGANIZATION**", Regex.Replace(IOSAppToolchain.Config.Settings.CompanyName, "[^A-Za-z0-9]", "")));
        }
    public static void OnPostprocessBuild(BuildTarget target, string path)
    {
        // Don't do anything if build target is not iOS
        if (target != BuildTarget.iOS)
        {
            return;
        }

        // Create a PBXProject object for the generated Xcode project
        PBXProject project        = new PBXProject();
        string     pbxProjectPath = PBXProject.GetPBXProjectPath(path);

        project.ReadFromFile(pbxProjectPath);

        // GUID of main app target. This is the target whose build settings we will be modifying.
        string unityAppTargetGuid = project.TargetGuidByName("Unity-iPhone");
        // GUID of UnityFramework target. This target is only present in Unity 2019.3 and above.
        // We need to add our app controller mm file to this target, if present. Else we add
        // it to app target.
        string unityFrameworkTargetGuid = project.TargetGuidByName("UnityFramework");

        // Add HelpshiftX-Unity.h header file to project, if not already added.
        string unityHeaderProjectPath = "Libraries/Helpshift/Plugins/iOS/HelpshiftX-Unity.h";
        string unityHeaderGuid        = project.FindFileGuidByProjectPath(unityHeaderProjectPath);

        if (unityHeaderGuid == null)
        {
            string unityHeaderDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/HelpshiftX-Unity.h";
            project.AddFile(unityHeaderDiskPath, unityHeaderProjectPath, PBXSourceTree.Absolute);
        }

        // Add HsUnityAppController.mm file to project, if not already added.
        string unityAppControllerProjectPath = "Libraries/Helpshift/Plugins/iOS/HsUnityAppController.mm";
        string unityAppControllerGuid        = project.FindFileGuidByProjectPath(unityHeaderProjectPath);

        if (unityAppControllerGuid == null)
        {
            string unityAppControllerDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/HsUnityAppController.mm";
            unityAppControllerGuid = project.AddFile(unityAppControllerDiskPath, unityAppControllerProjectPath, PBXSourceTree.Absolute);
            project.AddFileToBuild(unityFrameworkTargetGuid ?? unityAppTargetGuid, unityAppControllerGuid);
        }

        // Add HelpshiftX.framework to project, if not already added.
        string frameworkProjectPath = "Frameworks/Helpshift/Plugins/iOS/HelpshiftX.framework";
        string frameworkGuid        = project.FindFileGuidByProjectPath(frameworkProjectPath);

        if (frameworkGuid == null)
        {
            string frameworkDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/HelpshiftX.framework";
            frameworkGuid = project.AddFile(frameworkDiskPath, frameworkProjectPath, PBXSourceTree.Absolute);
            project.AddFileToBuild(unityFrameworkTargetGuid ?? unityAppTargetGuid, frameworkGuid);
            // If framework is added to project via this script, we also need to set the Framework Search Path to path of framework on disk.
            project.AddBuildProperty(unityFrameworkTargetGuid ?? unityAppTargetGuid, "FRAMEWORK_SEARCH_PATHS", frameworkDiskPath.Replace("/HelpshiftX.framework", ""));
        }

        // Embed HelpshiftX.framework into main app target
        PBXProjectExtensions.AddFileToEmbedFrameworks(project, unityAppTargetGuid, frameworkGuid);

        // Add script phase to strip simulator slices from HelpshiftX.framework in app target, if not already added
        if (!project.isShellScriptAdded(unityAppTargetGuid, "HS Strip Simulator Slices"))
        {
            project.AddShellScriptBuildPhase(unityAppTargetGuid,
                                             "HS Strip Simulator Slices",
                                             "/bin/sh",
                                             "bash \"${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/HelpshiftX.framework/strip_frameworks.sh\"");
        }

        // Add @executable_path/Frameworks to Runpath Search Paths for app target, if not already added
        if (!project.IsBuildPropertyAdded(unityAppTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"))
        {
            project.AddBuildProperty(unityAppTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");
        }

        // Set Validate Workspace to YES. If you are setting this to NO elsewhere in your build pipeline,
        // comment this line out.
        project.SetBuildProperty(unityAppTargetGuid, "VALIDATE_WORKSPACE", "YES");

        // Add UserNotifications.framework system framework
        project.AddFrameworkToProject(unityFrameworkTargetGuid ?? unityAppTargetGuid, "UserNotifications.framework", false);

        // Save modified Xcode project
        project.WriteToFile(pbxProjectPath);

        // Enable remote notifications
        string preprocessorPath = path + "/Classes/Preprocessor.h";
        string text             = File.ReadAllText(preprocessorPath);

        text = text.Replace("UNITY_USES_REMOTE_NOTIFICATIONS 0", "UNITY_USES_REMOTE_NOTIFICATIONS 1");
        File.WriteAllText(preprocessorPath, text);
    }
Beispiel #25
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
            return;
        }

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

        pbxProject.ReadFromFile(projectPath);
        string targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

        // Add Property
        pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
        pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
        pbxProject.SetBuildProperty(targetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
        pbxProject.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
        pbxProject.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
        pbxProject.SetBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Frameworks/**");
        pbxProject.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/Pods/**");

        // Add Default Framework

        // IGAWorksCore
        AddLibToProject(pbxProject, targetGuid, "libxml2.tbd");
        pbxProject.AddFrameworkToProject(targetGuid, "iAd.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "UIKit.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreGraphics.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreText.framework", false);

        // Adbrix
        pbxProject.AddFrameworkToProject(targetGuid, "MessageUI.framework", false);

        // NaverCafe
        pbxProject.AddFrameworkToProject(targetGuid, "AVKit.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "AVFoundation.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "MediaPlayer.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreMedia.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "AssetsLibrary.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "ImageIO.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "QuartzCore.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "ReplayKit.framework", true);

        // NaverCafe & IGAWorksCore
        pbxProject.AddFrameworkToProject(targetGuid, "MobileCoreServices.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);

        // NaverCafe & GamePot
        pbxProject.AddFrameworkToProject(targetGuid, "WebKit.framework", false);

        // Facebook & Google SignIn
        pbxProject.AddFrameworkToProject(targetGuid, "SafariServices.framework", false);

        // Adjust
        pbxProject.AddFrameworkToProject(targetGuid, "AdSupport.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "UserNotifications.framework", false);

        // Google
        pbxProject.AddFrameworkToProject(targetGuid, "AuthenticationServices.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "LocalAuthentication.framework", false);

        AddLibToProject(pbxProject, targetGuid, "libz.tbd");

        //Unity 2019.03.x 이후 버전에서의 BuildTarget 재맵핑
#if UNITY_2019_3_OR_NEWER
        targetGuid = pbxProject.TargetGuidByName("UnityFramework");

        pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
        pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
        pbxProject.SetBuildProperty(targetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
        pbxProject.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
        pbxProject.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
        // Google
        pbxProject.AddFrameworkToProject(targetGuid, "LocalAuthentication.framework", false);
        // Facebook & Google SignIn
        pbxProject.AddFrameworkToProject(targetGuid, "SafariServices.framework", false);

        //Target 원상복귀
        targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

        // Add Bundle  explicitly
        AddBundle(pbxProject, targetGuid, pathToBuiltProject, "GamePot.bundle");
        AddBundle(pbxProject, targetGuid, pathToBuiltProject, "GoogleSignIn.bundle");
        AddBundle(pbxProject, targetGuid, pathToBuiltProject, "NaverAuth.bundle");
        AddBundle(pbxProject, targetGuid, pathToBuiltProject, "NaverCafeSDK.bundle");
#endif

        const string frameworkPath = "Frameworks/Plugins/IOS/Frameworks/";

        const string twitterCoreFrameworkName = "TwitterCore.framework";
        if (Directory.Exists(Application.dataPath + "/Plugins/IOS/Frameworks/" + twitterCoreFrameworkName))
        {
            PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, pbxProject.AddFile(frameworkPath + twitterCoreFrameworkName, frameworkPath + twitterCoreFrameworkName));
        }

        const string lineFrameworkName = "LineSDK.framework";
        if (Directory.Exists(Application.dataPath + "/Plugins/IOS/Frameworks/" + lineFrameworkName))
        {
            PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, pbxProject.AddFile(frameworkPath + lineFrameworkName, frameworkPath + lineFrameworkName));
        }

        const string twitterKitFrameworkName = "TwitterKit.framework";
        if (Directory.Exists(Application.dataPath + "/Plugins/IOS/Frameworks/" + twitterKitFrameworkName))
        {
            PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, pbxProject.AddFile(frameworkPath + twitterKitFrameworkName, frameworkPath + twitterKitFrameworkName));
        }


        const string lineObjCFrameworkName = "LineSDKObjC.framework";
        if (Directory.Exists(Application.dataPath + "/Plugins/IOS/Frameworks/" + lineObjCFrameworkName))
        {
            PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, pbxProject.AddFile(frameworkPath + lineObjCFrameworkName, frameworkPath + lineObjCFrameworkName));
        }

        const string naverThirdPartyLoginFrameworkName = "NaverThirdPartyLogin.framework";
        if (Directory.Exists(Application.dataPath + "/Plugins/IOS/Frameworks/" + naverThirdPartyLoginFrameworkName))
        {
            PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, pbxProject.AddFile(frameworkPath + naverThirdPartyLoginFrameworkName, frameworkPath + naverThirdPartyLoginFrameworkName));
        }

        pbxProject.RemoveFileFromBuild(targetGuid, "TwitterCore.framework");
        pbxProject.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");


        //GamePot Config Key
        if (File.Exists(pathToBuiltProject + "/GamePotConfig-Info.plist"))
        {
            File.Delete(pathToBuiltProject + "/GamePotConfig-Info.plist");
        }

        if (File.Exists(pathToBuiltProject + "/GoogleService-Info.plist"))
        {
            File.Delete(pathToBuiltProject + "/GoogleService-Info.plist");
        }

        File.Copy(Application.dataPath + "/Plugins/IOS/GamePotConfig-Info.plist", pathToBuiltProject + "/GamePotConfig-Info.plist");
        pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile("GamePotConfig-Info.plist", "GamePotConfig-Info.plist"));

        File.Copy(Application.dataPath + "/Plugins/IOS/GoogleService-Info.plist", pathToBuiltProject + "/GoogleService-Info.plist");
        pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist"));

        pbxProject.WriteToFile(projectPath);

        // Apply settings
        File.WriteAllText(projectPath, pbxProject.WriteToString());

        // Info.plist file Setting
        var plistPath    = Path.Combine(pathToBuiltProject, "Info.plist");
        var gamePotPath  = Path.Combine(pathToBuiltProject, "GamePotConfig-Info.plist");
        var plist        = new PlistDocument();
        var gamePotPlist = new PlistDocument();

        plist.ReadFromFile(plistPath);
        gamePotPlist.ReadFromFile(gamePotPath);

        PlistElementDict dict     = plist.root.AsDict();
        PlistElementDict gameDict = gamePotPlist.root.AsDict();

        // Add LSApplicationQueriesSchemes
        PlistElementArray querisesSchemesArray = dict.CreateArray("LSApplicationQueriesSchemes");
        querisesSchemesArray.AddString("navercafe");
        querisesSchemesArray.AddString("naversearchapp");
        querisesSchemesArray.AddString("naversearchthirdlogin");
        querisesSchemesArray.AddString("fbapi");
        querisesSchemesArray.AddString("fb-messenger-share-api");
        querisesSchemesArray.AddString("fbauth2");
        querisesSchemesArray.AddString("fbshareextension");
        querisesSchemesArray.AddString("lineauth2");
        querisesSchemesArray.AddString("twitter");
        querisesSchemesArray.AddString("twitterauth");

        // Add URL Scheme
        var array = plist.root.CreateArray("CFBundleURLTypes");

        if (gameDict.values.ContainsKey("gamepot_naver_urlscheme") && gameDict["gamepot_naver_urlscheme"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString(gameDict["gamepot_naver_urlscheme"].AsString());
        }

        if (gameDict.values.ContainsKey("gamepot_facebook_app_id") && gameDict["gamepot_facebook_app_id"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString("fb" + gameDict["gamepot_facebook_app_id"].AsString());
        }

        if (gameDict.values.ContainsKey("gamepot_google_url_schemes") && gameDict ["gamepot_google_url_schemes"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString(gameDict ["gamepot_google_url_schemes"].AsString());
        }

        if (gameDict.values.ContainsKey("gamepot_line_url_schemes") && gameDict ["gamepot_line_url_schemes"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString(gameDict ["gamepot_line_url_schemes"].AsString());
        }

        if (gameDict.values.ContainsKey("gamepot_twitter_consumerkey") && gameDict ["gamepot_twitter_consumerkey"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString("twitterkit-" + gameDict ["gamepot_twitter_consumerkey"].AsString());
        }

        if (gameDict.values.ContainsKey("gamepot_naver_urlscheme") && gameDict ["gamepot_naver_urlscheme"].AsString().Equals("") != true)
        {
            var urlDict = array.AddDict();
            urlDict.SetString("CFBundleURLName", "");
            urlDict.CreateArray("CFBundleURLSchemes").AddString(gameDict ["gamepot_naver_urlscheme"].AsString());
        }
        // Apply editing settings to Info.plist
        plist.WriteToFile(plistPath);
    }
Beispiel #26
0
        /// <summary>
        /// 将SDK复制到XCode项目
        /// </summary>
        /// <param name="pbxProject">PBXProject</param>
        /// <param name="targetGuid">Target Guid</param>
        /// <param name="unityTargetGuid">UnityFramework Guid, since 2019.3</param>
        /// <param name="sourcePath">SDK路径</param>
        /// <param name="destPath">XCode项目路径</param>
        /// <param name="destRelativePath">XCode项目用于复制SDK的相对路径</param>
        /// <param name="isAddBuild">是否加入Build</param>
        public static void CopySDKDirectoryToXCode(PBXProject pbxProject, string targetGuid, string unityTargetGuid, string sourcePath, string destPath, string destRelativePath, bool isAddBuild = true)
        {
            var files        = Directory.GetFiles(sourcePath);
            var buildPhaseId = pbxProject.AddSourcesBuildPhase(targetGuid);

            foreach (var file in files)
            {
                var fileName = Path.GetFileName(file);
                if (fileName[0] == '.')
                {
                    continue;
                }

                string fileExtension = Path.GetExtension(file);

                if (fileExtension == ExtensionName.META || fileExtension == ExtensionName.RTF)
                {
                    continue;
                }
                else if (fileExtension == ExtensionName.ARCHIVE)
                {
                    pbxProject.AddBuildProperty(unityTargetGuid, "LIBRARY_SEARCH_PATHS", "$(PROJECT_DIR)/" + destRelativePath);
                }

                string copyPath = Path.Combine(destPath, destRelativePath);

                if (!Directory.Exists(copyPath))
                {
                    Directory.CreateDirectory(copyPath);
                }

                File.Copy(file, Path.Combine(copyPath, fileName), true);

                if (isAddBuild)
                {
                    var buildPath = Path.Combine(destRelativePath, fileName);
                    var newGuid   = pbxProject.AddFile(buildPath, buildPath, PBXSourceTree.Source);


#if UNITY_2019_3_OR_NEWER
                    var ext = Path.GetExtension(fileName);
                    if (ext.Equals(".h", StringComparison.CurrentCultureIgnoreCase) || ext.Equals(".m", StringComparison.CurrentCultureIgnoreCase))
                    {
                        pbxProject.AddFileToBuildSection(unityTargetGuid, buildPhaseId, newGuid);
                    }
                    else
                    {
                        if (fileName.Equals("JCiOSConfig.plist"))
                        {
                            pbxProject.AddFileToBuild(targetGuid, newGuid);
                        }
                        else
                        {
                            pbxProject.AddFileToBuild(unityTargetGuid, newGuid);
                        }
                    }
#else
                    pbxProject.AddFileToBuild(unityTargetGuid, newGuid);
#endif
                }
            }

            var dirs = Directory.GetDirectories(sourcePath);

            foreach (var dir in dirs)
            {
                var dirName = Path.GetFileName(dir);
                if (dirName.StartsWith("."))
                {
                    continue;
                }

                bool needAddBuild = isAddBuild;

                if (dirName.EndsWith(ExtensionName.FRAMEWORK) || dirName.EndsWith(ExtensionName.BUNDLE))
                {
                    var buildPath = Path.Combine(destRelativePath, dirName);
                    var newGuid   = pbxProject.AddFile(buildPath, buildPath, PBXSourceTree.Source);
                    pbxProject.AddFileToBuild(unityTargetGuid, newGuid);
                    pbxProject.AddBuildProperty(unityTargetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/" + destRelativePath);
                    needAddBuild = false;

                    if (embedFrameworkList.Contains(dirName))
                    {
                        PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, newGuid);
                    }
                }

                CopySDKDirectoryToXCode(pbxProject, targetGuid, unityTargetGuid, dir, destPath, Path.Combine(destRelativePath, dirName), needAddBuild);
            }
        }
    //拷贝并增加到项目
    public static void CopyAndAddBuildToXcode(PBXProject pbxProject, string targetGuid, string copyDirectoryPath, string buildPath, string currentDirectoryPath, List <string> embedFrameworks, bool needToAddBuild = true)
    {
        string unityDirectoryPath = copyDirectoryPath;
        string xcodeDirectoryPath = buildPath;

        if (!string.IsNullOrEmpty(currentDirectoryPath))
        {
            unityDirectoryPath = Path.Combine(unityDirectoryPath, currentDirectoryPath);
            xcodeDirectoryPath = Path.Combine(xcodeDirectoryPath, currentDirectoryPath);
            Delete(xcodeDirectoryPath);
            Directory.CreateDirectory(xcodeDirectoryPath);
        }

        foreach (string filePath in Directory.GetFiles(unityDirectoryPath))
        {
            //过滤.meta文件
            string extension = Path.GetExtension(filePath);
            if (extension == ExtensionName.META)
            {
                continue;
            }
            //
            if (extension == ExtensionName.ARCHIVE)
            {
                pbxProject.AddBuildProperty(targetGuid, XcodeProjectSetting.LIBRARY_SEARCH_PATHS_KEY, XcodeProjectSetting.PROJECT_ROOT + currentDirectoryPath);
            }

            string fileName = Path.GetFileName(filePath);
            string copyPath = Path.Combine(xcodeDirectoryPath, fileName);

            //有可能是.DS_Store文件,直接过滤
            if (fileName[0] == '.')
            {
                continue;
            }
            File.Delete(copyPath);
            File.Copy(filePath, copyPath);

            if (needToAddBuild)
            {
                string relativePath = Path.Combine(currentDirectoryPath, fileName);
                //特殊化处理,XMain目录下文件添加flags:-fno-objc-arc
                if (relativePath.Contains(ExtensionName.XMain))
                {
                    pbxProject.AddFileToBuildWithFlags(targetGuid, pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source), "-fno-objc-arc");
                }
                else
                {
                    pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source));
                }
            }
        }

        foreach (string directoryPath in Directory.GetDirectories(unityDirectoryPath))
        {
            string directoryName = Path.GetFileName(directoryPath);
            if (directoryName.Contains(ExtensionName.LANGUAGE) && needToAddBuild)
            {
                //特殊化处理本地语言,暂时官方PBXProject不支持AddLocalization方法,如果需要,则必须自己扩充
                string relativePath = Path.Combine(currentDirectoryPath, directoryName);
                CopyAndAddBuildToXcode(pbxProject, targetGuid, copyDirectoryPath, buildPath, relativePath, embedFrameworks, false);
                string[] dirs = Directory.GetDirectories(Path.Combine(xcodeDirectoryPath, directoryName));
                if (dirs.Length > 0)
                {
                    string fileName = Path.GetFileName(Directory.GetFiles(dirs[0], "*.strings")[0]);
                    AddLocalizedStrings(pbxProject, buildPath, fileName, directoryPath, directoryName);
                }
            }
            else
            {
                bool nextNeedToAddBuild = needToAddBuild;
                if (directoryName.Contains(ExtensionName.FRAMEWORK) || directoryName.Contains(ExtensionName.BUNDLE) || directoryName == XcodeProjectSetting.IMAGE_XCASSETS_DIRECTORY_NAME)
                {
                    nextNeedToAddBuild = false;
                }
                CopyAndAddBuildToXcode(pbxProject, targetGuid, copyDirectoryPath, buildPath, Path.Combine(currentDirectoryPath, directoryName), embedFrameworks, nextNeedToAddBuild);
                if (directoryName.Contains(ExtensionName.FRAMEWORK))
                {
                    string relativePath = Path.Combine(currentDirectoryPath, directoryName);
                    string fileGuid     = pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source);
                    pbxProject.AddFileToBuild(targetGuid, fileGuid);
                    pbxProject.AddBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, XcodeProjectSetting.PROJECT_ROOT + currentDirectoryPath);

                    if (embedFrameworks.Contains(directoryName))
                    {
                        PBXProjectExtensions.AddFileToEmbedFrameworks(pbxProject, targetGuid, fileGuid);
                    }
                }
                else if (directoryName.Contains(ExtensionName.BUNDLE) && needToAddBuild)
                {
                    string relativePath = Path.Combine(currentDirectoryPath, directoryName);
                    string fileGuid     = pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source);
                    pbxProject.AddFileToBuild(targetGuid, fileGuid);
                    pbxProject.AddBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, XcodeProjectSetting.PROJECT_ROOT + currentDirectoryPath);
                }
            }
        }
    }
    public static void OnPostprocessBuild(BuildTarget target, string path)
    {
        // Don't do anything if build target is not iOS
        if (target != BuildTarget.iOS)
        {
            return;
        }

        // Create a PBXProject object for the generated Xcode project
        PBXProject project        = new PBXProject();
        string     pbxProjectPath = PBXProject.GetPBXProjectPath(path);

        project.ReadFromFile(pbxProjectPath);

        // GUID of main app target. This is the target whose build settings we will be modifying.
        string unityAppTargetGuid = project.TargetGuidByName("Unity-iPhone");
        // GUID of UnityFramework target. This target is only present in Unity 2019.3 and above.
        // We need to add our app controller header file to this target, if present. Else we add
        // it to app target.
        string unityFrameworkTargetGuid = project.TargetGuidByName("UnityFramework");

        // Add Helpshift-Unity.h header file to project, if not already added.
        string unityHeaderProjectPath = "Libraries/Helpshift/Plugins/iOS/Helpshift-Unity.h";
        string unityHeaderGuid        = project.FindFileGuidByProjectPath(unityHeaderProjectPath);

        if (unityHeaderGuid == null)
        {
            string unityHeaderDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/Helpshift-Unity.h";
            project.AddFile(unityHeaderDiskPath, unityHeaderProjectPath, PBXSourceTree.Absolute);
        }

        // Add HsUnityAppController.mm file to project, if not already added.
        string unityAppControllerProjectPath = "Libraries/Helpshift/Plugins/iOS/HsUnityAppController.mm";
        string unityAppControllerGuid        = project.FindFileGuidByProjectPath(unityHeaderProjectPath);

        if (unityAppControllerGuid == null)
        {
            string unityAppControllerDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/HsUnityAppController.mm";
            unityAppControllerGuid = project.AddFile(unityAppControllerDiskPath, unityAppControllerProjectPath, PBXSourceTree.Absolute);
            project.AddFileToBuild(unityFrameworkTargetGuid ?? unityAppTargetGuid, unityAppControllerGuid);
        }

        // Add Helpshift.framework to project, if not already added.
        string frameworkProjectPath = "Frameworks/Helpshift/Plugins/iOS/Helpshift.framework";
        string frameworkGuid        = project.FindFileGuidByProjectPath(frameworkProjectPath);

        if (frameworkGuid == null)
        {
            // Normal Helpshift.framework not added in project. Check if bitcode framework is added.
            frameworkProjectPath = "Frameworks/Helpshift/Plugins/iOS/Bitcode/Helpshift.framework";
            frameworkGuid        = project.FindFileGuidByProjectPath(frameworkProjectPath);
        }
        if (frameworkGuid == null)
        {
            string frameworkDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/Helpshift.framework";
            if (!Directory.Exists(frameworkDiskPath))
            {
                // Normal framework not found on disk. Check if bitcode framework is found.
                frameworkDiskPath = Application.dataPath + "/Helpshift/Plugins/iOS/Bitcode/Helpshift.framework";
            }
            frameworkGuid = project.AddFile(frameworkDiskPath, frameworkProjectPath, PBXSourceTree.Absolute);
            project.AddFileToBuild(unityFrameworkTargetGuid ?? unityAppTargetGuid, frameworkGuid);
            // If framework is added to project via this script, we also need to set the Framework Search Path to path of framework on disk.
            project.AddBuildProperty(unityFrameworkTargetGuid ?? unityAppTargetGuid, "FRAMEWORK_SEARCH_PATHS", frameworkDiskPath.Replace("/Helpshift.framework", ""));
        }

        // Embed Helpshift.framework into main app target
        PBXProjectExtensions.AddFileToEmbedFrameworks(project, unityAppTargetGuid, frameworkGuid);

        // Add script phase to strip simulator slices from Helpshift.framework in app target
        if (!project.isShellScriptAdded(unityAppTargetGuid, "HS Strip Simulator Slices"))
        {
            project.AddShellScriptBuildPhase(unityAppTargetGuid,
                                             "HS Strip Simulator Slices",
                                             "/bin/sh",
                                             "bash \"${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Helpshift.framework/strip_frameworks.sh\"");
        }

        // Set Always Embed Swift Standard Libraries to YES for app target
        project.SetBuildProperty(unityAppTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");

        // Add @executable_path/Frameworks to Runpath Search Paths for app target
        if (!project.IsBuildPropertyAdded(unityAppTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"))
        {
            project.AddBuildProperty(unityAppTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");
        }

        /**
         * Uncomment this line if you want to add custom themes for Helpshift SDK
         * Refer https://developers.helpshift.com/unity/design-ios/ to know more
         */
        // Add Helpshift theming plist files to main app target
        // HelpshiftPostProcess.AddHelpshiftCustomThemes(project);

        // Save modified Xcode project
        project.WriteToFile(pbxProjectPath);

        // Enable remote notifications
        string preprocessorPath = path + "/Classes/Preprocessor.h";
        string text             = File.ReadAllText(preprocessorPath);

        text = text.Replace("UNITY_USES_REMOTE_NOTIFICATIONS 0", "UNITY_USES_REMOTE_NOTIFICATIONS 1");
        File.WriteAllText(preprocessorPath, text);
    }