This commit is contained in:
puxuan 2025-08-04 19:14:30 +08:00
parent 4ce72abeb5
commit d351d4549f
5 changed files with 576 additions and 622 deletions

View File

@ -20,61 +20,32 @@ namespace BFEditor.Build
} }
} }
public static class BuildMode
{
public const string DEV = "dev";
public const string TEST = "test";
public const string PUBLISH = "publish";
}
[Serializable] [Serializable]
public class BuildInfo public class BuildInfo
{ {
public string bundleName; // 包名 public string bundleName; // 包名
public string version; // 版本号 public string version; // 版本号
public string mode; // 渠道名_debug 或 渠道名_release public string mode; // 内网测试包,外网测试包,外网正式包
public int version_code = 1; // 各自渠道的version_code public int versionCode = 1; // 各自渠道的version code
public List<BulidGitInfo> git_info; // 打包的git信息 public List<BulidGitInfo> git_info; // 打包的git信息
public bool exportProject = false; // 是否只导出工程
public bool onlyAssetBundle = false; // 是否只打ab包
[NonSerialized] [NonSerialized]
public bool skipVersion = false; // 是否跳过版本校验 public bool skipVersion = false; // 是否跳过版本校验
public bool IsGPChannel()
{
return bundleName == "com.combo.heroes.puzzle.rpg";
}
public bool IsGPOfficial()
{
return bundleName == "com.combo.heroes.puzzle.rpg";
}
// dev包使用mono编译不会导出as工程
public bool IsDevChannel()
{
return bundleName == "com.juzu.b6.dev" || bundleName == "com.juzu.b6.dev.android" ||
bundleName == "com.juzu.b6.dev.ios";
}
public bool IsReleaseChannel()
{
return !IsDevChannel();
}
// 是否是内网release
public bool IsLanRelease()
{
return bundleName == "com.juzu.b6.release.android" || bundleName == "com.juzu.b6.release.ios";
}
public bool IsPublish() public bool IsPublish()
{ {
return !IsDevChannel() && !IsLanRelease(); return mode == BuildMode.PUBLISH;
} }
public bool IsIOSPlatform()
{
return bundleName.Contains("ios");
}
public bool IsAndroidPlatform()
{
return !IsIOSPlatform();
}
public string GetBundleName() public string GetBundleName()
{ {
return bundleName; return bundleName;

View File

@ -48,6 +48,12 @@ namespace BFEditor.Build
return false; return false;
} }
// 只打ab包
if (buildInfo.onlyAssetBundle)
{
AssetDatabase.Refresh();
return true;
}
// 删除不进包的多语言 // 删除不进包的多语言
// if (!DeleteOverLanguageAb(buildInfo)) // if (!DeleteOverLanguageAb(buildInfo))
// { // {
@ -73,19 +79,10 @@ namespace BFEditor.Build
watch.Start(); watch.Start();
var result = false; var result = false;
if (BuildAndroidUtils.BuildAndroidPlayer(buildInfo))
if (buildInfo.IsAndroidPlatform() && BuildAndroidUtils.BuildAndroidPlayer(buildInfo))
{ {
result = true; result = true;
} }
#if UNITY_EDITOR_OSX
if (buildInfo.IsIOSPlatform() && BuildIOSUtils.BuildIOSPlayer(buildInfo))
{
result = true;
}
#endif
if (result) if (result)
{ {
watch.Stop(); watch.Stop();
@ -140,8 +137,7 @@ namespace BFEditor.Build
var watch = new System.Diagnostics.Stopwatch(); var watch = new System.Diagnostics.Stopwatch();
watch.Start(); watch.Start();
// var buildTarget = buildInfo.IsIOSPlatform() ? BuildTarget.iOS : BuildTarget.Android; var isRelease = true;
var isRelease = buildInfo.IsReleaseChannel();
Debug.Log("[bfinfo]开始打包资源, bundleName : " + buildInfo.bundleName + " version : " + buildInfo.version + " mode : " + buildInfo.mode); Debug.Log("[bfinfo]开始打包资源, bundleName : " + buildInfo.bundleName + " version : " + buildInfo.version + " mode : " + buildInfo.mode);
// // 检查平台 // // 检查平台
@ -197,7 +193,7 @@ namespace BFEditor.Build
} }
// 本地缓存ab // 本地缓存ab
if (buildInfo.IsReleaseChannel()) if (buildInfo.IsPublish())
{ {
Debug.Log("[bfinfo]正在缓存assetbundles..."); Debug.Log("[bfinfo]正在缓存assetbundles...");
BFEditorUtils.CopyDirWithIgnore(outputPath, Path.Combine(AssetBundleCachePath, buildInfo.version), new List<string> { ".meta" }); BFEditorUtils.CopyDirWithIgnore(outputPath, Path.Combine(AssetBundleCachePath, buildInfo.version), new List<string> { ".meta" });

View File

@ -6,77 +6,116 @@ namespace BFEditor.Build
public enum BFPlatformOptions public enum BFPlatformOptions
{ {
AndroidDev = 1, AndroidDev = 1,
IOSDev, AndroidTest,
AndroidRelease,
AndroidGP, AndroidGP,
AndroidGPRU
} }
public class BuildProjectWindow : EditorWindow public class BuildProjectWindow : EditorWindow
{ {
private static int versionCode = 18; private static int VersionCode = 4;
private static string versionName = "1.6.5"; private static string VersionName = "1.2.10";
private static int VersionCodeRU = 12;
private static string VersionNameRU = "0.4.9";
BFPlatformOptions platform = BFPlatformOptions.AndroidDev; BFPlatformOptions platform = BFPlatformOptions.AndroidDev;
const string ANDROID_DEV_PACKAGE_NAME = "com.juzu.b6.dev.android"; const string ANDROID_GP_PACKAGE_NAME = "com.c1.dev.android";
const string ANDROID_RELEASE_PACKAGE_NAME = "com.juzu.b6.release.android";
const string ANDROID_GP_PACKAGE_NAME = "com.combo.heroes.puzzle.rpg";
const string IOS_PACKAGE_NAME = "com.juzu.b6.dev.ios";
public BuildProjectWindow() public BuildProjectWindow()
{ {
titleContent = new GUIContent("打包"); titleContent = new GUIContent("打包");
} }
private void OnEnable() { } private void OnEnable() { }
void OnGUI() void OnGUI()
{ {
GUILayout.BeginVertical("box");
EditorGUILayout.LabelField("选择渠道");
platform = (BFPlatformOptions)EditorGUILayout.EnumPopup("", platform);
EditorGUILayout.Space();
EditorGUILayout.LabelField("版本: " + versionName);
EditorGUILayout.Space();
string packageName; string packageName;
string mode; string mode;
string versionName = VersionName;
int versionCode = VersionCode;
bool skipVersion = false; bool skipVersion = false;
string appType;
if (platform == BFPlatformOptions.AndroidDev) if (platform == BFPlatformOptions.AndroidDev)
{ {
packageName = ANDROID_DEV_PACKAGE_NAME; packageName = ANDROID_GP_PACKAGE_NAME;
skipVersion = true; skipVersion = true;
mode = "dev_debug"; mode = BuildMode.DEV;
versionName = "0.1.0";
versionCode = 1;
appType = "内网测试包";
} }
else if(platform == BFPlatformOptions.AndroidRelease) else if(platform == BFPlatformOptions.AndroidTest)
{ {
packageName = ANDROID_RELEASE_PACKAGE_NAME; packageName = ANDROID_GP_PACKAGE_NAME;
mode = "release_release"; mode = BuildMode.TEST;
versionName = "0.1.0";
versionCode = 1;
appType = "外网测试包";
} }
else if(platform == BFPlatformOptions.AndroidGP) else if(platform == BFPlatformOptions.AndroidGP)
{ {
packageName = ANDROID_GP_PACKAGE_NAME; packageName = ANDROID_GP_PACKAGE_NAME;
mode = "publish_release"; mode = BuildMode.PUBLISH;
appType = "外网正式包";
} }
else else
{ {
packageName = IOS_PACKAGE_NAME; packageName = ANDROID_GP_PACKAGE_NAME;
mode = "dev_debug"; skipVersion = true;
mode = BuildMode.DEV;
versionName = "0.1.0";
versionCode = 1;
appType = "内网测试包";
} }
GUILayout.BeginVertical("box");
EditorGUILayout.LabelField("选择");
platform = (BFPlatformOptions)EditorGUILayout.EnumPopup("", platform);
EditorGUILayout.Space();
EditorGUILayout.LabelField("版本: " + versionName);
EditorGUILayout.Space();
EditorGUILayout.LabelField("包名: " + packageName); EditorGUILayout.LabelField("包名: " + packageName);
EditorGUILayout.LabelField("mode: " + mode); EditorGUILayout.Space();
EditorGUILayout.LabelField(appType);
EditorGUILayout.Space();
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.Space(); var buildInfo = new BuildInfo();
buildInfo.version = versionName;
buildInfo.versionCode = versionCode;
buildInfo.mode = mode;
buildInfo.bundleName = packageName;
buildInfo.skipVersion = skipVersion;
if (GUILayout.Button("一键打包")) if (GUILayout.Button("一键APK"))
{ {
var buildInfo = new BuildInfo(); buildInfo.exportProject = false;
buildInfo.version = versionName; buildInfo.onlyAssetBundle = false;
buildInfo.version_code = versionCode; BuildProjectTools.BuildBFPlayer(buildInfo);
buildInfo.mode = mode; }
buildInfo.bundleName = packageName;
buildInfo.skipVersion = skipVersion; EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
if (GUILayout.Button("仅导出工程"))
{
buildInfo.exportProject = true;
buildInfo.onlyAssetBundle = false;
BuildProjectTools.BuildBFPlayer(buildInfo);
}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
if (GUILayout.Button("仅打ab包"))
{
buildInfo.exportProject = true;
buildInfo.onlyAssetBundle = true;
BuildProjectTools.BuildBFPlayer(buildInfo); BuildProjectTools.BuildBFPlayer(buildInfo);
} }

View File

@ -3,9 +3,9 @@ using UnityEditor;
using System.IO; using System.IO;
using UnityEditor.Build.Reporting; using UnityEditor.Build.Reporting;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System; using System;
using System.Threading; using System.Threading;
using System.Collections.Generic;
namespace BFEditor.Build namespace BFEditor.Build
{ {
@ -24,13 +24,13 @@ namespace BFEditor.Build
static string BuglyPath = Application.dataPath + "/../Bugly"; static string BuglyPath = Application.dataPath + "/../Bugly";
static string BuglySOPath = Application.dataPath + "/../Bugly/so"; static string BuglySOPath = Application.dataPath + "/../Bugly/so";
static string GradleExcuteProjectPath = Application.dataPath + "/../BFVersions/android/ub-release"; static string GradleExcuteProjectPath = Application.dataPath + "/../BFVersions/android/ub-release";
static string DevAsProjectPath = Application.dataPath + "/../BFVersions/android/dz_dev";
static string LanReleaseAsProjectPath = Application.dataPath + "/../BFVersions/android/dz_release";
static string GoogleAsProjectPath = Application.dataPath + "/../BFVersions/android/dz_google_apk"; static string GoogleAsProjectPath = Application.dataPath + "/../BFVersions/android/dz_google_apk";
static string GoogleCommonProjectPath = Application.dataPath + "/../BFVersions/android/google_common"; static string GoogleCommonProjectPath = Application.dataPath + "/../BFVersions/android/google_common";
static string GPAsProjectPath = Application.dataPath + "/../BFVersions/android/ub-gp"; // gp删档测试渠道 static string RuStoreProjectPath = Application.dataPath + "/../BFVersions/android/ru_store";
static string GPOfficialAsProjectPath = Application.dataPath + "/../BFVersions/android/ub-google"; // gp正式渠道 static string RuProjectPath = Application.dataPath + "/../BFVersions/android/ru";
static string GoogleServicesProjectPath = Application.dataPath + "/../BFVersions/android/google-services";
static string PublishAsProjectPath = Application.dataPath + "/../BFVersions/android/publish_release"; static string PublishAsProjectPath = Application.dataPath + "/../BFVersions/android/publish_release";
static string KeystoreFilePath = Application.dataPath + "/../BFVersions/android/keystore/dz_keystore.txt";
static string SignShellPath = Application.dataPath + "/../BFFiles/androidkey"; static string SignShellPath = Application.dataPath + "/../BFFiles/androidkey";
static string GpAlginShellPath = Application.dataPath + "/../BFFiles/androidkey"; static string GpAlginShellPath = Application.dataPath + "/../BFFiles/androidkey";
static HashSet<string> AABInPackageFileHashSet = new HashSet<string>() static HashSet<string> AABInPackageFileHashSet = new HashSet<string>()
@ -77,10 +77,19 @@ namespace BFEditor.Build
var bpOptions = GetBuildOptions(buildInfo); var bpOptions = GetBuildOptions(buildInfo);
var report = BuildPipeline.BuildPlayer(bpOptions); var report = BuildPipeline.BuildPlayer(bpOptions);
// 打包成功 // 导出工程成功
if (report.summary.result == BuildResult.Succeeded) if (report.summary.result == BuildResult.Succeeded)
{ {
return BuildAndroidAPK(buildInfo); MergeProject(buildInfo, GoogleAsProjectPath);
FixGradleVersion(buildInfo.versionCode, buildInfo.version);
if (buildInfo.exportProject)
{
return true;
}
else
{
return BuildAPK(buildInfo);
}
} }
else else
{ {
@ -98,7 +107,7 @@ namespace BFEditor.Build
PlayerSettings.bundleVersion = buildInfo.version; PlayerSettings.bundleVersion = buildInfo.version;
// 设置VersionCode // 设置VersionCode
PlayerSettings.Android.bundleVersionCode = buildInfo.version_code; PlayerSettings.Android.bundleVersionCode = buildInfo.versionCode;
// 设置竖屏 // 设置竖屏
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait; PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
@ -118,41 +127,33 @@ namespace BFEditor.Build
// 设置包名 // 设置包名
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, buildInfo.bundleName); PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, buildInfo.bundleName);
Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName);
// 跳过版本控制 // 跳过版本控制
var symbols = ANDROID_DEFINE_SYMBOLS; var symbols = ANDROID_DEFINE_SYMBOLS;
if (buildInfo.skipVersion) if (buildInfo.skipVersion)
{ {
symbols = symbols + ";SKIP_VERSION;"; symbols = symbols + ";SKIP_VERSION";
}
if (buildInfo.mode == BuildMode.DEV)
{
symbols = symbols + ";BF_APP_DEV";
}
else if (buildInfo.mode == BuildMode.TEST)
{
symbols = symbols + ";BF_APP_TEST";
} }
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, symbols); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, symbols);
Debug.Log("[bfinfo]设置defineSymbols: " + symbols); Debug.Log("[bfinfo]设置defineSymbols: " + symbols);
// 是否是dev PlayerSettings.productName = "Pull Pull Pull Heroes";
var development = buildInfo.IsDevChannel() ? true : false; EditorUserBuildSettings.development = false;
EditorUserBuildSettings.development = development; EditorUserBuildSettings.androidBuildType = AndroidBuildType.Release;
// 商品名称
// 应用名
if (buildInfo.IsPublish())
{
PlayerSettings.productName = "Knights Combo";
}
else
{
PlayerSettings.productName = development ? "b6-dev" : "b6-release";
}
// BuildType设置dev/release
EditorUserBuildSettings.androidBuildType = development ? AndroidBuildType.Debug : AndroidBuildType.Release;
// 是否导出as工程 // 是否导出as工程
// EditorUserBuildSettings.exportAsGoogleAndroidProject = development ? false : true;
EditorUserBuildSettings.exportAsGoogleAndroidProject = true; EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
// dev使用Mono release使用IL2CPP var scriptImp = ScriptingImplementation.IL2CPP;
var scriptImp = development ? ScriptingImplementation.Mono2x : ScriptingImplementation.IL2CPP;
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, scriptImp); PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, scriptImp);
} }
@ -164,29 +165,9 @@ namespace BFEditor.Build
var bpOptions = new BuildPlayerOptions(); var bpOptions = new BuildPlayerOptions();
bpOptions.scenes = AssetBundleUtils.GetBuildScenes(); bpOptions.scenes = AssetBundleUtils.GetBuildScenes();
bpOptions.target = BuildTarget.Android; bpOptions.target = BuildTarget.Android;
// if (buildInfo.IsDevChannel())
// {
// bpOptions.locationPathName = GetDevApkPathName(buildInfo);
// Debug.Log("[bfinfo]apk path : " + bpOptions.locationPathName);
// }
// else
// {
// bpOptions.locationPathName = GetASProjectPathName();
// Debug.Log("[bfinfo]asProject path : " + bpOptions.locationPathName);
// }
bpOptions.locationPathName = GetASProjectPathName(buildInfo); bpOptions.locationPathName = GetASProjectPathName(buildInfo);
BuildOptions options; BuildOptions options = BuildOptions.None;
if (buildInfo.IsReleaseChannel())
{
options = BuildOptions.None;
}
else
{
options = BuildOptions.Development;
}
bpOptions.options = options; bpOptions.options = options;
return bpOptions; return bpOptions;
} }
@ -200,7 +181,7 @@ namespace BFEditor.Build
static string GetASProjectPathName(BuildInfo buildInfo) static string GetASProjectPathName(BuildInfo buildInfo)
{ {
var dir = Path.Combine(AS_PROJECT_PATH, buildInfo.mode); var dir = Path.Combine(AS_PROJECT_PATH, "publish_release");
if (Directory.Exists(dir)) if (Directory.Exists(dir))
{ {
Directory.Delete(dir, true); Directory.Delete(dir, true);
@ -208,32 +189,53 @@ namespace BFEditor.Build
return dir; return dir;
} }
static bool BuildAPK(BuildInfo buildInfo) static bool BuildAPK(BuildInfo buildInfo, bool isAAB = false)
{ {
if (buildInfo.IsGPChannel()) // 设置jdk环境变量
{ string javaHomePath = System.Environment.GetEnvironmentVariable("JAVE_HOME");
MergeGPToReleaseProject(buildInfo); if (string.IsNullOrEmpty(javaHomePath))
FixGradleVersion(buildInfo.version_code, buildInfo.version); {
} Debug.LogError("[bferror] 找不到环境变量JAVE_HOME");
return false;
}
var gradleFilePath = Path.Combine(PublishAsProjectPath, "gradle.properties");
var gradleFileText = File.ReadAllText(gradleFilePath);
if (!gradleFileText.Contains("org.gradle.java.home"))
{
gradleFileText = gradleFileText + "\norg.gradle.java.home=" + javaHomePath.Replace("\\", "/");
}
File.WriteAllText(gradleFilePath, gradleFileText);
if (buildInfo.IsLanRelease()) // 设置密钥密码
{ if (File.Exists(KeystoreFilePath))
AddBuglyParamsToReleaseProject(); {
} var password = File.ReadAllText(KeystoreFilePath).Replace("\n", "").Replace("\r", "");
var buildGradlePath = Path.Combine(PublishAsProjectPath, "launcher/build.gradle");
var text = File.ReadAllText(buildGradlePath);
var regex = new Regex("REPLACE_PASSWORD");
text = regex.Replace(text, password);
File.WriteAllText(buildGradlePath, text);
}
Debug.Log("[bfinfo]正在buildApk..."); Debug.Log("[bfinfo]正在buildApk...");
var success = true; var success = true;
var args = ""; var args = "assembleRelease";
if (buildInfo.IsReleaseChannel()) if (isAAB)
{ {
args += " assembleRelease"; args = "bundleRelease";
} }
else string gradleHomePath = System.Environment.GetEnvironmentVariable("GRADLE_HOME");
{ if (string.IsNullOrEmpty(gradleHomePath))
args += " assembleDebug"; {
} Debug.LogError("[bferror] 找不到环境变量GRADLE_HOME");
return false;
BFEditorUtils.RunCommond(GRADLE_PATH, args, GradleExcuteProjectPath, }
#if UNITY_EDITOR_OSX
var gradleCommondPath = Path.Combine(gradleHomePath, "gradle");
#else
var gradleCommondPath = Path.Combine(gradleHomePath, "gradle.bat");
#endif
BFEditorUtils.RunCommond(gradleCommondPath, args, PublishAsProjectPath,
(msg) => (msg) =>
{ {
}, },
@ -245,80 +247,35 @@ namespace BFEditor.Build
Debug.LogError("[bferror] " + errorMsg); Debug.LogError("[bferror] " + errorMsg);
} }
}); });
if (buildInfo.IsGPChannel())
{
// 尝试制作并上传bugly符号表 开新Thread不影响打包流程
if (success)
{
CopySOAndUploadBuglySymbol(buildInfo.bundleName, buildInfo.version);
}
}
return success; return success;
} }
static bool BuildAAB(BuildInfo buildInfo)
{
var result = true;
if(buildInfo.IsGPChannel())
{
// MergeGPToReleaseProject(buildInfo);
// FixGradleVersion(buildInfo.version_code, buildInfo.version);
}
return result;
}
static bool BuildAndroidAPK(BuildInfo buildInfo)
{
var result = true;
if(buildInfo.IsDevChannel())
{
MergeProject(buildInfo, DevAsProjectPath);
var dir = Path.Combine(Application.dataPath, "../", AS_PROJECT_PATH, buildInfo.mode);
BFEditorUtils.RunCommond("gradle", " assembleDebug", dir, (msg) => {
}, (errorMsg) => {
Debug.LogError("[bferror] " + errorMsg);
});
}
else if(buildInfo.IsLanRelease())
{
MergeProject(buildInfo, LanReleaseAsProjectPath);
}
else if(buildInfo.IsGPChannel())
{
MergeProject(buildInfo, GoogleAsProjectPath);
FixGradleVersion(buildInfo.version_code, buildInfo.version);
}
return result;
}
/// <summary> /// <summary>
/// 合并dev工程 /// 合并工程
/// </summary> /// </summary>
static void MergeProject(BuildInfo buildInfo, String asProjectPath) static void MergeProject(BuildInfo buildInfo, String asProjectPath)
{ {
Debug.Log("[bfinfo]正在整合dev project..."); Debug.Log("[bfinfo]正在整合 project...");
var dir = Path.Combine(Application.dataPath, "../", AS_PROJECT_PATH, buildInfo.mode); var dir = Path.Combine(Application.dataPath, "../", AS_PROJECT_PATH, "publish_release");
var javaPath = Path.Combine(dir, "unityLibrary/src/main/java"); var javaPath = Path.Combine(dir, "unityLibrary/src/main/java");
var manifestPath = Path.Combine(dir, "unityLibrary/src/main/AndroidManifest.xml"); var manifestPath = Path.Combine(dir, "unityLibrary/src/main/AndroidManifest.xml");
// 老版本unity需要替换这个2021之后的新版本不需要
// 获取到unity打出的build-id // 获取到unity打出的build-id
var reader = new StreamReader(new FileStream(manifestPath, FileMode.Open)); // var reader = new StreamReader(new FileStream(manifestPath, FileMode.Open));
string buildIdLine; // string buildIdLine;
while ((buildIdLine = reader.ReadLine()) != null) // while ((buildIdLine = reader.ReadLine()) != null)
{ // {
if (buildIdLine.Contains("unity.build-id")) // if (buildIdLine.Contains("unity.build-id"))
{ // {
Debug.Log("[bfinfo]修正build-id: " + buildIdLine); // Debug.Log("[bfinfo]修正build-id: " + buildIdLine);
break; // break;
} // }
} // }
reader.Close(); // reader.Close();
reader.Dispose(); // reader.Dispose();
if (Directory.Exists(javaPath)) if (Directory.Exists(javaPath))
{ {
@ -326,71 +283,62 @@ namespace BFEditor.Build
di.Delete(true); di.Delete(true);
} }
BFEditorUtils.CopyDir(GoogleCommonProjectPath, dir); // 如果是俄罗斯支付 则需要覆盖为俄罗斯相关文件
// 获取到google_common复制过去的build.gradle和AndroidManifest // if (buildInfo.bundleName == BF.BFPlatform.ANDROID_GP_PACKAGE_NAME_RU)
var buildGradlePath = Path.Combine(dir, "launcher/build.gradle"); // {
var text = File.ReadAllText(buildGradlePath); // BFEditorUtils.CopyDir(RuProjectPath, dir);
var regex = new Regex("REPLACE_APPLICATION_ID"); // // 获取到build.gradle和AndroidManifest
text = regex.Replace(text, buildInfo.bundleName); // var buildGradlePath = Path.Combine(dir, "launcher/build.gradle");
File.WriteAllText(buildGradlePath, text); // var text = File.ReadAllText(buildGradlePath);
// var regex = new Regex("REPLACE_APPLICATION_ID");
// text = regex.Replace(text, buildInfo.bundleName);
// File.WriteAllText(buildGradlePath, text);
var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml"); // var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml");
text = File.ReadAllText(androidManifestPath); // text = File.ReadAllText(androidManifestPath);
regex = new Regex("REPLACE_APPLICATION_ID"); // regex = new Regex("REPLACE_APPLICATION_ID");
text = regex.Replace(text, buildInfo.bundleName); // text = regex.Replace(text, buildInfo.bundleName);
File.WriteAllText(androidManifestPath, text); // File.WriteAllText(androidManifestPath, text);
BFEditorUtils.CopyDir(asProjectPath, dir); // // 还有另一个AndroidManifest
// androidManifestPath = Path.Combine(dir, "unityLibrary/src/main/AndroidManifest.xml");
// text = File.ReadAllText(androidManifestPath);
// regex = new Regex("REPLACE_APPLICATION_ID");
// text = regex.Replace(text, buildInfo.bundleName);
// File.WriteAllText(androidManifestPath, text);
// }
// // 否则使用通用谷歌
// else
// {
BFEditorUtils.CopyDir(GoogleCommonProjectPath, dir);
// 获取到google_common复制过去的build.gradle和AndroidManifest
var buildGradlePath = Path.Combine(dir, "launcher/build.gradle");
var text = File.ReadAllText(buildGradlePath);
var regex = new Regex("REPLACE_APPLICATION_ID");
text = regex.Replace(text, buildInfo.bundleName);
File.WriteAllText(buildGradlePath, text);
text = File.ReadAllText(manifestPath); var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml");
regex = new Regex("REPLACE_BUILD_ID"); text = File.ReadAllText(androidManifestPath);
text = regex.Replace(text, buildIdLine); regex = new Regex("REPLACE_APPLICATION_ID");
File.WriteAllText(manifestPath, text); text = regex.Replace(text, buildInfo.bundleName);
} File.WriteAllText(androidManifestPath, text);
/// <summary> BFEditorUtils.CopyDir(asProjectPath, dir);
/// 合并gp工程 // 还有dz_google_apk下的AndroidManifest
/// </summary> androidManifestPath = Path.Combine(dir, "unityLibrary/src/main/AndroidManifest.xml");
static void MergeGPToReleaseProject(BuildInfo buildInfo) text = File.ReadAllText(androidManifestPath);
{ regex = new Regex("REPLACE_APPLICATION_ID");
Debug.Log("[bfinfo]正在整合gp渠道sdk..."); text = regex.Replace(text, buildInfo.bundleName);
File.WriteAllText(androidManifestPath, text);
var javaPath = GradleExcuteProjectPath + "/src/main/java"; // }
var manifestPath = GradleExcuteProjectPath + "/src/main/AndroidManifest.xml"; // 统一替换google-services文件
var gsPath = Path.Combine(GoogleServicesProjectPath, Path.Combine(buildInfo.bundleName, "google-services.json"));
// 获取到unity打出的build-id if (File.Exists(gsPath))
var reader = new StreamReader(new FileStream(manifestPath, FileMode.Open));
string buildIdLine;
while ((buildIdLine = reader.ReadLine()) != null)
{
if (buildIdLine.Contains("unity.build-id"))
{
Debug.Log("[bfinfo]修正build-id: " + buildIdLine);
break;
}
}
reader.Close();
reader.Dispose();
if (Directory.Exists(javaPath))
{
var di = new DirectoryInfo(javaPath);
di.Delete(true);
}
if (buildInfo.IsGPOfficial())
{ {
BFEditorUtils.CopyDir(GPOfficialAsProjectPath, GradleExcuteProjectPath); var destFilePath = Path.Combine(dir, "launcher/google-services.json");
File.Copy(gsPath, destFilePath, true);
} }
else
{
BFEditorUtils.CopyDir(GPAsProjectPath, GradleExcuteProjectPath);
}
var text = File.ReadAllText(manifestPath);
var regex = new Regex("REPLACE_BUILD_ID");
text = regex.Replace(text, buildIdLine);
File.WriteAllText(manifestPath, text);
} }
/// <summary> /// <summary>

View File

@ -1,348 +1,348 @@
#if UNITY_EDITOR_OSX // #if UNITY_EDITOR_OSX
using UnityEngine; // using UnityEngine;
using UnityEditor; // using UnityEditor;
using UnityEditor.Build.Reporting; // using UnityEditor.Build.Reporting;
using UnityEditor.iOS.Xcode; // using UnityEditor.iOS.Xcode;
using System.IO; // using System.IO;
#endif // #endif
namespace BFEditor.Build // namespace BFEditor.Build
{ // {
public static class BuildIOSUtils // public static class BuildIOSUtils
{ // {
#if UNITY_EDITOR_OSX // #if UNITY_EDITOR_OSX
const string IOS_DEFINE_SYMBOLS = "THREAD_SAFE;USE_AB"; // const string IOS_DEFINE_SYMBOLS = "THREAD_SAFE;USE_AB";
const string DEV_XCODE_LOCAL_PATH = "BFVersions/ios/dev"; // const string DEV_XCODE_LOCAL_PATH = "BFVersions/ios/dev";
const string RELEASE_XCODE_LOCAL_PATH = "BFVersions/ios/release"; // const string RELEASE_XCODE_LOCAL_PATH = "BFVersions/ios/release";
static string devXCodePath = Application.dataPath + "/../" + DEV_XCODE_LOCAL_PATH; // static string devXCodePath = Application.dataPath + "/../" + DEV_XCODE_LOCAL_PATH;
static string releaseXCodePath = Application.dataPath + "/../" + RELEASE_XCODE_LOCAL_PATH; // static string releaseXCodePath = Application.dataPath + "/../" + RELEASE_XCODE_LOCAL_PATH;
static string devOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dev/ExportOptions.plist"; // static string devOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dev/ExportOptions.plist";
static string releaseOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/release/ExportOptions.plist"; // static string releaseOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/release/ExportOptions.plist";
static string publishOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dis/ExportOptions.plist"; // static string publishOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dis/ExportOptions.plist";
public static bool BuildIOSPlayer(BuildInfo buildInfo) // public static bool BuildIOSPlayer(BuildInfo buildInfo)
{ // {
var buildTarget = BuildTarget.iOS; // var buildTarget = BuildTarget.iOS;
// 检查平台 // // 检查平台
if (EditorUserBuildSettings.activeBuildTarget != buildTarget) // if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
{ // {
Debug.LogError("[bferror]当前没有在对应平台"); // Debug.LogError("[bferror]当前没有在对应平台");
return false; // return false;
} // }
// 重新生成XLua // // 重新生成XLua
CompileScriptsUtils.RegenerateXLuaCode(true); // CompileScriptsUtils.RegenerateXLuaCode(true);
// 打包设置 // // 打包设置
BuildSettings(buildInfo); // BuildSettings(buildInfo);
// 开始打包 // // 开始打包
var bpOptions = GetBuildOptions(buildInfo); // var bpOptions = GetBuildOptions(buildInfo);
var report = BuildPipeline.BuildPlayer(bpOptions); // var report = BuildPipeline.BuildPlayer(bpOptions);
if (report.summary.result == BuildResult.Succeeded) // if (report.summary.result == BuildResult.Succeeded)
{ // {
return BuildIpaFromXCode(buildInfo); // return BuildIpaFromXCode(buildInfo);
} // }
else // else
{ // {
Debug.LogError("[bferror]unity打包xcode失败"); // Debug.LogError("[bferror]unity打包xcode失败");
return false; // return false;
} // }
} // }
/// <summary> // /// <summary>
/// 打包设置 // /// 打包设置
/// </summary> // /// </summary>
static void BuildSettings(BuildInfo buildInfo) // static void BuildSettings(BuildInfo buildInfo)
{ // {
// 设置bundleVersion // // 设置bundleVersion
PlayerSettings.bundleVersion = buildInfo.version; // PlayerSettings.bundleVersion = buildInfo.version;
// 设置buildNumber // // 设置buildNumber
PlayerSettings.iOS.buildNumber = buildInfo.version_code.ToString(); // PlayerSettings.iOS.buildNumber = buildInfo.versionCode.ToString();
// 设置竖屏 // // 设置竖屏
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait; // PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
PlayerSettings.allowedAutorotateToPortrait = false; // PlayerSettings.allowedAutorotateToPortrait = false;
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false; // PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
PlayerSettings.allowedAutorotateToLandscapeLeft = false; // PlayerSettings.allowedAutorotateToLandscapeLeft = false;
PlayerSettings.allowedAutorotateToLandscapeRight = false; // PlayerSettings.allowedAutorotateToLandscapeRight = false;
// 允许Xcode根据appleDeveloperTeamID自动签署应用程序 // // 允许Xcode根据appleDeveloperTeamID自动签署应用程序
PlayerSettings.iOS.appleEnableAutomaticSigning = !buildInfo.IsPublish(); // PlayerSettings.iOS.appleEnableAutomaticSigning = !buildInfo.IsPublish();
// 使用手动签名时iOS资源调配配置文件的类型自动 // // 使用手动签名时iOS资源调配配置文件的类型自动
PlayerSettings.iOS.iOSManualProvisioningProfileType = buildInfo.IsPublish() ? ProvisioningProfileType.Distribution : ProvisioningProfileType.Automatic; // PlayerSettings.iOS.iOSManualProvisioningProfileType = buildInfo.IsPublish() ? ProvisioningProfileType.Distribution : ProvisioningProfileType.Automatic;
// 关闭启动动画 // // 关闭启动动画
PlayerSettings.SplashScreen.show = false; // PlayerSettings.SplashScreen.show = false;
// 设置包名 // // 设置包名
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildInfo.bundleName); // PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildInfo.bundleName);
Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName); // Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName);
// 是否跳过版本控制 // // 是否跳过版本控制
var symbols = IOS_DEFINE_SYMBOLS; // var symbols = IOS_DEFINE_SYMBOLS;
if (buildInfo.skipVersion) // if (buildInfo.skipVersion)
{ // {
symbols = symbols + ";SKIP_VERSION;"; // symbols = symbols + ";SKIP_VERSION;";
} // }
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, symbols); // PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, symbols);
Debug.Log("[bfinfo]设置defineSymbols: " + symbols); // Debug.Log("[bfinfo]设置defineSymbols: " + symbols);
// 是否是dev // // 是否是dev
var development = buildInfo.IsDevChannel(); // var development = buildInfo.IsDevChannel();
EditorUserBuildSettings.development = development; // EditorUserBuildSettings.development = development;
// 商品名称 // // 商品名称
if (buildInfo.IsPublish()) // if (buildInfo.IsPublish())
{ // {
PlayerSettings.productName = "Heroic Expedition"; // PlayerSettings.productName = "Heroic Expedition";
} // }
else // else
{ // {
PlayerSettings.productName = development ? "b6-dev" : "b6-release"; // PlayerSettings.productName = development ? "b6-dev" : "b6-release";
} // }
// BuildType设置dev/release // // BuildType设置dev/release
EditorUserBuildSettings.iOSXcodeBuildConfig = development ? XcodeBuildConfig.Debug : XcodeBuildConfig.Release; // EditorUserBuildSettings.iOSXcodeBuildConfig = development ? XcodeBuildConfig.Debug : XcodeBuildConfig.Release;
// 使用IL2CPP // // 使用IL2CPP
var scriptImp = ScriptingImplementation.IL2CPP; // var scriptImp = ScriptingImplementation.IL2CPP;
PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, scriptImp); // PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, scriptImp);
// 目标平台架构目前支持ARM64 // // 目标平台架构目前支持ARM64
PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 1); // PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 1);
} // }
/// <summary> // /// <summary>
/// 获取打包参数 // /// 获取打包参数
/// </summary> // /// </summary>
static BuildPlayerOptions GetBuildOptions(BuildInfo buildInfo) // static BuildPlayerOptions GetBuildOptions(BuildInfo buildInfo)
{ // {
var bpOptions = new BuildPlayerOptions(); // var bpOptions = new BuildPlayerOptions();
bpOptions.scenes = AssetBundleUtils.GetBuildScenes(); // bpOptions.scenes = AssetBundleUtils.GetBuildScenes();
bpOptions.target = BuildTarget.iOS; // bpOptions.target = BuildTarget.iOS;
var path = buildInfo.IsReleaseChannel() ? RELEASE_XCODE_LOCAL_PATH : DEV_XCODE_LOCAL_PATH; // var path = buildInfo.IsReleaseChannel() ? RELEASE_XCODE_LOCAL_PATH : DEV_XCODE_LOCAL_PATH;
bpOptions.locationPathName = path; // bpOptions.locationPathName = path;
Debug.Log("[bfinfo]xcode path : " + path); // Debug.Log("[bfinfo]xcode path : " + path);
var absolutePath = buildInfo.IsReleaseChannel() ? releaseXCodePath : devXCodePath; // var absolutePath = buildInfo.IsReleaseChannel() ? releaseXCodePath : devXCodePath;
if (Directory.Exists(absolutePath)) // if (Directory.Exists(absolutePath))
{ // {
Directory.Delete(absolutePath, true); // Directory.Delete(absolutePath, true);
} // }
if (!buildInfo.IsPublish()) // if (!buildInfo.IsPublish())
{ // {
var options = BuildOptions.Development | BuildOptions.ConnectWithProfiler | BuildOptions.AllowDebugging; // var options = BuildOptions.Development | BuildOptions.ConnectWithProfiler | BuildOptions.AllowDebugging;
bpOptions.options = options; // bpOptions.options = options;
} // }
return bpOptions; // return bpOptions;
} // }
/// <summary> // /// <summary>
/// 打包ipa // /// 打包ipa
/// </summary> // /// </summary>
static bool BuildIpaFromXCode(BuildInfo buildInfo) // static bool BuildIpaFromXCode(BuildInfo buildInfo)
{ // {
// 修改XCode设置 // // 修改XCode设置
FixXCodeProject(buildInfo); // FixXCodeProject(buildInfo);
// 权限 // // 权限
UnlockKeyChain(); // UnlockKeyChain();
// archive // // archive
if (!Archive(buildInfo)) // if (!Archive(buildInfo))
{ // {
return false; // return false;
} // }
// 导出ipa // // 导出ipa
if (!ExportIpa(buildInfo)) // if (!ExportIpa(buildInfo))
{ // {
return false; // return false;
} // }
return true; // return true;
} // }
/// <summary> // /// <summary>
/// xCode工程设置 // /// xCode工程设置
/// </summary> // /// </summary>
static void FixXCodeProject(BuildInfo buildInfo) // static void FixXCodeProject(BuildInfo buildInfo)
{ // {
var isDev = buildInfo.IsDevChannel(); // var isDev = buildInfo.IsDevChannel();
var xCodeProjectPath = isDev ? devXCodePath : releaseXCodePath; // var xCodeProjectPath = isDev ? devXCodePath : releaseXCodePath;
var path = xCodeProjectPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; // var path = xCodeProjectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
var pbxProject = new PBXProject(); // var pbxProject = new PBXProject();
pbxProject.ReadFromFile(path); // pbxProject.ReadFromFile(path);
var targetGuid = pbxProject.TargetGuidByName("Unity-iPhone"); // var targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");
pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC"); // pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); // pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO"); // pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "49QQW8856Q"); // pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "49QQW8856Q");
if (buildInfo.IsPublish()) // if (buildInfo.IsPublish())
{ // {
pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", "ub_appstore_dis"); // pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", "ub_appstore_dis");
} // }
// 添加系统库 // // 添加系统库
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libsqlite3.tbd"); // AddSystemLibReferenceToProject(pbxProject, targetGuid, "libsqlite3.tbd");
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libz.1.tbd"); // AddSystemLibReferenceToProject(pbxProject, targetGuid, "libz.1.tbd");
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libiconv.2.tbd"); // AddSystemLibReferenceToProject(pbxProject, targetGuid, "libiconv.2.tbd");
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libresolv.9.tbd"); // AddSystemLibReferenceToProject(pbxProject, targetGuid, "libresolv.9.tbd");
var pListPath = Path.Combine(xCodeProjectPath, "Info.plist"); // var pListPath = Path.Combine(xCodeProjectPath, "Info.plist");
var pList = new PlistDocument(); // var pList = new PlistDocument();
pList.ReadFromFile(pListPath); // pList.ReadFromFile(pListPath);
// 版本号 // // 版本号
var vKey = "CFBundleShortVersionString"; // var vKey = "CFBundleShortVersionString";
var vValue = new PlistElementString(buildInfo.version); // var vValue = new PlistElementString(buildInfo.version);
var pListRoot = pList.root; // var pListRoot = pList.root;
var rootDict = pListRoot.values; // var rootDict = pListRoot.values;
if (!rootDict.ContainsKey(vKey)) // if (!rootDict.ContainsKey(vKey))
{ // {
rootDict.Add(vKey, vValue); // rootDict.Add(vKey, vValue);
} // }
else // else
{ // {
rootDict[vKey] = vValue; // rootDict[vKey] = vValue;
} // }
// VersionCode // // VersionCode
var vCodeKey = "CFBundleVersion"; // var vCodeKey = "CFBundleVersion";
var vCodeValue = new PlistElementString(buildInfo.version_code.ToString()); // var vCodeValue = new PlistElementString(buildInfo.versionCode.ToString());
if (!rootDict.ContainsKey(vCodeKey)) // if (!rootDict.ContainsKey(vCodeKey))
{ // {
rootDict.Add(vCodeKey, vCodeValue); // rootDict.Add(vCodeKey, vCodeValue);
} // }
else // else
{ // {
rootDict[vCodeKey] = vCodeValue; // rootDict[vCodeKey] = vCodeValue;
} // }
// 数美SDK会使用位置必须加入这个说明 // // 数美SDK会使用位置必须加入这个说明
var localtionKey = "NSLocationWhenInUseUsageDescription"; // var localtionKey = "NSLocationWhenInUseUsageDescription";
var localtionValue = new PlistElementString("We use your location to give you a better localization."); // var localtionValue = new PlistElementString("We use your location to give you a better localization.");
if (!rootDict.ContainsKey(localtionKey)) // if (!rootDict.ContainsKey(localtionKey))
{ // {
rootDict.Add(localtionKey, localtionValue); // rootDict.Add(localtionKey, localtionValue);
} // }
else // else
{ // {
rootDict[localtionKey] = localtionValue; // rootDict[localtionKey] = localtionValue;
} // }
// 提审提示缺少出口合规证明,这里直接设置为false即可 // // 提审提示缺少出口合规证明,这里直接设置为false即可
var encryptionKey = "ITSAppUsesNonExemptEncryption"; // var encryptionKey = "ITSAppUsesNonExemptEncryption";
var encryptionValue = new PlistElementBoolean(false); // var encryptionValue = new PlistElementBoolean(false);
if (!rootDict.ContainsKey(encryptionKey)) // if (!rootDict.ContainsKey(encryptionKey))
{ // {
rootDict.Add(encryptionKey, encryptionValue); // rootDict.Add(encryptionKey, encryptionValue);
} // }
else // else
{ // {
rootDict[encryptionKey] = encryptionValue; // rootDict[encryptionKey] = encryptionValue;
} // }
pList.WriteToFile(pListPath); // pList.WriteToFile(pListPath);
pbxProject.WriteToFile(path); // pbxProject.WriteToFile(path);
} // }
//添加系统lib方法 // //添加系统lib方法
static void AddSystemLibReferenceToProject(PBXProject pbxProject, string targetGuid, string lib) // static void AddSystemLibReferenceToProject(PBXProject pbxProject, string targetGuid, string lib)
{ // {
var fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk); // var fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);
pbxProject.AddFileToBuild(targetGuid, fileGuid); // pbxProject.AddFileToBuild(targetGuid, fileGuid);
} // }
/// <summary> // /// <summary>
/// Archive // /// Archive
/// </summary> // /// </summary>
static bool Archive(BuildInfo buildInfo) // static bool Archive(BuildInfo buildInfo)
{ // {
Debug.Log("[bfinfo]正在archive..."); // Debug.Log("[bfinfo]正在archive...");
var result = true; // var result = true;
var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath; // var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive"; // var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
var args = string.Format("archive -scheme Unity-iPhone -configuration Release -archivePath {0}", archivePath); // var args = string.Format("archive -scheme Unity-iPhone -configuration Release -archivePath {0}", archivePath);
BFEditorUtils.RunCommond("xcodebuild", args, xCodeProjectPath, // BFEditorUtils.RunCommond("xcodebuild", args, xCodeProjectPath,
(info) => // (info) =>
{ // {
Debug.Log(info); // Debug.Log(info);
}, // },
(error) => // (error) =>
{ // {
if (error.Contains("ARCHIVE FAILED")) // 失败标志 // if (error.Contains("ARCHIVE FAILED")) // 失败标志
{ // {
result = false; // result = false;
} // }
Debug.LogError("[bferror] " + error); // Debug.LogError("[bferror] " + error);
} // }
); // );
return result; // return result;
} // }
/// <summary> // /// <summary>
/// 导出ipa // /// 导出ipa
/// </summary> // /// </summary>
static bool ExportIpa(BuildInfo buildInfo) // static bool ExportIpa(BuildInfo buildInfo)
{ // {
Debug.Log("[bfinfo]正在导出ipa..."); // Debug.Log("[bfinfo]正在导出ipa...");
var result = false; // var result = false;
var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath; // var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
string exportPListPath; // string exportPListPath;
if (buildInfo.IsPublish()) // if (buildInfo.IsPublish())
{ // {
exportPListPath = publishOptionsPListPath; // exportPListPath = publishOptionsPListPath;
} // }
else // else
{ // {
exportPListPath = buildInfo.IsDevChannel() ? devOptionsPListPath : releaseOptionsPListPath; // exportPListPath = buildInfo.IsDevChannel() ? devOptionsPListPath : releaseOptionsPListPath;
} // }
var ipaPath = xCodeProjectPath + "/build/ipa"; // var ipaPath = xCodeProjectPath + "/build/ipa";
var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive"; // var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
var args = string.Format("-exportArchive -archivePath {0} -exportPath {1} -exportOptionsPlist {2} -allowProvisioningUpdates", archivePath, ipaPath, exportPListPath); // var args = string.Format("-exportArchive -archivePath {0} -exportPath {1} -exportOptionsPlist {2} -allowProvisioningUpdates", archivePath, ipaPath, exportPListPath);
BFEditorUtils.RunCommond("xcodebuild", args, null, // BFEditorUtils.RunCommond("xcodebuild", args, null,
(info) => // (info) =>
{ // {
if(info.Contains("EXPORT SUCCEEDED")) // if(info.Contains("EXPORT SUCCEEDED"))
{ // {
result = true; // result = true;
} // }
}, // },
(error) => // (error) =>
{ // {
} // }
); // );
return result; // return result;
} // }
/// <summary> // /// <summary>
/// 远程打包签名ipa时需要钥匙串权限 // /// 远程打包签名ipa时需要钥匙串权限
/// </summary> // /// </summary>
static void UnlockKeyChain() // static void UnlockKeyChain()
{ // {
BFEditorUtils.RunCommond("security", "-v unlock-keychain -p '123456' /Users/aoddabao/Library/Keychains/login.keychain-db", null, // BFEditorUtils.RunCommond("security", "-v unlock-keychain -p '123456' /Users/aoddabao/Library/Keychains/login.keychain-db", null,
(msg) => // (msg) =>
{ // {
Debug.Log(msg); // Debug.Log(msg);
}, // },
(msg) => // (msg) =>
{ // {
Debug.LogError(msg); // Debug.LogError(msg);
} // }
); // );
} // }
#endif // #endif
} // }
} // }