Esempio n. 1
0
    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 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);
        }
    }
Esempio n. 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
 }
Esempio n. 4
0
    private static void AddNotificationServiceExtension(PBXProject project, string path)
    {
#if UNITY_2017_2_OR_NEWER && !UNITY_CLOUD_BUILD
        var projectPath         = PBXProject.GetPBXProjectPath(path);
        var mainTargetGUID      = GetPBXProjectTargetGUID(project);
        var extensionTargetName = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME;

        var exisitingPlistFile = CreateNotificationExtensionPlistFile(path);
        // If file exisits then the below has been completed before from another build
        // The below will not be updated on Append builds
        // Changes would most likely need to be made to support Append builds
        if (exisitingPlistFile)
        {
            return;
        }

        var extensionGUID = PBXProjectExtensions.AddAppExtension(
            project,
            mainTargetGUID,
            extensionTargetName,
            PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + extensionTargetName,
            extensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
            );

        AddNotificationServiceSourceFilesToTarget(project, extensionGUID, path);

        foreach (var framework in FRAMEWORKS_TO_ADD)
        {
            project.AddFrameworkToProject(extensionGUID, framework, true);
        }

        // Makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
        project.SetBuildProperty(extensionGUID, "TARGETED_DEVICE_FAMILY", "1,2");
        project.SetBuildProperty(extensionGUID, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");

        project.SetBuildProperty(extensionGUID, "ARCHS", "$(ARCHS_STANDARD)");
        project.SetBuildProperty(extensionGUID, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);

        project.AddBuildProperty(extensionGUID, "LIBRARY_SEARCH_PATHS", "$(PROJECT_DIR)/Libraries/OneSignal/Platforms/iOS");
        project.WriteToFile(projectPath);

        // Add libOneSignal.a to the OneSignalNotificationServiceExtension target
        var contents = File.ReadAllText(projectPath);

        // This method only modifies the PBXProject string passed in (contents).
        // After this method finishes, we must write the contents string to disk
        InsertStaticFrameworkIntoTargetBuildPhaseFrameworks("libOneSignal", "CD84C25F20742FAB0035D524", extensionGUID, ref contents, project);
        File.WriteAllText(projectPath, contents);

        AddOrUpdateEntitlements(
            path,
            project,
            extensionGUID,
            extensionTargetName,
            new HashSet <EntitlementOptions> {
            EntitlementOptions.AppGroups
        }
            );
#endif
    }
Esempio n. 5
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);
        }
        // 添加动态库 注意路径
        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");
        }
Esempio n. 8
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/");
            }
        }
Esempio n. 10
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));
        }
Esempio n. 12
0
    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);
    }
Esempio n. 13
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());
             }
         }
     }
 }
Esempio n. 16
0
        private void ExtractFrameworkAndAddItToXcode(string pathToBuiltProject)
        {
            //
            //  Extracts framework
            //
            const string frameworksDir = "Frameworks";
            //const string frameworksDir = "Plugins";
            var pathToExport2 = Path.Combine((GetMacOsProjectPath(pathToBuiltProject)), "Plugins");
            var pathToExport  = Directory.GetParent(GetMacOsProjectPath(pathToBuiltProject)).FullName;
            var pathToLib     = Path.Combine(Application.dataPath, EditorHelpers.PluginPath + "/libs/Standalone/UniversalDeepLink.framework.zip");


            ShellHelper.ShellRequest unzip = ShellHelper.ProcessFileCommand("unzip", string.Format("-o \"{0}\" -d \"{1}\"", pathToLib, pathToExport));
            //
            //  Remove this and remove the Copy file options from the pbxx
            //
            ShellHelper.ShellRequest _ = ShellHelper.ProcessFileCommand("unzip", string.Format("-o \"{0}\" -d \"{1}\"", pathToLib, pathToExport2));

            unzip.OnDone += () =>
            {
                string     projectPath = PBXProject.GetPBXProjectPath(_macOsXcodeProj);
                PBXProject project     = new PBXProject();
                project.ReadFromString(File.ReadAllText(projectPath));

                //
                //  Adds framework to pbx
                //
                var frameworkInProject = Path.Combine(Application.productName, frameworksDir);
                frameworkInProject = Path.Combine(frameworkInProject, FrameworkName);
                var prodGuid = project.TargetGuidByName(Application.productName);

                var myFramework = project.AddFile(FrameworkName, frameworkInProject, PBXSourceTree.Source);
                project.AddFileToBuild(prodGuid, myFramework);
                PBXProjectExtensions.AddFileToEmbedLibraries(project, prodGuid, myFramework);

                File.WriteAllText(projectPath, project.WriteToString());
                BuildProcessor.TriggerOnPostBuildProcessCompleted();
            };
        }
        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);
        }
Esempio n. 18
0
        public static void OnPostprocessBuildHandler(BuildTarget buildTarget, string path)
        {
            if (buildTarget == BuildTarget.iOS)
            {
                var projPath = PBXProject.GetPBXProjectPath(path);
                var proj     = new PBXProject();
                proj.ReadFromFile(projPath);

#if UNITY_2019_3_OR_NEWER
                var targetGUID = proj.GetUnityFrameworkTargetGuid();
 #else
                var targetGUID = proj.TargetGuidByName("Unity-iPhone");
 #endif
                var notificationServicePlistPath = PathToNotificationService + "/Info.plist";

                var notificationServicePlist = new PlistDocument();
                notificationServicePlist.ReadFromFile(notificationServicePlistPath);
                notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
                notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber);
                notificationServicePlist.root.SetString("CFBundleDisplayName", PlayerSettings.iOS.applicationDisplayName);

                notificationServicePlist.WriteToFile(notificationServicePlistPath);

                var notificationServiceTarget = PBXProjectExtensions.AddAppExtension(proj, targetGUID, "notificationservice", PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + ".bknotificationservice", notificationServicePlistPath);

                proj.AddHeadersBuildPhase(notificationServiceTarget);

                proj.AddFileToBuild(notificationServiceTarget, proj.AddFile(PathToNotificationService + "/NotificationService.h", "NotificationService/NotificationService.h"));
                proj.AddFileToBuild(notificationServiceTarget, proj.AddFile(PathToNotificationService + "/NotificationService.m", "NotificationService/NotificationService.m"));
                proj.AddFrameworkToProject(notificationServiceTarget, "NotificationCenter.framework", true);
                proj.AddFrameworkToProject(notificationServiceTarget, "UserNotifications.framework", true);
                proj.SetBuildProperty(notificationServiceTarget, "ARCHS", "$(ARCHS_STANDARD)");
                proj.SetBuildProperty(notificationServiceTarget, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
                proj.SetBuildProperty(notificationServiceTarget, "TARGETED_DEVICE_FAMILY", "1,2");

                proj.WriteToFile(projPath);
            }
        }
Esempio n. 19
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);
        }
    }
    //拷贝并增加到项目
    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);
                }
            }
        }
    }
Esempio n. 21
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 CreateRichPushNotificationTarget(BuildTarget buildTarget, string buildOutputPath)
    {
        iOSConfiguration config = iOSConfiguration.Load();

        if (!config.enableRichPushNotifications)
        {
            return;
        }

        string     xcodeProjectPath = PBXProject.GetPBXProjectPath(buildOutputPath);
        PBXProject project          = new PBXProject();

        project.ReadFromFile(xcodeProjectPath);

        string guidOfInitialTarget = GetTargetGuid(project);

        string        pathToInfoPlist      = Path.Combine(buildOutputPath, PATH_TO_INFO_PLIST_INSIDE_TARGET);
        PlistDocument mainProjectInfoPlist = new PlistDocument();

        mainProjectInfoPlist.ReadFromFile(pathToInfoPlist);
        PlistElementArray array = mainProjectInfoPlist.root.CreateArray("UIBackgroundModes");

        array.AddString("remote-notification");
        mainProjectInfoPlist.WriteToFile(pathToInfoPlist);

        string bundleIdentifierForNotificationService = config.pushNotificationServiceExtensionIdentifier;
        int    indexOfLastIdentifierSection           = bundleIdentifierForNotificationService.LastIndexOf('.') + 1;
        string displayName = bundleIdentifierForNotificationService.Substring(indexOfLastIdentifierSection);

        string pathToNotificationServiceImplementation = Path.Combine(buildOutputPath, displayName);

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

        PlistDocument notificationServicePlist = new PlistDocument();
        string        plistTemplatePath        = Path.Combine(GetPathToSourceDirectory(), "Info.plist");

        notificationServicePlist.ReadFromFile(plistTemplatePath);
        notificationServicePlist.root.SetString("CFBundleDisplayName", displayName);
        notificationServicePlist.root.SetString("CFBundleIdentifier", bundleIdentifierForNotificationService);
        notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
        notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString());

        string pathToNotificationServicePlist = Path.Combine(pathToNotificationServiceImplementation, PATH_TO_INFO_PLIST_INSIDE_TARGET);

        notificationServicePlist.WriteToFile(pathToNotificationServicePlist);

        string guidOfExtension = PBXProjectExtensions.AddAppExtension(
            project, guidOfInitialTarget,
            displayName,
            PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + ".notificationservice",
            pathToNotificationServicePlist
            );
        string buildPhaseId = project.AddSourcesBuildPhase(guidOfExtension);

        AddSourceFileToProject(
            project,
            "NotificationService.h",
            displayName,
            guidOfExtension,
            buildPhaseId,
            pathToNotificationServiceImplementation
            );
        AddSourceFileToProject(
            project,
            "NotificationService.m",
            displayName,
            guidOfExtension,
            buildPhaseId,
            pathToNotificationServiceImplementation
            );
        AddFileToProject(
            project,
            pathToNotificationServicePlist,
            "Info.plist",
            displayName,
            guidOfExtension,
            buildPhaseId
            );

        project.AddFrameworkToProject(guidOfExtension, "NotificationCenter.framework", true);
        project.AddFrameworkToProject(guidOfExtension, "UserNotifications.framework", true);
        project.SetBuildProperty(guidOfExtension, "ARCHS", "$(ARCHS_STANDARD");
        project.SetBuildProperty(guidOfExtension, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);

        string[] copyableProperties =
        {
            "IPHONEOS_DEPLOYMENT_TARGET",
            "TARGETED_DEVICE_FAMILY"
        };
        foreach (string copyableProperty in copyableProperties)
        {
            string originalBuildProperty = project.GetBuildPropertyForAnyConfig(guidOfInitialTarget, copyableProperty);
            project.SetBuildProperty(guidOfExtension, copyableProperty, originalBuildProperty);
        }

        project.WriteToFile(xcodeProjectPath);
    }
    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);
            }
        }
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        string     projectPath = PBXProject.GetPBXProjectPath(path);
        PBXProject project     = new PBXProject();

        project.ReadFromString(File.ReadAllText(projectPath));
        string targetName = PBXProject.GetUnityTargetName();
        string targetGUID = project.TargetGuidByName(targetName);

        // UserNotifications.framework is required by libOneSignal.a
        project.AddFrameworkToProject(targetGUID, "UserNotifications.framework", false);

        var extensionTargetName       = "OneSignalNotificationServiceExtension";
        var pathToNotificationService = path + "/" + extensionTargetName;

        Directory.CreateDirectory(pathToNotificationService);

        var notificationServicePlistPath = pathToNotificationService + "/Info.plist";

        PlistDocument notificationServicePlist = new PlistDocument();

        notificationServicePlist.ReadFromFile("Assets/OneSignal/Platforms/iOS/Info.plist");
        notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
        notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString());

        var notificationServiceTarget = PBXProjectExtensions.AddAppExtension(project, targetGUID, extensionTargetName, PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + extensionTargetName, notificationServicePlistPath);

        var sourceDestination = extensionTargetName + "/NotificationService";

        project.AddFileToBuild(notificationServiceTarget, project.AddFile(sourceDestination + ".h", sourceDestination + ".h", PBXSourceTree.Source));
        project.AddFileToBuild(notificationServiceTarget, project.AddFile(sourceDestination + ".m", sourceDestination + ".m", PBXSourceTree.Source));

        var frameworks = new string[] { "NotificationCenter.framework", "UserNotifications.framework", "UIKit.framework", "SystemConfiguration.framework" };

        foreach (string framework in frameworks)
        {
            project.AddFrameworkToProject(notificationServiceTarget, framework, true);
        }

        //makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
        project.SetBuildProperty(notificationServiceTarget, "TARGETED_DEVICE_FAMILY", "1,2");
        project.SetBuildProperty(notificationServiceTarget, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");

        project.SetBuildProperty(notificationServiceTarget, "ARCHS", "$(ARCHS_STANDARD)");
        project.SetBuildProperty(notificationServiceTarget, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);

        notificationServicePlist.WriteToFile(notificationServicePlistPath);

        FileUtil.CopyFileOrDirectory("Assets/OneSignal/Platforms/iOS/NotificationService.h", path + "/" + sourceDestination + ".h");
        FileUtil.CopyFileOrDirectory("Assets/OneSignal/Platforms/iOS/NotificationService.m", path + "/" + sourceDestination + ".m");

        project.WriteToFile(projectPath);

        //add libOneSignal.a to the OneSignalNotificationServiceExtension target
        string contents = File.ReadAllText(projectPath);

        //this method only modifies the PBXProject string passed in (contents).
        //after this method finishes, we must write the contents string to disk
        InsertStaticFrameworkIntoTargetBuildPhaseFrameworks("libOneSignal", "CD84C25F20742FAB0035D524", notificationServiceTarget, ref contents, project);
        File.WriteAllText(projectPath, contents);

        // enable the Notifications capability in the main app target
        project.ReadFromString(contents);
        var entitlementPath = path + "/" + targetName + "/" + targetName + ".entitlements";

        PlistDocument entitlements = new PlistDocument();

        entitlements.root.SetString("aps-environment", "development");
        entitlements.WriteToFile(entitlementPath);

        // Copy the entitlement file to the xcode project
        var entitlementFileName = Path.GetFileName(entitlementPath);
        var unityTarget         = PBXProject.GetUnityTargetName();
        var relativeDestination = unityTarget + "/" + entitlementFileName;

        // Add the pbx configs to include the entitlements files on the project
        project.AddFile(relativeDestination, entitlementFileName);
        project.AddBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", relativeDestination);

        // Add push notifications as a capability on the target
        project.AddBuildProperty(targetGUID, "SystemCapabilities", "{com.apple.Push = {enabled = 1;};}");
        File.WriteAllText(projectPath, project.WriteToString());
    }
Esempio n. 26
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);
    }
Esempio n. 27
0
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        var separator = Path.DirectorySeparatorChar;

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

        project.ReadFromString(File.ReadAllText(projectPath));
        string targetName = PBXProject.GetUnityTargetName();
        string targetGUID = project.TargetGuidByName(targetName);

        // UserNotifications.framework is required by libOneSignal.a
        project.AddFrameworkToProject(targetGUID, "UserNotifications.framework", false);

         #if UNITY_2017_2_OR_NEWER && !UNITY_CLOUD_BUILD
        var platformsLocation         = "Assets" + separator + "OneSignal" + separator + "Platforms" + separator;
        var extensionTargetName       = "OneSignalNotificationServiceExtension";
        var pathToNotificationService = path + separator + extensionTargetName;

        var notificationServicePlistPath = pathToNotificationService + separator + "Info.plist";

        PlistDocument notificationServicePlist = new PlistDocument();

        //if this is a rebuild, we've already added the extension service, no need to run this script a second time
        if (File.Exists(notificationServicePlistPath))
        {
            // update version
            notificationServicePlist.ReadFromFile(platformsLocation + "iOS" + separator + "Info.plist");
            notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
            notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString());
            notificationServicePlist.WriteToFile(notificationServicePlistPath);
            return;
        }

        Directory.CreateDirectory(pathToNotificationService);

        notificationServicePlist.ReadFromFile(platformsLocation + "iOS" + separator + "Info.plist");
        notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
        notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString());

        var notificationServiceTarget = PBXProjectExtensions.AddAppExtension(project, targetGUID, extensionTargetName, PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + extensionTargetName, notificationServicePlistPath);

        var sourceDestination = extensionTargetName + "/NotificationService";

        project.AddFileToBuild(notificationServiceTarget, project.AddFile(sourceDestination + ".h", sourceDestination + ".h", PBXSourceTree.Source));
        project.AddFileToBuild(notificationServiceTarget, project.AddFile(sourceDestination + ".m", sourceDestination + ".m", PBXSourceTree.Source));

        var frameworks = new string[] { "NotificationCenter.framework", "UserNotifications.framework", "UIKit.framework", "SystemConfiguration.framework" };

        foreach (string framework in frameworks)
        {
            project.AddFrameworkToProject(notificationServiceTarget, framework, true);
        }

        //makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
        project.SetBuildProperty(notificationServiceTarget, "TARGETED_DEVICE_FAMILY", "1,2");
        project.SetBuildProperty(notificationServiceTarget, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");

        project.SetBuildProperty(notificationServiceTarget, "ARCHS", "$(ARCHS_STANDARD)");
        project.SetBuildProperty(notificationServiceTarget, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);

        notificationServicePlist.WriteToFile(notificationServicePlistPath);

        foreach (string type in new string[] { "m", "h" })
        {
            if (!File.Exists(path + separator + sourceDestination + "." + type))
            {
                FileUtil.CopyFileOrDirectory(platformsLocation + "iOS" + separator + "NotificationService." + type, path + separator + sourceDestination + "." + type);
            }
        }

        project.WriteToFile(projectPath);

        //add libOneSignal.a to the OneSignalNotificationServiceExtension target
        string contents = File.ReadAllText(projectPath);

        //this method only modifies the PBXProject string passed in (contents).
        //after this method finishes, we must write the contents string to disk
        InsertStaticFrameworkIntoTargetBuildPhaseFrameworks("libOneSignal", "CD84C25F20742FAB0035D524", notificationServiceTarget, ref contents, project);
        File.WriteAllText(projectPath, contents);
         #else
        project.WriteToFile(projectPath);

        string contents = File.ReadAllText(projectPath);
         #endif

        // enable the Notifications capability in the main app target
        project.ReadFromString(contents);
        var entitlementPath = path + separator + targetName + separator + targetName + ".entitlements";

        PlistDocument entitlements = new PlistDocument();

        if (File.Exists(entitlementPath))
        {
            entitlements.ReadFromFile(entitlementPath);
        }

         #if !UNITY_CLOUD_BUILD && ADD_APP_GROUP
        if (entitlements.root["aps-environment"] == null)
        {
            entitlements.root.SetString("aps-environment", "development");
        }

        if (entitlements.root["com.apple.security.application-groups"] == null)
        {
            var groups = entitlements.root.CreateArray("com.apple.security.application-groups");
            groups.AddString("group." + PlayerSettings.applicationIdentifier + ".onesignal");
        }
         #endif

        entitlements.WriteToFile(entitlementPath);

        // Copy the entitlement file to the xcode project
        var entitlementFileName = Path.GetFileName(entitlementPath);
        var unityTarget         = PBXProject.GetUnityTargetName();
        var relativeDestination = unityTarget + "/" + entitlementFileName;

        // Add the pbx configs to include the entitlements files on the project
        project.AddFile(relativeDestination, entitlementFileName);
        project.AddBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", relativeDestination);

        // Add push notifications as a capability on the target
        project.AddBuildProperty(targetGUID, "SystemCapabilities", "{com.apple.Push = {enabled = 1;};}");
        File.WriteAllText(projectPath, project.WriteToString());
    }
        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]", "")));
        }
Esempio n. 29
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
        }
    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);
    }