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);
    }
Beispiel #2
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)
    {
        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);
    }