GetCompileFlagsForFile() public method

public GetCompileFlagsForFile ( string targetGuid, string fileGuid ) : List
targetGuid string
fileGuid string
return List
示例#1
0
    //设置Capabilities
    void SetCapabilities(string pathToBuildProject)
    {
        string projPath = pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj";  //项目路径,这个路径在mac上默认是不显示的,需要右键->显示包内容才能看到。unity到处的名字就是这个。

        UnityEditor.iOS.Xcode.PBXProject pbxProj = new UnityEditor.iOS.Xcode.PBXProject(); //创建xcode project类
        pbxProj.ReadFromString(File.ReadAllText(projPath));                                //xcode project读入
        string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName());     //获得Target名

        //设置BuildSetting
        pbxProj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
        pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
        pbxProj.SetBuildProperty(targetGuid, "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym"); //定位崩溃bug
        pbxProj.SetBuildProperty(targetGuid, "EXCLUDED_ARCHS", "armv7");

        pbxProj.AddFrameworkToProject(targetGuid, "MediaPlayer.framework", false);
        pbxProj.AddFrameworkToProject(targetGuid, "AdSupport.framework", true);
        //添加资源
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(System.Environment.CurrentDirectory + "/LTBaseSDK_Oversea/ltgame.cfg", "Resource/ltgame.cfg", PBXSourceTree.Source));

        //修改编译方式
        string mmfile = pbxProj.FindFileGuidByProjectPath("Classes/UnityAppController.mm");
        var    flags  = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile);

        flags.Add("-fno-objc-arc");
        pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags);
        mmfile = pbxProj.FindFileGuidByProjectPath("Libraries/Plugins/IOS/LTSDK/LTSDKNPC.mm");
        flags  = pbxProj.GetCompileFlagsForFile(targetGuid, mmfile);
        flags.Add("-fno-objc-arc");
        pbxProj.SetCompileFlagsForFile(targetGuid, mmfile, flags);
        pbxProj.WriteToFile(projPath);

        string[] splits     = PlayerSettings.applicationIdentifier.Split('.');
        var      capManager = new ProjectCapabilityManager(projPath, splits[splits.Length - 1] + ".entitlements", PBXProject.GetUnityTargetName());//创建设置Capability类

        if (PlayerSettings.applicationIdentifier.Equals("com.longtugame.dzyz.longtu"))
        {
            //正式包,增加计费
            capManager.AddInAppPurchase();
        }
        capManager.AddAssociatedDomains(new[]
        {
            "applinks:dy.longtugame.com"
        });
        capManager.WriteToFile();//写入文件保存
    }
    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);
    }