コード例 #1
0
    public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target != BuildTarget.iOS)
        {
            Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
            return;
        }

        //得到xcode工程的路径
        string path = Path.GetFullPath(pathToBuiltProject);

        XCFileChecker.InitModeDict();
        // Create a new project object from build target
        XCProject project = new XCProject(pathToBuiltProject);

        // Find and run through all projmods files to patch the project.
        // Please pay attention that ALL projmods files in your project folder will be excuted!
        string applicationPath = Application.dataPath.Replace("/Assets", "");

        string[] files = Directory.GetFiles(applicationPath + "/Mods", "*.projmods", SearchOption.TopDirectoryOnly);

        XCFileChecker.SortMods(ref files);

        string selectProjmods = EditorPrefs.GetString("selectProjmods");

        Debug.Log("selectProjmods = " + selectProjmods);

        foreach (string file in files)
        {
            if (string.IsNullOrEmpty(selectProjmods))
            {
                UnityEngine.Debug.Log("ProjMod File: " + file);
                project.ApplyMod(file);
            }
            else
            {
                if (XCFileChecker.CheckApplyMod(file))
                {
                    UnityEngine.Debug.Log("ProjMod File: " + file);
                    project.ApplyMod(file);
                }
            }
        }

        //modify for xcode7
        project.overwriteBuildSetting("ENABLE_BITCODE", "NO", "all");


        XCFileChecker.EditCode(path);

//		if (selectProjmods == "kuaiyongSDK.projmods")
//		{
//			//编辑代码文件
//			EditorCodeForKuaiyong(path);
//		}

        // Finally save the xcode project
        project.Save();
    }
コード例 #2
0
        public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false,
                                     string compilerFlags             = null)
        {
            //Debug.Log("AddFile " + filePath + ", " + parent + ", " + tree + ", " + (createBuildFiles? "TRUE":"FALSE") + ", " + (weak? "TRUE":"FALSE") );

            if (!XCFileChecker.CheckAddFile(filePath))
            {
                return(null);
            }

            PBXDictionary results = new PBXDictionary();

            if (filePath == null)
            {
                Debug.LogError("AddFile called with null filePath");
                return(results);
            }

            string absPath = string.Empty;

            if (Path.IsPathRooted(filePath))
            {
                Debug.Log("Path is Rooted");
                absPath = filePath;
            }
            else if (tree.CompareTo("SDKROOT") != 0)
            {
                absPath = Path.Combine(Application.dataPath, filePath);
            }

            if (!(File.Exists(absPath) || Directory.Exists(absPath)) && tree.CompareTo("SDKROOT") != 0)
            {
                Debug.Log("Missing file: " + filePath);
                return(results);
            }
            else if (tree.CompareTo("SOURCE_ROOT") == 0)
            {
                Debug.Log("Source Root File");
                System.Uri fileURI = new System.Uri(absPath);
                System.Uri rootURI = new System.Uri((projectRootPath + "/."));
                filePath = rootURI.MakeRelativeUri(fileURI).ToString();
            }
            else if (tree.CompareTo("GROUP") == 0)
            {
                Debug.Log("Group File");
                filePath = System.IO.Path.GetFileName(filePath);
            }

            if (parent == null)
            {
                parent = _rootGroup;
            }

            //Check if there is already a file
            PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));

            if (fileReference != null)
            {
                Debug.Log("File already exists: " + filePath);                 //not a warning, because this is normal for most builds!
                return(null);
            }

            fileReference = new PBXFileReference(filePath, compilerFlags, (TreeEnum)System.Enum.Parse(typeof(TreeEnum), tree));
            parent.AddChild(fileReference);
            fileReferences.Add(fileReference);
            results.Add(fileReference.guid, fileReference);

            //Create a build file for reference
            if (!string.IsNullOrEmpty(fileReference.buildPhase) && createBuildFiles)
            {
                switch (fileReference.buildPhase)
                {
                case "PBXFrameworksBuildPhase":
                    foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases)
                    {
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    if (!string.IsNullOrEmpty(absPath) && (tree.CompareTo("SOURCE_ROOT") == 0))
                    {
                        string libraryPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath));
                        if (File.Exists(absPath))
                        {
                            this.AddLibrarySearchPaths(new PBXList(libraryPath));
                        }
                        else
                        {
                            this.AddFrameworkSearchPaths(new PBXList(libraryPath));
                        }
                    }
                    break;

                case "PBXResourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases)
                    {
                        Debug.Log("Adding Resources Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXShellScriptBuildPhase":
                    foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases)
                    {
                        Debug.Log("Adding Script Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXSourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases)
                    {
                        Debug.Log("Adding Source Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXCopyFilesBuildPhase":
                    foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                    {
                        Debug.Log("Adding Copy Files Build Phase");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case null:
                    Debug.LogWarning("File Not Supported: " + filePath);
                    break;

                default:
                    Debug.LogWarning("File Not Supported.");
                    return(null);
                }
            }
            return(results);
        }