Xcodeのプロジェクトを書き出す際の設定値
Inheritance: UnityEngine.ScriptableObject
Beispiel #1
0
    public static void CreateAsset()
    {
        AssetDatabase.GenerateUniqueAssetPath(GetCurrentFilePath());
        XcodeProjectSetting setting = XcodeProjectSetting.Instance;

        setting.SaveConfig();
    }
    public static void CreateAsset()
    {
        string path = AssetDatabase.GenerateUniqueAssetPath("Assets/XcodeProjectSetting.asset");
        XcodeProjectSetting data = ScriptableObject.CreateInstance <XcodeProjectSetting> ();

        AssetDatabase.CreateAsset(data, path);
        AssetDatabase.SaveAssets();
    }
    public static void SetInfoPlist(string buildPath, XcodeProjectSetting setting)
    {
        PlistDocument plist = GetInfoPlist(buildPath);

        SetPrivacySensiticeData(plist, setting.privacySensiticeData, "privacySensiticeData");
        SetApplicationQueriesSchemes(plist, setting.ApplicationQueriesSchemes);
        SetBackgroundModes(plist, setting.BackgroundModes);
        SetURLSchemes(plist, setting.BundleUrlTypeList);
        plist.WriteToFile(GetInfoPlistPath(buildPath));
    }
    private static void SetUpDevelopmentInfo(PBXProject pbxProject, XcodeProjectSetting setting, string targetGuid)
    {
        string debugConfig   = pbxProject.BuildConfigByName(targetGuid, "Debug");
        string releaseConfig = pbxProject.BuildConfigByName(targetGuid, "Release");

        foreach (XcodeProjectSetting.DevelopmentInfo info in setting.developmentInfoList)
        {
            if (info.tag == DevelopType.Debug)
            {
                pbxProject.SetBuildPropertyForConfig(debugConfig, XcodeProjectSetting.PROVISIONING_PROFILE_SPECIFIER, info.provisioningProfileName);
                pbxProject.SetBuildPropertyForConfig(debugConfig, XcodeProjectSetting.DEVELOPMENT_TEAM, info.developmentTeam);
                pbxProject.SetBuildPropertyForConfig(debugConfig, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", "iPhone Developer");
            }
            else
            {
                pbxProject.SetBuildPropertyForConfig(releaseConfig, XcodeProjectSetting.PROVISIONING_PROFILE_SPECIFIER, info.provisioningProfileName);
                pbxProject.SetBuildPropertyForConfig(releaseConfig, XcodeProjectSetting.DEVELOPMENT_TEAM, info.developmentTeam);
                pbxProject.SetBuildPropertyForConfig(releaseConfig, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", "iPhone Distribution");
            }
        }
    }
Beispiel #5
0
    public static void SetInfoPlist(string buildPath, XcodeProjectSetting setting)
    {
        PlistDocument plist = GetInfoPlist(buildPath);

        SetPrivacySensiticeData(plist, setting.privacySensiticeData);
        SetApplicationQueriesSchemes(plist, setting.ApplicationQueriesSchemes);
        SetBackgroundModes(plist, setting.BackgroundModes);
        SetURLSchemes(plist, setting.BundleUrlTypeList);
        SetBundleName(plist);
        SetATS(plist, setting.EnableATS);
        SetStatusBar(plist, setting.EnableStatusBar);
        SetFullScreen(plist, setting.EnableFullScreen);
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            DeleteLaunchiImagesKey(plist);
        }

        if (setting.EnableGameCenter)
        {
            SetGameCenter(plist);
        }

        plist.WriteToFile(GetInfoPlistPath(buildPath));
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //iOS以外にビルドしている場合は更新処理を行わないように
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        //Xcodeの設定データを読み込む
        XcodeProjectSetting setting = Resources.Load <XcodeProjectSetting>(SETTING_DATA_PATH);

        if (setting == null)
        {
            Debug.Log("Resources/" + SETTING_DATA_PATH + "不存在,请查看文件是否建立");
            //Debug.Log ("Resources/" + SETTING_DATA_PATH + "がありません!");
            return;
        }

        //Xcodeプロジェクトの読み込み
        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //ターゲットのID取得
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        //根据设置路径先拷贝文件夹下的所有文件并在XcodeBuild中设置
        //指定ディレクトリ内のファイルを全てコピーする
        List <string> copyFilesPathList = setting.CopyDirectoryPath;

        for (int i = 0; i < copyFilesPathList.Count; i++)
        {
            string copyDirectoryPath = copyFilesPathList[i];
            if (!string.IsNullOrEmpty(copyDirectoryPath))
            {
                DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, copyDirectoryPath, buildPath, "");
            }
        }

        //设置文件 CompilerFlags 属性
        //设置其它属性 URL Identifier以下的配置
        //コンパイラフラグの設定
        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);
            }
        }

        //システムのフレームワークを追加
        foreach (XcodeProjectSetting.FrameworkSet framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework.content, framework.weak);
        }

        //add tbd file
        //发现在Xcode8以下使用这个会有bug 请务必升级到最新版本
        foreach (string tbdName in setting.LibsList)
        {
            pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile(
                                          "usr/lib/" + tbdName,
                                          "Frameworks/" + tbdName,
                                          PBXSourceTree.Sdk)
                                      );
        }

        //Linker Flagの設定
        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");

        //如果用到脚本工具打包并且需要兼容xcode8 这块代码需要用上
        //并且脚本代码需要将自动模式改成手动模式
        //sed指令:sed -i '' 's/ProvisioningStyle = Automatic;ProvisioningStyle = Manual;/g'%s
        //SetUpDevelopmentInfo (pbxProject, setting, targetGuid);

        //プロジェクトファイル書き出し
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //URLスキームの設定
        List <string> urlSchemeList = new List <string>(setting.URLSchemeList);

        InfoPlistProcessor.SetURLSchemes(buildPath, setting.URLIdentifier, urlSchemeList);

        //デフォルトで設定されているスプラッシュ画像の設定を消す
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATSの設定
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //ステータスバーの設定
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);
    }
Beispiel #7
0
    /// <summary>
    /// 指定ディレクトリをXcodeにコピーして追加する
    /// </summary>
    public static void CopyAndAddBuildToXcode(
        PBXProject pbxProject, string targetGuid,
        string copyDirectoryPath, string buildPath, string currentDirectoryPath,
        bool needToAddBuild = true
        )
    {
        XcodeProjectSetting setting   = Resources.Load <XcodeProjectSetting>(XcodeProjectUpdater.SETTING_DATA_PATH);
        HashSet <string>    embedHash = new HashSet <string>(setting.EmbedFrameworks);

        //コピー元(Unity)のディレクトリとコピー先(Xcode)のディレクトリのパスを作成
        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;
            }
            //アーカイブファイルの場合は、それが入っているディレクトリにパスを通す
            else 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);
                pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source));
            }
        }

        //ディレクトリの中にあるディレクトリの中もコピー
        foreach (string directoryPath in Directory.GetDirectories(unityDirectoryPath))
        {
            string directoryName      = Path.GetFileName(directoryPath);
            bool   nextNeedToAddBuild = needToAddBuild;

            //フレームワークやImages.xcassetsがが入っているディレクトリはコピーするだけ
            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),
                nextNeedToAddBuild
                );

            //フレームワークはディレクトリ内を全てコピーしてから、フレームワークごとプロジェクトに追加し、フレームワーク検索パスを通す
            if (directoryName.Contains(ExtensionName.FRAMEWORK) || directoryName.Contains(ExtensionName.BUNDLE))
            {
                string relativePath = Path.Combine(currentDirectoryPath, directoryName);
                string fileGuild    = pbxProject.AddFile(relativePath, relativePath, PBXSourceTree.Source);

                if (embedHash.Contains(directoryName))
                {
                    pbxProject.AddFileToEmbedFrameworks(targetGuid, fileGuild);
                    pbxProject.AddBuildProperty(
                        targetGuid,
                        XcodeProjectSetting.LD_RUNPATH_SEARCH_PATHS_KEY,
                        "$(inherited) @executable_path/Frameworks"
                        );
                }
                else
                {
                    pbxProject.AddFileToBuild(targetGuid, fileGuild);
                    pbxProject.AddBuildProperty(
                        targetGuid,
                        XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY,
                        XcodeProjectSetting.PROJECT_ROOT + currentDirectoryPath
                        );
                }
            }
        }
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //iOS以外にビルドしている場合は更新処理を行わないように
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        //Xcodeの設定データを読み込む
        XcodeProjectSetting setting = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(SETTING_DATA_PATH);

        if (setting == null)
        {
            Debug.Log("Resources/" + SETTING_DATA_PATH + "がありません!");
            return;
        }
        //Xcodeプロジェクトの読み込み
        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //ターゲットのID取得
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        //指定ディレクトリ内のファイルを全てコピーする
        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);

                InfoPlistProcessor.SetURLSchemes(buildPath, fileGuid, flagsList);
            }
        }

        //システムのフレームワークを追加
        foreach (string framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework, false);
        }

        foreach (string lib in setting.LibraryList)
        {
            string fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);
            pbxProject.AddFileToBuild(targetGuid, fileGuid);
        }

        //Linker Flagの設定
        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");

        //プロジェクトファイル書き出し
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //URLスキームの設定

        /*
         * List<string> urlSchemeList = new List<string>(setting.URLSchemeList);
         * InfoPlistProcessor.SetURLSchemes(buildPath, setting.URLIdentifier, urlSchemeList);
         */

        foreach (XcodeProjectSetting.URLIdentifierSet compilerFlagsSet in setting.URLIdentifierList)
        {
            List <string> urlSchemeList = new List <string>(compilerFlagsSet.URLSchemeList);
            InfoPlistProcessor.SetURLSchemes(buildPath, compilerFlagsSet.Flags, urlSchemeList);
        }

        List <string> applicationQueriesSchemes = new List <string>(setting.ApplicationQueriesSchemes);

        InfoPlistProcessor.SetApplicationQueriesSchemes(buildPath, applicationQueriesSchemes);

        //デフォルトで設定されているスプラッシュ画像の設定を消す
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATSの設定
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //ステータスバーの設定
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);
        var    code_path = buildPath + "/Classes/UnityAppController.h";
        string code_head = FileUtils.getInstance().getString(code_path);

        if (code_head.IndexOf("@property NSURL* mUrl;") == -1)
        {
            code_head = code_head.Replace("- (void)shouldAttachRenderDelegate;", "- (void)shouldAttachRenderDelegate;\n@property NSURL* mUrl;\n");
            FileUtils.getInstance().writeString(code_path, code_head);
        }
        code_path = buildPath + "/Classes/UnityAppController.mm";
        string code = FileUtils.getInstance().getString(code_path);

        if (code_head.IndexOf("_mUrl = url;") == -1)
        {
            code = code.Replace("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);", "_mUrl = url;\nAppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);");
            FileUtils.getInstance().writeString(code_path, code);
        }
    }
Beispiel #9
0
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        if (_enable == false)
        {
            return;
        }
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        PBXProject          pbxProject = null;
        XcodeProjectSetting setting    = null;
        string pbxProjPath             = PBXProject.GetPBXProjectPath(buildPath);
        string targetGuid = null;

        Debug.Log("开始设置.XCodeProj");

        setting    = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(SETTING_DATA_PATH);
        pbxProject = new PBXProject();
        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));
        targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.DEVELOPMENT_TEAM, setting.DevelopmentTeam);
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_EXCEPTIONS, setting.EnableCppEcceptions ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_RTTI, setting.EnableCppRtti ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_OBJC_EXCEPTIONS, setting.EnableObjcExceptions ? "YES" : "NO");

        if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");
        }

        //编译器标记(Compiler flags)
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    continue;
                }
                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);
                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        //引用内部框架
        foreach (string framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework, false);
        }

        //引用.tbd文件
        foreach (string tbd in setting.TbdList)
        {
            pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile("usr/lib/" + tbd, "Frameworks/" + tbd, PBXSourceTree.Sdk));
        }

        //设置OTHER_LDFLAGS
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);
        //设置Framework Search Paths
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //已经存在的文件,拷贝替换
        foreach (XcodeProjectSetting.CopeFiles file in setting.CopeFilesList)
        {
            File.Copy(Application.dataPath + file.sourcePath, buildPath + file.copyPath, true);
        }

        //File.Copy(Application.dataPath + "/Editor/XCodeAPI/UnityAppController.h", buildPath + "/Classes/UnityAppController.h", true);
        //File.Copy(Application.dataPath + "/Editor/XCodeAPI/UnityAppController.mm", buildPath + "/Classes/UnityAppController.mm", true);

        //设置Plist
        InfoPlistProcessor.SetInfoPlist(buildPath, setting);
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //是不是ios
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        string cfgPath = Application.dataPath + "/XcodeSet.asset";//PlayerPrefs.GetString(SETTING_DATA_PATHKEY,"");

        if (string.IsNullOrEmpty(cfgPath))
        {
            return;
        }
        //Xcode读取配置数据
        XcodeProjectSetting setting = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(cfgPath);

        if (setting == null)
        {
            Debug.Log("Resources/" + cfgPath + "目录不存在");
            return;
        }
        else
        {
            Debug.LogError("cfgPath =" + cfgPath);
        }

        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new 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");

        //保存最终工程
        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))
            {
                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);
    }
Beispiel #11
0
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //iOS以外にビルドしている場合は更新処理を行わないように
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        //Xcodeの設定データを読み込む
        XcodeProjectSetting setting = Resources.Load <XcodeProjectSetting>(SETTING_DATA_PATH);

        if (setting == null)
        {
            Debug.Log("Resources/" + SETTING_DATA_PATH + "がありません!");
            return;
        }

        //Xcodeプロジェクトの読み込み
        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //ターゲットのID取得
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        //指定ディレクトリ内のファイルを全てコピーする
        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);
            }
        }

        //システムのフレームワークを追加
        foreach (string framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework, false);
        }

        //Linker Flagの設定
        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");

        //プロジェクトファイル書き出し
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //URLスキームの設定
        List <string> urlSchemeList = new List <string>(setting.URLSchemeList);

        InfoPlistProcessor.SetURLSchemes(buildPath, setting.URLIdentifier, urlSchemeList);

        //デフォルトで設定されているスプラッシュ画像の設定を消す
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATSの設定
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //ステータスバーの設定
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        PBXProject          pbxProject = null;
        XcodeProjectSetting setting    = null;
        string pbxProjPath             = PBXProject.GetPBXProjectPath(buildPath);
        string targetGuid = null;

        Debug.Log("开始设置.XCodeProj");

        setting    = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(SETTING_DATA_PATH);
        pbxProject = new PBXProject();
        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));
        targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.DEVELOPMENT_TEAM, setting.DevelopmentTeam);
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_EXCEPTIONS, setting.EnableCppEcceptions ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_RTTI, setting.EnableCppRtti ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_OBJC_EXCEPTIONS, setting.EnableObjcExceptions ? "YES" : "NO");

        //  if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        //    DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");

        for (int i = 0; i < setting.CopyDirectoryPath.Count; i++)
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath[i], buildPath, "");
        }

        //编译器标记(Compiler flags)
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    continue;
                }
                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);
                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        var codesign    = Debug.isDebugBuild ? "iPhone Developer: Liang Dong (62ZU2QZX6V)" : "iPhone Distribution: X.D. Network Inc. (NTC4BJ542G)";
        var provision   = Debug.isDebugBuild ? "XDMagicp" : "TheLastCrown_AppStore";
        var bundleName  = Debug.isDebugBuild ? "com.xindong.lastcrown" : "com.xindong.thelastcrown";
        var produceName = Debug.isDebugBuild ? "lastcrown" : "thelastcrown";
        var teamId      = Debug.isDebugBuild ? "XF28F2YCJQ" : "NTC4BJ542G";

        pbxProject.SetBuildProperty(targetGuid, "CODE_SIGN_IDENTITY", codesign);
        pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", provision);
        pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", teamId);
        pbxProject.AddBuildProperty(targetGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleName);
        pbxProject.AddBuildProperty(targetGuid, "CODE_SIGN_STYLE", "Manual");
        pbxProject.SetBuildProperty(targetGuid, "PRODUCT_NAME", produceName);

        DirectoryProcessor.CopyAndReplace("/Users/dongliang/Perforce/lizheng_dongliangdeMac-mini_2302/CopyiOS/Unity-iPhone", buildPath + "/Unity-iPhone");

        //引用内部框架
        foreach (string framework in setting.FrameworkList)
        {
            pbxProject.AddFrameworkToProject(targetGuid, framework, false);
        }

        //引用.tbd文件
        foreach (string tbd in setting.TbdList)
        {
            pbxProject.AddFileToBuild(targetGuid, pbxProject.AddFile("usr/lib/" + tbd, "Frameworks/" + tbd, PBXSourceTree.Sdk));
        }

        //设置OTHER_LDFLAGS
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);
        //设置Framework Search Paths
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //已经存在的文件,拷贝替换
        foreach (XcodeProjectSetting.CopeFiles file in setting.CopeFilesList)
        {
            File.Copy(Application.dataPath + file.sourcePath, buildPath + file.copyPath, true);
        }

        //File.Copy(Application.dataPath + "/Editor/XCodeAPI/UnityAppController.h", buildPath + "/Classes/UnityAppController.h", true);
        //File.Copy(Application.dataPath + "/Editor/XCodeAPI/UnityAppController.mm", buildPath + "/Classes/UnityAppController.mm", true);

        //设置Plist
        InfoPlistProcessor.SetInfoPlist(buildPath, setting);
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        PBXProject          pbxProject = null;
        XcodeProjectSetting setting    = null;
        string pbxProjPath             = PBXProject.GetPBXProjectPath(buildPath);
        string targetGuid = null;

        Debug.Log("开始设置.XCodeProj");

        setting    = XcodeProjectSetting.Instance;
        pbxProject = new PBXProject();
        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));
        targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());

        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");
        if (!string.IsNullOrEmpty(setting.DevelopmentTeam))
        {
            pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.DEVELOPMENT_TEAM, setting.DevelopmentTeam);
        }
        if (!string.IsNullOrEmpty(setting.ProvisioningProfile))
        {
            pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.PROVISIONING_PROFILE, setting.ProvisioningProfile);
            pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.PROVISIONING_PROFILE_SPECIFIER, setting.ProvisioningProfile);
        }
        if (!string.IsNullOrEmpty(setting.CodeSignIdentity))
        {
            pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.CODE_SIGN_IDENTITY, setting.CodeSignIdentity);
            pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.CODE_SIGN_IDENTITY_OTHER, setting.CodeSignIdentity);
        }
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_EXCEPTIONS, setting.EnableCppEcceptions ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_CPP_RTTI, setting.EnableCppRtti ? "YES" : "NO");
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.GCC_ENABLE_OBJC_EXCEPTIONS, setting.EnableObjcExceptions ? "YES" : "NO");

        //添加Capability
        CapabilityProcessor capProcessor = new CapabilityProcessor(pbxProject, buildPath, pbxProjPath, setting.EntitlementFilePath, targetGuid);

        capProcessor.AddInAppPurchase();
        capProcessor.AddPushNotifications(true);
        capProcessor.AddKeychainSharing();
        if (setting.EnableGameCenter)
        {
            capProcessor.AddGameCenter();
        }
        capProcessor.WriteToFile();

        if (!string.IsNullOrEmpty(setting.XcodeAPIDirectoryPath))
        {
            string modsPath = Path.Combine(setting.XcodeAPIDirectoryPath, XcodeProjectSetting.MODS_PATH);
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, modsPath, buildPath, "", setting.EmbedFrameworkList);
            if (setting.EmbedFrameworkList.Count > 0)
            {
                pbxProject.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            }
        }

        //编译器标记(Compiler flags)
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    continue;
                }
                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);
                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        //引用内部框架
        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);
        }

        //引用.tbd文件
        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";
                }
            }
            string fileGuid = pbxProject.AddFile("usr/lib/" + libStr, "Frameworks/" + libStr, PBXSourceTree.Sdk);
            pbxProject.AddFileToBuild(targetGuid, fileGuid, weak);
        }

        //设置OTHER_LDFLAGS
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);
        //设置Framework Search Paths
        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        //已经存在的文件,拷贝替换
        foreach (XcodeProjectSetting.CopyFiles file in setting.CopyFilesList)
        {
            string sourcePath = Path.Combine(Application.dataPath, setting.XcodeAPIDirectoryPath.Replace("Assets/", ""), XcodeProjectSetting.COPY_PATH, file.sourcePath);
            string copyPath   = buildPath + file.copyPath;
            if (File.Exists(sourcePath))
            {
                File.Copy(sourcePath, copyPath, true);
            }
            else
            {
                DirectoryProcessor.CopyAndReplace(sourcePath, copyPath);
            }
        }

        //设置Plist
        InfoPlistProcessor.SetInfoPlist(buildPath, setting);
    }