97 lines
4.3 KiB
C#
97 lines
4.3 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
#if UNITY_IPHONE
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEditor.Callbacks;
|
|||
|
|
using UnityEditor.iOS.Xcode;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
public class XCodeProjectMod : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
#if UNITY_IPHONE
|
|||
|
|
private const string SETTING_DATA_PATH = "Assets/Editor/XCodeAPI/Setting/XcodeProjectSetting.asset";
|
|||
|
|
[PostProcessBuild]
|
|||
|
|
private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
|
|||
|
|
{
|
|||
|
|
Debug.LogError("ios工程==========================================");
|
|||
|
|
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.GetUnityFrameworkTargetGuid();
|
|||
|
|
|
|||
|
|
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");
|
|||
|
|
|
|||
|
|
var sign_type = setting.SignType.ToString();
|
|||
|
|
foreach (XcodeProjectSetting.SignIdentity si in setting.SignIdentityList)
|
|||
|
|
{
|
|||
|
|
if (si.name == sign_type)
|
|||
|
|
{
|
|||
|
|
pbxProject.SetBuildProperty(targetGuid, "CODE_SIGN_IDENTITY", si.codeSign);
|
|||
|
|
pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE", si.profile);
|
|||
|
|
pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", si.profileSpecifier);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 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)
|
|||
|
|
{
|
|||
|
|
Debug.Log(Application.dataPath + file.sourcePath + " " + buildPath + file.copyPath);
|
|||
|
|
File.Copy(Application.dataPath + file.sourcePath, buildPath + file.copyPath, true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//设置Plist
|
|||
|
|
InfoPlistProcessor.SetInfoPlist(buildPath, setting);
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
}
|