Exemple #1
0
        public static string AddWatchApp(this PBXProject proj, string mainTargetGuid, string watchExtensionTargetGuid, string name, string bundleId, string infoPlistPath)
        {
            string str1 = proj.AddTarget(name, ".app", "com.apple.product-type.application.watchapp2");
            string str2 = proj.nativeTargets[watchExtensionTargetGuid].name.Replace(" ", "_");

            foreach (string name1 in proj.BuildConfigNames())
            {
                string configGuid = proj.BuildConfigByName(str1, name1);
                if (name1.Contains("Debug"))
                {
                    PBXProjectExtensions.SetDefaultWatchAppDebugBuildFlags(proj, configGuid);
                }
                else
                {
                    PBXProjectExtensions.SetDefaultWatchAppReleaseBuildFlags(proj, configGuid);
                }
                proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
                proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath);
                proj.SetBuildPropertyForConfig(configGuid, "IBSC_MODULE", str2);
            }
            proj.AddResourcesBuildPhase(str1);
            string sectionGuid1 = proj.AddCopyFilesBuildPhase(str1, "Embed App Extensions", "", "13");

            proj.AddFileToBuildSection(str1, sectionGuid1, proj.GetTargetProductFileRef(watchExtensionTargetGuid));
            string sectionGuid2 = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed Watch Content", "$(CONTENTS_FOLDER_PATH)/Watch", "16");

            proj.AddFileToBuildSection(mainTargetGuid, sectionGuid2, proj.GetTargetProductFileRef(str1));
            proj.AddTargetDependency(str1, watchExtensionTargetGuid);
            proj.AddTargetDependency(mainTargetGuid, str1);
            return(str1);
        }
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

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

        var proj = new PBXProject();

        proj.ReadFromFile(projPath);
        var targetGUID = proj.GetUnityFrameworkTargetGuid();

        //set xcode proj properties
        proj.AddBuildProperty(targetGUID, "SWIFT_VERSION", "5.0");
//        proj.SetBuildProperty(targetGUID, "SWIFT_OBJC_BRIDGING_HEADER", "Libraries/Plugins/iOS/HandDetector/Native/HandDetector.h");
//        proj.SetBuildProperty(targetGUID, "SWIFT_OBJC_INTERFACE_HEADER_NAME","HandDetector-Swift.h");
        proj.SetBuildProperty(targetGUID, "SWIFT_OBJC_INTERFACE_HEADER_NAME", "Libraries/Plugins/iOS/HandDetector/Native/HandDetector.h");
        proj.SetBuildProperty(targetGUID, "COREML_CODEGEN_LANGUAGE", "Swift");


        //add handmodel to xcode proj build phase.
        var buildPhaseGUID = proj.AddSourcesBuildPhase(targetGUID);
        var handModelPath  = Application.dataPath + "/../CoreML/HandModel.mlmodel";
        var fileGUID       = proj.AddFile(handModelPath, "/HandModel.mlmodel");

        proj.AddFileToBuildSection(targetGUID, buildPhaseGUID, fileGUID);

        proj.WriteToFile(projPath);
    }
Exemple #3
0
        private static void CopyRawSettingsFile(string rootPath, PBXProject project, string target, CASInitSettings casSettings)
        {
            if (!casSettings)
            {
                return;
            }

            var resourcesBuildPhase = project.GetResourcesBuildPhaseByTarget(target);

            for (int i = 0; i < casSettings.managersCount; i++)
            {
                string managerId       = casSettings.GetManagerId(i);
                int    managerIdLength = managerId.Length;
                string suffixChar      = char.ToLower(managerId[managerIdLength - 1]).ToString();
                string fileName        = "cas_settings" + managerIdLength.ToString() + suffixChar + ".json";
                string pathInAssets    = CASEditorUtils.GetNativeSettingsPath(BuildTarget.iOS, managerId);
                if (File.Exists(pathInAssets))
                {
                    try
                    {
                        File.Copy(pathInAssets, Path.Combine(rootPath, fileName), true);
                        var fileGuid = project.AddFile(fileName, fileName, PBXSourceTree.Source);
                        project.AddFileToBuildSection(target, resourcesBuildPhase, fileGuid);
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(CASEditorUtils.logTag + "Copy Raw File To XCode Project failed: " + e.ToString());
                    }
                }
                else
                {
                    Debug.Log(CASEditorUtils.logTag + "Not found Raw file: " + pathInAssets);
                }
            }
        }
Exemple #4
0
    //添加 xcodeModel.frameworks 中指定的 framework shareSDK子平台的framework
    private static void AddXcodeModelFrameworks(MOBXCodeEditorModel xcodeModel, PBXProject xcodeProj, string xcodeTargetGuid, string xcodeTargetPath)
    {
        foreach (MOBPathModel pathModel in xcodeModel.frameworks)
        {
            if (pathModel.filePath.Contains(".framework") && !pathModel.filePath.Contains("MOBFoundation.framework"))
            {
                string frameworkPath = pathModel.filePath.Replace(pathModel.rootPath, "");


                string savePath  = xcodeTargetPath + frameworkPath;
                int    tempIndex = frameworkPath.LastIndexOf("\\");
                if (tempIndex == -1)
                {
                    tempIndex = frameworkPath.LastIndexOf("/");
                }
                string saveFrameworkPath = frameworkPath.Substring(0, tempIndex);
                //将 framework copy到指定目录
                DirectoryInfo frameworkInfo     = new DirectoryInfo(pathModel.filePath);
                DirectoryInfo saveFrameworkInfo = new DirectoryInfo(savePath);
                CopyAll(frameworkInfo, saveFrameworkInfo);
                //将 framework 加入 proj中
                xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddFrameworksBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(frameworkPath.Substring(1), "MOB" + frameworkPath, PBXSourceTree.Absolute));
                //将 build setting 设置
                xcodeProj.AddBuildProperty(xcodeTargetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)" + saveFrameworkPath.Replace("\\", "/"));
            }
            else
            {
                Debug.LogWarning(pathModel.filePath + " no framework");
            }
        }
    }
Exemple #5
0
    //添加 bundle
    private static void AddBundle(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        SearchOption searchOption;

        if (secondFilePath.Contains("/ShareSDK/") || secondFilePath.Contains("\\ShareSDK\\") || secondFilePath.Contains("/ShareSDK\\")) //shareSDK
        {
            searchOption = SearchOption.TopDirectoryOnly;
        }
        else
        {
            searchOption = SearchOption.AllDirectories;
        }
        string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.bundle", searchOption);
        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            //			Debug.Log("lastFilePath" + lastFilePath);
            string bundlePath = lastFilePath.Replace(pathModel.rootPath, "");
            //			Debug.Log("bundlePath" + bundlePath);
            string savePath = xcodeTargetPath + bundlePath;
            //将 framework copy到指定目录
            DirectoryInfo bundleInfo     = new DirectoryInfo(lastFilePath);
            DirectoryInfo saveBundleInfo = new DirectoryInfo(savePath);
            CopyAll(bundleInfo, saveBundleInfo);
            //将 framework 加入 proj中
            xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddResourcesBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(bundlePath.Substring(1), "MOB" + bundlePath, PBXSourceTree.Absolute));
        }
    }
Exemple #6
0
        public static string AddStickerExtension(
            this PBXProject proj,
            string mainTargetGuid,
            string name,
            string bundleId,
            string infoPlistPath)
        {
            string ext = ".appex";
            string str = proj.AddTarget(name, ext, "com.apple.product-type.app-extension.messages-sticker-pack");

            foreach (string buildConfigName in proj.BuildConfigNames())
            {
                string configGuid = proj.BuildConfigByName(str, buildConfigName);
                if (buildConfigName.Contains("Debug"))
                {
                    proj.SetDefaultAppExtensionDebugBuildFlags(configGuid);
                }
                else
                {
                    proj.SetDefaultAppExtensionReleaseBuildFlags(configGuid);
                }
                proj.SetBuildPropertyForConfig(configGuid, "INFOPLIST_FILE", infoPlistPath);
                proj.SetBuildPropertyForConfig(configGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
            }
            proj.AddSourcesBuildPhase(str);
            proj.AddResourcesBuildPhase(str);
            proj.AddFrameworksBuildPhase(str);
            string sectionGuid = proj.AddCopyFilesBuildPhase(mainTargetGuid, "Embed App Extensions", "", "13");

            proj.AddFileToBuildSection(mainTargetGuid, sectionGuid, proj.GetTargetProductFileRef(str));
            proj.AddTargetDependency(mainTargetGuid, str);
            return(str);
        }
    private static void AddFileToProject(PBXProject project, string filepath, string filename, string extensionDisplayName, string extensionGuid, string buildPhase)
    {
        string xcodePath = extensionDisplayName + "/" + filename;
        string fileGuid  = project.AddFile(filepath, xcodePath);

        project.AddFileToBuildSection(extensionGuid, buildPhase, fileGuid);
    }
Exemple #8
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        UnityEngine.Debug.Log("OnPostprocessBuild");

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

        proj.ReadFromString(File.ReadAllText(projPath));
        string targetGuid = proj.GetUnityMainTargetGuid();

#if UNITY_2019_3_OR_NEWER
        pcm = new ProjectCapabilityManager(projPath, "ntsdk.entitlements", null, proj.GetUnityMainTargetGuid());
#else
        pcm = new ProjectCapabilityManager(projPath, "ntsdk.entitlements", PBXProject.GetUnityTargetName());
#endif

#if UNITY_2019_3_OR_NEWER
        string target = proj.GetUnityMainTargetGuid();
#else
        string target = proj.TargetGuidByName("Unity-iPhone");
#endif

        string[] linkerFlagsToAdd =
        {
            // "-lz" , AppGuard 용 . NTSDK 에서 이미 하므로 생략함.
            "-lstdc++"                     // AppGuard 용
        };

        proj.UpdateBuildProperty(target, "OTHER_LDFLAGS", linkerFlagsToAdd, null);
        pcm.WriteToFile();

        string finalFolderName = "iosConfig_Line.IcarusEternal.KR.iOS";
        string configDir       = Path.GetDirectoryName(Application.dataPath) + $@"/AppGuard_iOS/{finalFolderName}";

        //////////////////

        proj.ReadFromString(File.ReadAllText(projPath));
        List <string> resources = new List <string>();

        CopyAndReplaceDirectory(configDir, Path.Combine(path, finalFolderName));
        GetDirFileList(configDir, ref resources, finalFolderName);

        foreach (string resource in resources)
        {
            Debug.Log("CopyTo 'Copy Bundle Resource' : " + resource);
            string resourcesBuildPhase = proj.GetResourcesBuildPhaseByTarget(targetGuid);
            string resourcesFilesGuid  = proj.AddFile(resource, resource, PBXSourceTree.Source);
            proj.AddFileToBuildSection(targetGuid, resourcesBuildPhase, resourcesFilesGuid);
        }

        File.WriteAllText(projPath, proj.WriteToString());
    }
Exemple #9
0
    //添加其他资源
    private static void AddOtherFile(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj, Hashtable fileFlags)
    {
        string[] secondDirectories = Directory.GetFiles(secondFilePath, "*", SearchOption.AllDirectories);
        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            //			Debug.LogWarning("lastFilePath:" + lastFilePath);
            if (!lastFilePath.Contains(".framework") &&
                !lastFilePath.Contains(".a") &&
                !lastFilePath.Contains(".h") &&
                !lastFilePath.Contains(".bundle") &&
                !lastFilePath.Contains(".DS_Store") &&
                !lastFilePath.Contains(".meta"))
            {
                string otherFilePath = lastFilePath.Replace(pathModel.rootPath, "");


                int index         = otherFilePath.LastIndexOf("\\");
                int fileNameIndex = 2;
                if (index == -1)
                {
                    fileNameIndex = 1;
                    index         = otherFilePath.LastIndexOf("/");
                }
                //项目目录
                string saveOtherFilePath = otherFilePath.Substring(0, index);
                string fileName          = otherFilePath.Substring(index + fileNameIndex);
                //存放的本地目录
                string saveDirectory = xcodeTargetPath + saveOtherFilePath;
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }
                //将其他文件拷贝到指定目录
                FileInfo fileInfo = new FileInfo(lastFilePath);
                string   savePath = xcodeTargetPath + otherFilePath;
                fileInfo.CopyTo(savePath, true);
                //将.a 加入 proj中

                if (fileFlags.ContainsKey(fileName))
                {
                    string flag = (string)fileFlags[fileName];
                    //Debug.Log(flag);
                    xcodeProj.AddFileToBuildWithFlags(xcodeTargetGuid, xcodeProj.AddFile(otherFilePath.Substring(1), "MOB" + otherFilePath, PBXSourceTree.Absolute), flag);
                }
                else
                {
                    xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddFrameworksBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(otherFilePath.Substring(1), "MOB" + otherFilePath, PBXSourceTree.Absolute));
                }
            }
        }
    }
        public static void IosXcodeFix(string path)
        {
            PBXProject project  = new PBXProject();
            string     projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

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

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

            Debug.Log("Setting linker flag ENABLE_BITCODE to NO");
            project.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

            //get the framework file id (check for possible different locations)
            string fileId = null;

            //universal (new)
            if (fileId == null)
            {
                fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/universal/webrtccsharpwrap.framework");
            }

            //armv7 only
            if (fileId == null)
            {
                fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/armv7/webrtccsharpwrap.framework");
            }
            //arm64 only
            if (fileId == null)
            {
                fileId = project.FindFileGuidByProjectPath("Frameworks/WebRtcVideoChat/Plugins/ios/arm64/webrtccsharpwrap.framework");
            }
            //manual placement
            if (fileId == null)
            {
                fileId = project.FindFileGuidByProjectPath("Frameworks/webrtccsharpwrap.framework");
            }

            Debug.Log("Adding build phase CopyFrameworks to copy the framework to the app Frameworks directory");

#if UNITY_2017_2_OR_NEWER
            project.AddFileToEmbedFrameworks(target, fileId);
#else
            string copyFilePhase = project.AddCopyFilesBuildPhase(target, "CopyFrameworks", "", "10");
            project.AddFileToBuildSection(target, copyFilePhase, fileId);
            //Couldn't figure out how to set that flag yet.
            Debug.LogWarning("Code Sign On Copy flag must be set manually via Xcode for webrtccsharpwrap.framework:" +
                             "Project settings -> Build phases -> Copy Frameworks -> set the flag Code Sign On Copy");
#endif


            //make sure the Framework is expected in the Frameworks path. Without that ios won't find the framework
            project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            File.WriteAllText(projPath, project.WriteToString());
        }
Exemple #11
0
        private static void AddEmbeddedFrameworks(PBXProject proj, string targetGuid)
        {
            foreach (var framework in ISD_Settings.Instance.EmbededFrameworks)
            {
                var fileGuid   = proj.AddFile(framework.AbsoluteFilePath, "Frameworks/" + framework.FileName, PBXSourceTree.Source);
                var embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10");
                proj.AddFileToBuildSection(targetGuid, embedPhase, fileGuid);
#if UNITY_2017_4_OR_NEWER
                proj.AddFileToEmbedFrameworks(targetGuid, fileGuid);
#endif
                proj.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            }
        }
Exemple #12
0
        /// <summary>
        /// Add the swift source file required by the notification extension
        /// </summary>
        private void ExtensionAddSourceFiles(string extensionGuid)
        {
            var buildPhaseID     = _project.AddSourcesBuildPhase(extensionGuid);
            var sourcePath       = Path.Combine(PluginFilesPath, ServiceExtensionFilename);
            var destPathRelative = Path.Combine(ServiceExtensionTargetName, ServiceExtensionFilename);

            var destPath = Path.Combine(_outputPath, destPathRelative);

            if (!File.Exists(destPath))
            {
                FileUtil.CopyFileOrDirectory(sourcePath.Replace("\\", "/"), destPath.Replace("\\", "/"));
            }

            var sourceFileGuid = _project.AddFile(destPathRelative, destPathRelative);

            _project.AddFileToBuildSection(extensionGuid, buildPhaseID, sourceFileGuid);
        }
Exemple #13
0
    //添加 .a文件
    private static void AddStaticLibrary(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        //		SearchOption searchOption;
        //		if (secondFilePath.Contains ("/ShareSDK/")) //shareSDK
        //		{
        //			searchOption = SearchOption.TopDirectoryOnly;
        //		}
        //		else
        //		{
        //			searchOption = SearchOption.AllDirectories;
        //		}
        string[] secondDirectories = Directory.GetFiles(secondFilePath, "*.a", SearchOption.AllDirectories);
        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            string staticLibraryPath = lastFilePath.Replace(pathModel.rootPath, "");


            int index = staticLibraryPath.LastIndexOf("\\");
            if (index == -1)
            {
                index = staticLibraryPath.LastIndexOf("/");
            }

            //项目目录
            string saveStaticLibraryPath = staticLibraryPath.Substring(0, index);
            //存放的本地目录
            string saveDirectory = xcodeTargetPath + saveStaticLibraryPath;
            if (!Directory.Exists(saveDirectory))
            {
                Directory.CreateDirectory(saveDirectory);
            }
            //将.a copy到指定目录
            FileInfo fileInfo = new FileInfo(lastFilePath);
            string   savePath = xcodeTargetPath + staticLibraryPath;
            fileInfo.CopyTo(savePath, true);
            //将.a 加入 proj中
            xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddFrameworksBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(staticLibraryPath.Substring(1), "MOB" + staticLibraryPath, PBXSourceTree.Absolute));
            //将 build setting 设置
            xcodeProj.AddBuildProperty(xcodeTargetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)" + saveStaticLibraryPath.Replace("\\", "/"));
        }
    }
Exemple #14
0
        /// <inheritdoc />
        /// <remarks>
        /// Postprocessing of generated Xcode project.
        /// Collects all user frameworks and adds them as embedded to Xcode project.
        /// </remarks>
        public void OnPostprocessBuild(BuildTarget target, string path)
        {
            if (target != BuildTarget.iOS)
            {
                return;
            }

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

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

            string targetName = PBXProject.GetUnityTargetName();
            string targetGuid = xproject.TargetGuidByName(targetName);

            string embedPhaseGuid = xproject.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10");

            xproject.AddBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

            foreach (string framework in FindFrameworks())
            {
                Debug.LogFormat("Adding framework `{0}`", framework);
                string frameworkPathInProject = "Frameworks/" + framework;

                var fileGuid = xproject.FindFileGuidByProjectPath(frameworkPathInProject);
                if (fileGuid == null)
                {
                    Debug.LogFormat("Framework `{0}` NOT FOUND in generated xCode project.", frameworkPathInProject);
                    continue;
                }

                xproject.AddFileToBuildSection(targetGuid, embedPhaseGuid, fileGuid);
            }

            // Hack to Enable Code Sign on Copy attribute for embedded frameworks
            // Unity 2017.2.0f3 does not provide necessary API so replace in text required.
            string content = System.Text.RegularExpressions.Regex.Replace(
                xproject.WriteToString(),
                @"(.*\.framework in Embed Frameworks \*/ = .*) \};",
                @"$1 settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };"
                );

            File.WriteAllText(projectPath, content);
        }
Exemple #15
0
    private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            Debug.Log("Running Zapic Xcode Scripts");

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

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

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

            Debug.Log("Zapic: Including Swift Libraries");
            proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");

            Debug.Log("Zapic: Setting search path");
            proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

            //Find the existing framework id
            var frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/Zapic.framework");

            //Try lowercase
            if (string.IsNullOrEmpty(frameworkId))
            {
                frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/zapic.framework");
            }

            if (string.IsNullOrEmpty(frameworkId))
            {
                Debug.LogError("Zapic: Unable to find iOS framework");
            }

            Debug.Log("Zapic:Adding embedded frameworks");
            string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10");

            proj.AddFileToBuildSection(targetGuid, embedPhase, frameworkId);

            // Apply settings
            File.WriteAllText(projPath, proj.WriteToString());

            Debug.Log("Zapic:Done configuring xcode settings");
        }
    }
Exemple #16
0
        private static void AddEmbeddedFrameworks(PBXProject project, string targetGuid)
        {
            string frameworkRelativePath = Path.Combine(InstabugPluginPath, InstabugFrameworkName);
            string frameworkAbsolutePath = Path.Combine(Application.dataPath, frameworkRelativePath);

            string frameworkGuid = project.AddFile(frameworkAbsolutePath, "Frameworks/" + InstabugFrameworkName, PBXSourceTree.Source);

            project.AddFileToBuild(targetGuid, frameworkGuid);

            string embedPhaseGuid = project.AddCopyFilesBuildPhase(targetGuid, BuildPhaseName, "", "10" /* Frameworks */);

            project.AddFileToBuildSection(targetGuid, embedPhaseGuid, frameworkGuid);

            // HACK: Use the correct path in the project. Not sure why it's using the absolute path.
            string projectContents = project.WriteToString();

            projectContents = projectContents.Replace(frameworkAbsolutePath, "Frameworks/" + frameworkRelativePath);
            project.ReadFromString(projectContents);
        }
Exemple #17
0
    //添加 .h文件
    private static void AddHeader(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj)
    {
        string[]  secondDirectories = Directory.GetFiles(secondFilePath, "*.h", SearchOption.AllDirectories);
        ArrayList savePathArray     = new ArrayList();

        foreach (string lastFilePath in secondDirectories)
        {
            if ((secondFilePath.EndsWith("SDK/ShareSDK") || secondFilePath.EndsWith("SDK\\ShareSDK")) && (lastFilePath.Contains("Support/PlatformSDK") || lastFilePath.Contains("Support\\PlatformSDK")))
            {
                continue;
            }
            if (!lastFilePath.Contains(".framework"))
            {
                string headerPath = lastFilePath.Replace(pathModel.rootPath, "");

                int index = headerPath.LastIndexOf("\\");
                if (index == -1)
                {
                    index = headerPath.LastIndexOf("/");
                }
                //项目目录
                string saveHeaderPath = headerPath.Substring(0, index);
                //存放的本地目录
                string saveDirectory = xcodeTargetPath + saveHeaderPath;
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }
                //将.h copy到指定目录
                FileInfo fileInfo = new FileInfo(lastFilePath);
                string   savePath = xcodeTargetPath + headerPath;
                fileInfo.CopyTo(savePath, true);
                //将.h 加入 proj中
                xcodeProj.AddFileToBuildSection(xcodeTargetGuid, xcodeProj.AddResourcesBuildPhase(xcodeTargetGuid), xcodeProj.AddFile(headerPath.Substring(1), "MOB" + headerPath, PBXSourceTree.Absolute));
                if (!savePathArray.Contains(saveHeaderPath))
                {
                    savePathArray.Add(saveHeaderPath);
                    //将 build setting 设置
                    xcodeProj.AddBuildProperty(xcodeTargetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)" + saveHeaderPath.Replace("\\", "/"));
                }
            }
        }
    }
Exemple #18
0
    // Copies NotificationService.m and .h files into the OneSignalNotificationServiceExtension folder adds them to the Xcode target
    private static void AddNotificationServiceSourceFilesToTarget(PBXProject project, string extensionGUID, string path)
    {
        var buildPhaseID = project.AddSourcesBuildPhase(extensionGUID);

        foreach (var type in new string[] { "m", "h" })
        {
            var nativeFileName = NOTIFICATION_SERVICE_EXTENSION_OBJECTIVEC_FILENAME + "." + type;
            var sourcePath     = OS_PLATFORM_LOCATION + "iOS" + DIR_CHAR + nativeFileName;
            var nativeFileRelativeDestination = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME + "/" + nativeFileName;

            var destPath = path + DIR_CHAR + nativeFileRelativeDestination;
            if (!File.Exists(destPath))
            {
                FileUtil.CopyFileOrDirectory(sourcePath, destPath);
            }

            var sourceFileGUID = project.AddFile(nativeFileRelativeDestination, nativeFileRelativeDestination, PBXSourceTree.Source);
            project.AddFileToBuildSection(extensionGUID, buildPhaseID, sourceFileGUID);
        }
    }
Exemple #19
0
    // Copies NotificationService.m and .h files into the OneSignalNotificationServiceExtension folder adds them to the Xcode target
    private static void AddNotificationServiceSourceFilesToTarget(PBXProject project, string extensionGUID,
                                                                  string projectPath)
    {
        var buildPhaseID = project.AddSourcesBuildPhase(extensionGUID);

        foreach (var type in new string[] { "m", "h" })
        {
            var fileName   = $"{NotificationServiceExtensionObjCFilename}.{type}";
            var sourcePath = Path.Combine(PluginFilesPath, fileName);

            var destPathRelative = Path.Combine(NotificationServiceExtensionTargetName, fileName);
            var destPath         = Path.Combine(projectPath, destPathRelative);
            if (!File.Exists(destPath))
            {
                FileUtil.CopyFileOrDirectory(sourcePath.Replace("\\", "/"), destPath.Replace("\\", "/"));
            }

            var sourceFileGUID = project.AddFile(destPathRelative, destPathRelative);
            project.AddFileToBuildSection(extensionGUID, buildPhaseID, sourceFileGUID);
        }
    }
    private static void AddEmbeddedBinary(string projectPath)
    {
        const string buildPhaseName = "Embed Libraries";
        const string dylibName      = "libOVRLipSync.dylib";

        var project = new PBXProject();

        project.ReadFromFile(projectPath);

        // Don't add the same library twice
        if (project.FindFileGuidByProjectPath(dylibName) != null)
        {
            return;
        }

        var targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName());

        // Limit the target to ARM64
        project.SetBuildProperty(targetGUID, "ARCHS", "arm64");

        // Add dylib to the project
        var dylibGUID = project.AddFile(
            Path.Combine(Application.dataPath, "Oculus/LipSync/Plugins/iOS/" + dylibName),
            dylibName);
        // Copy it to the same folder as executable
        var embedPhaseGuid = project.AddCopyFilesBuildPhase(targetGUID, buildPhaseName, "", "6");

        project.AddFileToBuildSection(targetGUID, embedPhaseGuid, dylibGUID);
        var content = project.WriteToString();

        // Add CodeSignOnCopy attribute ot the library using an ugly regex
        content = Regex.Replace(content,
                                "(?<=" + buildPhaseName + ")(?:.*)(\\/\\* " + Regex.Escape(dylibName) + " \\*\\/)(?=; };)",
                                m => m.Value.Replace(
                                    "/* " + dylibName + " */",
                                    "/* " + dylibName + " */; settings = {ATTRIBUTES = (CodeSignOnCopy, );}"
                                    )
                                );
        File.WriteAllText(projectPath, content);
    }
Exemple #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);
            }
        }
Exemple #22
0
    //添加 Framework
    private static void AddFramework(string secondFilePath, string xcodeTargetPath, string xcodeTargetGuid, string xcodeFrameworkTargetGuid, MOBPathModel pathModel, PBXProject xcodeProj, ref bool hasMobFramework, MOBXCodeEditorModel editModel)
    {
        SearchOption searchOption;

        if (secondFilePath.Contains("/ShareSDK/") || secondFilePath.Contains("\\ShareSDK\\") || secondFilePath.Contains("/ShareSDK\\")) //shareSDK
        {
            searchOption = SearchOption.TopDirectoryOnly;
        }
        else
        {
            searchOption = SearchOption.AllDirectories;
        }
        string[] secondDirectories = Directory.GetDirectories(secondFilePath, "*.framework", searchOption);
        foreach (string lastFilePath in secondDirectories)
        {
            //			Debug.Log("lastFilePath" + lastFilePath);

            int index         = lastFilePath.LastIndexOf("\\");
            int fileNameIndex = 2;
            if (index == -1)
            {
                fileNameIndex = 1;
                index         = lastFilePath.LastIndexOf("/");
            }
            //framework 名称
            string frameworkName = lastFilePath.Substring(index + fileNameIndex);
            //			Debug.Log("frameworkName" + frameworkName);
            bool isMOBFoundation = (frameworkName == "MOBFoundation.framework");
            if (!isMOBFoundation || (isMOBFoundation && !hasMobFramework))
            {
                if (isMOBFoundation && !hasMobFramework)
                {
                    //					Debug.Log("isMOBFoundation " + lastFilePath);
                    hasMobFramework = true;
                }
                string frameworkPath = lastFilePath.Replace(pathModel.rootPath, "");
                //			Debug.Log("frameworkPath" + frameworkPath);
                string savePath  = xcodeTargetPath + frameworkPath;
                int    tempIndex = frameworkPath.LastIndexOf("\\");
                if (tempIndex == -1)
                {
                    tempIndex = frameworkPath.LastIndexOf("/");
                }

                string saveFrameworkPath = frameworkPath.Substring(0, tempIndex);
                string targetGuid        = xcodeFrameworkTargetGuid;
                //将 framework copy到指定目录AddURLSchemes
                DirectoryInfo frameworkInfo     = new DirectoryInfo(lastFilePath);
                DirectoryInfo saveFrameworkInfo = new DirectoryInfo(savePath);
                CopyAll(frameworkInfo, saveFrameworkInfo);
                //将 framework 加入 proj中



                if (frameworkName == "ShareSDKLink.framework" && !editModel.isOpenRestoreScene)
                {
                    continue;
                }

                string fileGuid = (string)xcodeProj.AddFile(frameworkPath.Substring(1), "MOB" + frameworkPath, PBXSourceTree.Absolute);


                string[] dynamicframework = { "OasisSDK.framework", "SCSDKCreativeKit.framework", "SCSDKLoginKit.framework", "SCSDKCoreKit.framework" };
                int      dynamicIndex     = Array.IndexOf(dynamicframework, frameworkName);

                if (dynamicIndex >= 0)
                {
                    targetGuid = xcodeTargetGuid;
                    xcodeProj.AddFileToBuildSection(targetGuid, xcodeProj.AddFrameworksBuildPhase(targetGuid), fileGuid);
#if UNITY_2019_3_OR_NEWER
                    xcodeProj.AddFileToEmbedFrameworks(targetGuid, fileGuid, targetGuid);
#endif
                }
                else
                {
                    xcodeProj.AddFileToBuildSection(targetGuid, xcodeProj.AddFrameworksBuildPhase(targetGuid), fileGuid);
                }

                //将 build setting 设置
                xcodeProj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)" + saveFrameworkPath.Replace("\\", "/"));
            }
        }
    }