Esempio n. 1
0
    /// <summary>
    /// 用unity自带的api修改xcode设置
    /// </summary>
    /// <param name="target"></param>
    /// <param name="pathToBuiltProject"></param>
    private static void EditProjectSettingWithUnity(BuildTarget target, string pathToBuiltProject)
    {
        string     projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromFile(projectPath);
        packageManager.EditProjectSettingWithUnity(pbxProject);
        pbxProject.WriteToFile(projectPath);
    }
Esempio n. 2
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            string projPath = UnityEditor.iOS.Xcode.Custom.PBXProject.GetPBXProjectPath(path);
            UnityEditor.iOS.Xcode.Custom.PBXProject pbxProject = new UnityEditor.iOS.Xcode.Custom.PBXProject();
            pbxProject.ReadFromString(File.ReadAllText(projPath));

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

            pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "false");
            pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", " -lxml2");

            File.WriteAllText(projPath, pbxProject.WriteToString());
        }
    }
Esempio n. 3
0
    public static void OnPostprocessBuild(XcodeProjectSetting setting, string buildPath)
    {
        string pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);

        UnityEditor.iOS.Xcode.Custom.PBXProject pbxProject = new UnityEditor.iOS.Xcode.Custom.PBXProject();
        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //获取 target的Guid
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
        string projPath   = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        //LinkLibraries(projPath);
        //拷贝所有文件
        if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");
        }

        //设置编译器标志
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    Debug.Log(targetPath + "编译器标志不能被设置,因为没有这个标志");
                    continue;
                }

                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);

                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        //添加所有的 Framework
        foreach (string framework in setting.FrameworkList)
        {
            string libStr = framework;
            bool   weak   = false;
            if (framework.Contains(":"))
            {
                string[] ss = framework.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }
            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }

        foreach (string lib in setting.LibList)
        {
            string libStr = lib;
            bool   weak   = false;
            if (lib.Contains(":"))
            {
                string [] ss = lib.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }

            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);

        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);

        //BitCode
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");
        pbxProject.AddCapability(targetGuid, UnityEditor.iOS.Xcode.Custom.PBXCapabilityType.PushNotifications);
        //保存最终工程
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        InfoPlistProcessor.SetApplicationQueriesSchemes(buildPath, setting.ApplicationQueriesSchemes);

        //URL配置
        foreach (XcodeProjectSetting.URLIdentifierData urlData in setting.URLIdentifierList)
        {
            InfoPlistProcessor.SetURLSchemes(buildPath, urlData.name, urlData.URLSchemes);
        }

        //关闭启动图像的已设定默认的设定
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATS配置
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //设置状态栏
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);

        //添加特殊的key   比如麦克风//
        foreach (XcodeProjectSetting.AddToInfoStringList data in setting.addStringKeyToPlist)
        {
            InfoPlistProcessor.AddStringKey(buildPath, data.Key, data.value);
        }

        foreach (XcodeProjectSetting.AddCodeData data in setting.AddCodeList)
        {
            string fileName = GetCClassFileName(buildPath, data.FileName);

            if (!System.IO.File.Exists(fileName))
            {
                fileName = Path.Combine(buildPath, data.FileName);
            }
            Debug.LogError("需要替换的文件路径:" + fileName);
            if (System.IO.File.Exists(fileName))
            {
                XClass xc = new XClass(fileName);
                xc.WriteStart(data.StartAddCode);
                foreach (XcodeProjectSetting.AddCodeSet addSet in data.addCodes)
                {
                    Debug.LogError(addSet.addFlag + "/需要替换的文件/" + addSet.AddCode);
                    xc.WriteBelow(addSet.addFlag, addSet.AddCode);
                }
                foreach (XcodeProjectSetting.ReplaceCodeSet replaceSet in data.replaceCode)
                {
                    xc.Replace(replaceSet.oldCode, replaceSet.newCode);
                }
            }
        }
        PlayerPrefs.DeleteKey(SETTING_DATA_PATHKEY);
    }