/// <summary>
        /// Writes properties to the XCode framework
        /// </summary>
        /// <param name="pbxProject"></param>
        /// <param name="targetGUID"></param>
        /// <param name="pbxProjectPath"></param>
        /// <param name="pluginPath"></param>
        private static void WritePropertiesToFramework(PBXProject pbxProject, string targetGUID, string pbxProjectPath, string pluginPath, bool forceAlwaysEmbedSwiftStandardLibraries)
        {
            // Full Path to copy from
            Debug.Log("[MMNVBuildPostProcessor] Adding properties to XCode framework");
            Debug.Log("[MMNVBuildPostProcessor] Plugin path : " + pluginPath);

            pbxProject.AddFrameworkToProject(targetGUID, "CoreHaptics.framework", false);
            pbxProject.SetBuildProperty(targetGUID, "SWIFT_VERSION", "5.1");
            pbxProject.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO");

            if (forceAlwaysEmbedSwiftStandardLibraries)
            {
                pbxProject.SetBuildProperty(targetGUID, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES");
                pbxProject.SetBuildProperty(targetGUID, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
            }
            pbxProject.SetBuildProperty(targetGUID, "CLANG_ENABLE_MODULES", "YES");
            pbxProject.SetBuildProperty(targetGUID, "SWIFT_INCLUDE_PATHS", pluginPath);
            pbxProject.SetBuildProperty(targetGUID, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            // if you're using the FB SDK and are having issues with your build pipeline, you may want to uncomment these lines (part 1/2) :
            // proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-lxml2");
            // proj.AddFrameworkToProject(targetGUID, "libxml2.dylib", true);

            // we add a module reference to the pbx project
            Debug.Log("[MMNVBuildPostProcessor] Add module reference : " + _moduleFileUnityPath + " -> " + _moduleFileXCodePath);
            string file_guid = pbxProject.AddFile(_moduleFileXCodePath,
                                                  _moduleFileXCodePath,
                                                  PBXSourceTree.Source);

            Debug.Log("[MMNVBuildPostProcessor] Module GUID : " + file_guid);
            pbxProject.AddFileToBuild(targetGUID, file_guid);
            File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());

            // we copy the module file to the project
            string projFileDir    = System.IO.Path.GetDirectoryName(pbxProjectPath);
            string moduleFilePath = Application.dataPath + SEPARATOR + ".." + SEPARATOR + _moduleFileUnityPath;
            string destination    = projFileDir + SEPARATOR + ".." + SEPARATOR + pluginPath + _moduleFileName;

            if (!Directory.Exists(Path.GetDirectoryName(destination)))
            {
                Debug.Log("[MMNVBuildPostProcessor] Creating directory " + destination);
                Directory.CreateDirectory(Path.GetDirectoryName(destination));
            }
            Debug.Log("[MMNVBuildPostProcessor] Copy module file to project : " + moduleFilePath + " -> " + destination);
            System.IO.File.Copy(moduleFilePath, destination, true);

            Debug.Log("[MMNVBuildPostProcessor] Copy module file to project : " + moduleFilePath + " -> " + destination);
            string headerGUID = pbxProject.AddFile(_headerFileUnityPath,
                                                   _headerFileXCodePath,
                                                   PBXSourceTree.Source);

            pbxProject.AddFileToBuild(targetGUID, headerGUID);
            pbxProject.AddPublicHeaderToBuild(targetGUID, headerGUID);

            Debug.Log("[MMNVBuildPostProcessor] Framework complete");
        }
    public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
    {
        Debug.Log("OnPostProcessBuild: " + buildTarget);

        if (buildTarget == BuildTarget.iOS)
        {
            var projectPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

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

            var unityFrameworkGuid = project.GetUnityFrameworkTargetGuid();

            // Modulemap
            project.AddBuildProperty(unityFrameworkGuid, "DEFINES_MODULE", "YES");

            var moduleFile = buildPath + "/UnityFramework/UnityFramework.modulemap";
            if (!File.Exists(moduleFile))
            {
                FileUtil.CopyFileOrDirectory("Assets/Plugins/iOS/SwiftToUnity/Source/UnityFramework.modulemap", moduleFile);
                project.AddFile(moduleFile, "UnityFramework/UnityFramework.modulemap");
                project.AddBuildProperty(unityFrameworkGuid, "MODULEMAP_FILE", "$(SRCROOT)/UnityFramework/UnityFramework.modulemap");
            }

            // Headers
            string unityInterfaceGuid = project.FindFileGuidByProjectPath("Classes/Unity/UnityInterface.h");
            project.AddPublicHeaderToBuild(unityFrameworkGuid, unityInterfaceGuid);

            string unityForwardDeclsGuid = project.FindFileGuidByProjectPath("Classes/Unity/UnityForwardDecls.h");
            project.AddPublicHeaderToBuild(unityFrameworkGuid, unityForwardDeclsGuid);

            string unityRenderingGuid = project.FindFileGuidByProjectPath("Classes/Unity/UnityRendering.h");
            project.AddPublicHeaderToBuild(unityFrameworkGuid, unityRenderingGuid);

            string unitySharedDeclsGuid = project.FindFileGuidByProjectPath("Classes/Unity/UnitySharedDecls.h");
            project.AddPublicHeaderToBuild(unityFrameworkGuid, unitySharedDeclsGuid);

            // Save project
            project.WriteToFile(projectPath);
        }

        Debug.Log("OnPostProcessBuild: Complete");
    }
Пример #3
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        switch (buildTarget)
        {
        case BuildTarget.iOS:
        {
            var xcodePath = path + "/Unity-Iphone.xcodeproj/project.pbxproj";
            var proj      = new PBXProject();
            proj.ReadFromFile(xcodePath);

            var targetGuid = proj.GetUnityFrameworkTargetGuid();

            proj.SetBuildProperty(targetGuid, "COREML_CODEGEN_LANGUAGE", "Swift");
            proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0");
            proj.AddBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
            proj.SetBuildProperty(targetGuid, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES");
            proj.SetBuildProperty(
                targetGuid,
                "FRAMERWORK_SEARCH_PATHS",
                "$(inherited) $(PROJECT_DIR) $(PROJECT_DIR)/Frameworks"
                );
            proj.SetBuildProperty(targetGuid, "DEFINES_MODULE", "YES");

            // Adds the data folder to the Unity target.
            // This is basically the manual step we were doing before!
            var dataGUID = proj.FindFileGuidByProjectPath("Data");
            proj.AddFileToBuild(targetGuid, dataGUID);

            /**
             * Module Map
             */

            var moduleFileName = "UnityFramework/UnityFramework.modulemap";
            var moduleFile     = path + "/" + moduleFileName;
            if (!File.Exists(moduleFile))
            {
                FileUtil.CopyFileOrDirectory("Assets/Plugins/iOS/" + AutoBuilder.MODULE_MAP, moduleFile);
                proj.AddFile(moduleFile, moduleFileName);
                proj.AddBuildProperty(targetGuid, "MODULEMAP_FILE", "$(SRCROOT)/" + moduleFileName);
            }

            /**
             * Headers
             */

            // Sets the visiblity of our native API header.
            // This is basically the manual step we were doing before!
            var unityInterfaceGuid = proj.FindFileGuidByProjectPath("Libraries/Plugins/iOS/" + AutoBuilder.INTERFACE_HEADER);
            proj.AddPublicHeaderToBuild(targetGuid, unityInterfaceGuid);

            proj.WriteToFile(xcodePath);
            break;
        }
        }
    }