build
This commit is contained in:
parent
4ce72abeb5
commit
d351d4549f
@ -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]
|
||||
public class BuildInfo
|
||||
{
|
||||
public string bundleName; // 包名
|
||||
public string version; // 版本号
|
||||
public string mode; // 渠道名_debug 或 渠道名_release
|
||||
public int version_code = 1; // 各自渠道的version_code
|
||||
public string mode; // 内网测试包,外网测试包,外网正式包
|
||||
public int versionCode = 1; // 各自渠道的version code
|
||||
public List<BulidGitInfo> git_info; // 打包的git信息
|
||||
public bool exportProject = false; // 是否只导出工程
|
||||
public bool onlyAssetBundle = false; // 是否只打ab包
|
||||
|
||||
[NonSerialized]
|
||||
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()
|
||||
{
|
||||
return !IsDevChannel() && !IsLanRelease();
|
||||
return mode == BuildMode.PUBLISH;
|
||||
}
|
||||
|
||||
public bool IsIOSPlatform()
|
||||
{
|
||||
return bundleName.Contains("ios");
|
||||
}
|
||||
|
||||
public bool IsAndroidPlatform()
|
||||
{
|
||||
return !IsIOSPlatform();
|
||||
}
|
||||
|
||||
public string GetBundleName()
|
||||
{
|
||||
return bundleName;
|
||||
|
||||
@ -48,6 +48,12 @@ namespace BFEditor.Build
|
||||
return false;
|
||||
}
|
||||
|
||||
// 只打ab包
|
||||
if (buildInfo.onlyAssetBundle)
|
||||
{
|
||||
AssetDatabase.Refresh();
|
||||
return true;
|
||||
}
|
||||
// 删除不进包的多语言
|
||||
// if (!DeleteOverLanguageAb(buildInfo))
|
||||
// {
|
||||
@ -73,19 +79,10 @@ namespace BFEditor.Build
|
||||
watch.Start();
|
||||
|
||||
var result = false;
|
||||
|
||||
if (buildInfo.IsAndroidPlatform() && BuildAndroidUtils.BuildAndroidPlayer(buildInfo))
|
||||
if (BuildAndroidUtils.BuildAndroidPlayer(buildInfo))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR_OSX
|
||||
if (buildInfo.IsIOSPlatform() && BuildIOSUtils.BuildIOSPlayer(buildInfo))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (result)
|
||||
{
|
||||
watch.Stop();
|
||||
@ -140,8 +137,7 @@ namespace BFEditor.Build
|
||||
var watch = new System.Diagnostics.Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
// var buildTarget = buildInfo.IsIOSPlatform() ? BuildTarget.iOS : BuildTarget.Android;
|
||||
var isRelease = buildInfo.IsReleaseChannel();
|
||||
var isRelease = true;
|
||||
Debug.Log("[bfinfo]开始打包资源, bundleName : " + buildInfo.bundleName + " version : " + buildInfo.version + " mode : " + buildInfo.mode);
|
||||
|
||||
// // 检查平台
|
||||
@ -197,7 +193,7 @@ namespace BFEditor.Build
|
||||
}
|
||||
|
||||
// 本地缓存ab
|
||||
if (buildInfo.IsReleaseChannel())
|
||||
if (buildInfo.IsPublish())
|
||||
{
|
||||
Debug.Log("[bfinfo]正在缓存assetbundles...");
|
||||
BFEditorUtils.CopyDirWithIgnore(outputPath, Path.Combine(AssetBundleCachePath, buildInfo.version), new List<string> { ".meta" });
|
||||
|
||||
@ -6,77 +6,116 @@ namespace BFEditor.Build
|
||||
public enum BFPlatformOptions
|
||||
{
|
||||
AndroidDev = 1,
|
||||
IOSDev,
|
||||
AndroidRelease,
|
||||
AndroidTest,
|
||||
AndroidGP,
|
||||
AndroidGPRU
|
||||
}
|
||||
|
||||
public class BuildProjectWindow : EditorWindow
|
||||
{
|
||||
private static int versionCode = 18;
|
||||
private static string versionName = "1.6.5";
|
||||
private static int VersionCode = 4;
|
||||
private static string VersionName = "1.2.10";
|
||||
private static int VersionCodeRU = 12;
|
||||
private static string VersionNameRU = "0.4.9";
|
||||
BFPlatformOptions platform = BFPlatformOptions.AndroidDev;
|
||||
const string ANDROID_DEV_PACKAGE_NAME = "com.juzu.b6.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";
|
||||
|
||||
const string ANDROID_GP_PACKAGE_NAME = "com.c1.dev.android";
|
||||
|
||||
public BuildProjectWindow()
|
||||
{
|
||||
titleContent = new GUIContent("打包");
|
||||
}
|
||||
{
|
||||
titleContent = new GUIContent("打包");
|
||||
}
|
||||
|
||||
private void OnEnable() { }
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
|
||||
EditorGUILayout.LabelField("选择渠道");
|
||||
platform = (BFPlatformOptions)EditorGUILayout.EnumPopup("", platform);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("版本: " + versionName);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
string packageName;
|
||||
string mode;
|
||||
string versionName = VersionName;
|
||||
int versionCode = VersionCode;
|
||||
bool skipVersion = false;
|
||||
string appType;
|
||||
if (platform == BFPlatformOptions.AndroidDev)
|
||||
{
|
||||
packageName = ANDROID_DEV_PACKAGE_NAME;
|
||||
packageName = ANDROID_GP_PACKAGE_NAME;
|
||||
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;
|
||||
mode = "release_release";
|
||||
packageName = ANDROID_GP_PACKAGE_NAME;
|
||||
mode = BuildMode.TEST;
|
||||
versionName = "0.1.0";
|
||||
versionCode = 1;
|
||||
appType = "外网测试包";
|
||||
}
|
||||
else if(platform == BFPlatformOptions.AndroidGP)
|
||||
{
|
||||
packageName = ANDROID_GP_PACKAGE_NAME;
|
||||
mode = "publish_release";
|
||||
mode = BuildMode.PUBLISH;
|
||||
appType = "外网正式包";
|
||||
}
|
||||
else
|
||||
{
|
||||
packageName = IOS_PACKAGE_NAME;
|
||||
mode = "dev_debug";
|
||||
packageName = ANDROID_GP_PACKAGE_NAME;
|
||||
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("mode: " + mode);
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(appType);
|
||||
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.version = versionName;
|
||||
buildInfo.version_code = versionCode;
|
||||
buildInfo.mode = mode;
|
||||
buildInfo.bundleName = packageName;
|
||||
buildInfo.skipVersion = skipVersion;
|
||||
buildInfo.exportProject = false;
|
||||
buildInfo.onlyAssetBundle = false;
|
||||
BuildProjectTools.BuildBFPlayer(buildInfo);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -3,12 +3,12 @@ using UnityEditor;
|
||||
using System.IO;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BFEditor.Build
|
||||
{
|
||||
{
|
||||
public static class BuildAndroidUtils
|
||||
{
|
||||
const string JAVA_HOME_ENVIRONMENT = "JAVA_HOME";
|
||||
@ -18,19 +18,19 @@ namespace BFEditor.Build
|
||||
const string GRADLE_PATH = "/Users/aoddabao/.gradle/wrapper/dists/gradle-5.6.4-all/ankdp27end7byghfw1q2sw75f/gradle-5.6.4/bin/gradle";
|
||||
const string BUGLY_APP_ID = "1eb4e5e560";
|
||||
const string BUGLY_APP_KEY = "99e249db-4eeb-440e-83e7-c2bd80e8b5e4";
|
||||
|
||||
|
||||
static Thread buglyUploadThread;
|
||||
static string ReleaseSOPath = Application.dataPath + "/../BFVersions/android/ub-release/src/main/jniLibs";
|
||||
static string BuglyPath = Application.dataPath + "/../Bugly";
|
||||
static string BuglySOPath = Application.dataPath + "/../Bugly/so";
|
||||
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 GoogleCommonProjectPath = Application.dataPath + "/../BFVersions/android/google_common";
|
||||
static string GPAsProjectPath = Application.dataPath + "/../BFVersions/android/ub-gp"; // gp删档测试渠道
|
||||
static string GPOfficialAsProjectPath = Application.dataPath + "/../BFVersions/android/ub-google"; // gp正式渠道
|
||||
static string RuStoreProjectPath = Application.dataPath + "/../BFVersions/android/ru_store";
|
||||
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 KeystoreFilePath = Application.dataPath + "/../BFVersions/android/keystore/dz_keystore.txt";
|
||||
static string SignShellPath = Application.dataPath + "/../BFFiles/androidkey";
|
||||
static string GpAlginShellPath = Application.dataPath + "/../BFFiles/androidkey";
|
||||
static HashSet<string> AABInPackageFileHashSet = new HashSet<string>()
|
||||
@ -38,12 +38,12 @@ namespace BFEditor.Build
|
||||
"bin",
|
||||
"UnityServicesProjectConfiguration.json"
|
||||
};
|
||||
|
||||
|
||||
static BuildAndroidUtils()
|
||||
{
|
||||
EnsureJavaHome();
|
||||
}
|
||||
|
||||
|
||||
public static void EnsureJavaHome()
|
||||
{
|
||||
// var javaHomeEnvironment = Environment.GetEnvironmentVariable(JAVA_HOME_ENVIRONMENT);
|
||||
@ -52,35 +52,44 @@ namespace BFEditor.Build
|
||||
// Environment.SetEnvironmentVariable(JAVA_HOME_ENVIRONMENT, JAVA_HOME_ENVIRONMENT_PATH);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打包android
|
||||
/// </summary>
|
||||
public static bool BuildAndroidPlayer(BuildInfo buildInfo)
|
||||
{
|
||||
var buildTarget = BuildTarget.Android;
|
||||
|
||||
|
||||
// 检查平台
|
||||
if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
|
||||
{
|
||||
Debug.LogError("[bferror]当前没有在对应平台");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 重新生成XLua
|
||||
CompileScriptsUtils.RegenerateXLuaCode(true);
|
||||
|
||||
|
||||
// 打包设置
|
||||
BuildSettings(buildInfo);
|
||||
|
||||
|
||||
// 开始打包
|
||||
var bpOptions = GetBuildOptions(buildInfo);
|
||||
var report = BuildPipeline.BuildPlayer(bpOptions);
|
||||
|
||||
// 打包成功
|
||||
|
||||
// 导出工程成功
|
||||
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
|
||||
{
|
||||
@ -88,7 +97,7 @@ namespace BFEditor.Build
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打包设置
|
||||
/// </summary>
|
||||
@ -96,66 +105,58 @@ namespace BFEditor.Build
|
||||
{
|
||||
// 设置bundleVersion
|
||||
PlayerSettings.bundleVersion = buildInfo.version;
|
||||
|
||||
|
||||
// 设置VersionCode
|
||||
PlayerSettings.Android.bundleVersionCode = buildInfo.version_code;
|
||||
|
||||
PlayerSettings.Android.bundleVersionCode = buildInfo.versionCode;
|
||||
|
||||
// 设置竖屏
|
||||
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
|
||||
PlayerSettings.allowedAutorotateToPortrait = false;
|
||||
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
|
||||
PlayerSettings.allowedAutorotateToLandscapeLeft = false;
|
||||
PlayerSettings.allowedAutorotateToLandscapeRight = false;
|
||||
|
||||
|
||||
// 安卓构建目标CPU架构
|
||||
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64;
|
||||
|
||||
|
||||
// 强加Internet权限
|
||||
PlayerSettings.Android.forceInternetPermission = true;
|
||||
|
||||
|
||||
// 关闭启动动画
|
||||
PlayerSettings.SplashScreen.show = false;
|
||||
|
||||
|
||||
// 设置包名
|
||||
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, buildInfo.bundleName);
|
||||
Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName);
|
||||
|
||||
|
||||
// 跳过版本控制
|
||||
var symbols = ANDROID_DEFINE_SYMBOLS;
|
||||
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);
|
||||
Debug.Log("[bfinfo]设置defineSymbols: " + symbols);
|
||||
|
||||
// 是否是dev
|
||||
var development = buildInfo.IsDevChannel() ? true : false;
|
||||
EditorUserBuildSettings.development = development;
|
||||
|
||||
// 商品名称
|
||||
// 应用名
|
||||
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;
|
||||
|
||||
PlayerSettings.productName = "Pull Pull Pull Heroes";
|
||||
EditorUserBuildSettings.development = false;
|
||||
EditorUserBuildSettings.androidBuildType = AndroidBuildType.Release;
|
||||
|
||||
// 是否导出as工程
|
||||
// EditorUserBuildSettings.exportAsGoogleAndroidProject = development ? false : true;
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
||||
|
||||
// dev使用Mono release使用IL2CPP
|
||||
var scriptImp = development ? ScriptingImplementation.Mono2x : ScriptingImplementation.IL2CPP;
|
||||
|
||||
var scriptImp = ScriptingImplementation.IL2CPP;
|
||||
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, scriptImp);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取打包参数
|
||||
/// </summary>
|
||||
@ -164,43 +165,23 @@ namespace BFEditor.Build
|
||||
var bpOptions = new BuildPlayerOptions();
|
||||
bpOptions.scenes = AssetBundleUtils.GetBuildScenes();
|
||||
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);
|
||||
|
||||
BuildOptions options;
|
||||
if (buildInfo.IsReleaseChannel())
|
||||
{
|
||||
options = BuildOptions.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
options = BuildOptions.Development;
|
||||
}
|
||||
|
||||
|
||||
BuildOptions options = BuildOptions.None;
|
||||
bpOptions.options = options;
|
||||
return bpOptions;
|
||||
}
|
||||
|
||||
|
||||
static string GetDevApkPathName(BuildInfo buildInfo)
|
||||
{
|
||||
var apkName = buildInfo.skipVersion ? "dz_dev_skip_version.apk" : "dz_dev_debug.apk";
|
||||
var path = Path.Combine(AS_PROJECT_PATH, apkName);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
@ -208,32 +189,53 @@ namespace BFEditor.Build
|
||||
return dir;
|
||||
}
|
||||
|
||||
static bool BuildAPK(BuildInfo buildInfo)
|
||||
static bool BuildAPK(BuildInfo buildInfo, bool isAAB = false)
|
||||
{
|
||||
if (buildInfo.IsGPChannel())
|
||||
{
|
||||
MergeGPToReleaseProject(buildInfo);
|
||||
FixGradleVersion(buildInfo.version_code, buildInfo.version);
|
||||
}
|
||||
|
||||
if (buildInfo.IsLanRelease())
|
||||
{
|
||||
AddBuglyParamsToReleaseProject();
|
||||
}
|
||||
|
||||
// 设置jdk环境变量
|
||||
string javaHomePath = System.Environment.GetEnvironmentVariable("JAVE_HOME");
|
||||
if (string.IsNullOrEmpty(javaHomePath))
|
||||
{
|
||||
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 (File.Exists(KeystoreFilePath))
|
||||
{
|
||||
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...");
|
||||
var success = true;
|
||||
var args = "";
|
||||
if (buildInfo.IsReleaseChannel())
|
||||
{
|
||||
args += " assembleRelease";
|
||||
}
|
||||
else
|
||||
{
|
||||
args += " assembleDebug";
|
||||
}
|
||||
|
||||
BFEditorUtils.RunCommond(GRADLE_PATH, args, GradleExcuteProjectPath,
|
||||
var args = "assembleRelease";
|
||||
if (isAAB)
|
||||
{
|
||||
args = "bundleRelease";
|
||||
}
|
||||
string gradleHomePath = System.Environment.GetEnvironmentVariable("GRADLE_HOME");
|
||||
if (string.IsNullOrEmpty(gradleHomePath))
|
||||
{
|
||||
Debug.LogError("[bferror] 找不到环境变量GRADLE_HOME");
|
||||
return false;
|
||||
}
|
||||
#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) =>
|
||||
{
|
||||
},
|
||||
@ -245,80 +247,35 @@ namespace BFEditor.Build
|
||||
Debug.LogError("[bferror] " + errorMsg);
|
||||
}
|
||||
});
|
||||
|
||||
if (buildInfo.IsGPChannel())
|
||||
{
|
||||
// 尝试制作并上传bugly符号表 开新Thread不影响打包流程
|
||||
if (success)
|
||||
{
|
||||
CopySOAndUploadBuglySymbol(buildInfo.bundleName, buildInfo.version);
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
/// 合并dev工程
|
||||
/// 合并工程
|
||||
/// </summary>
|
||||
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 manifestPath = Path.Combine(dir, "unityLibrary/src/main/AndroidManifest.xml");
|
||||
|
||||
// 老版本unity需要替换这个,2021之后的新版本不需要
|
||||
// 获取到unity打出的build-id
|
||||
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();
|
||||
// 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))
|
||||
{
|
||||
@ -326,71 +283,62 @@ namespace BFEditor.Build
|
||||
di.Delete(true);
|
||||
}
|
||||
|
||||
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);
|
||||
// 如果是俄罗斯支付 则需要覆盖为俄罗斯相关文件
|
||||
// if (buildInfo.bundleName == BF.BFPlatform.ANDROID_GP_PACKAGE_NAME_RU)
|
||||
// {
|
||||
// BFEditorUtils.CopyDir(RuProjectPath, dir);
|
||||
// // 获取到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);
|
||||
|
||||
var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml");
|
||||
text = File.ReadAllText(androidManifestPath);
|
||||
regex = new Regex("REPLACE_APPLICATION_ID");
|
||||
text = regex.Replace(text, buildInfo.bundleName);
|
||||
File.WriteAllText(androidManifestPath, text);
|
||||
// var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml");
|
||||
// text = File.ReadAllText(androidManifestPath);
|
||||
// regex = new Regex("REPLACE_APPLICATION_ID");
|
||||
// text = regex.Replace(text, buildInfo.bundleName);
|
||||
// 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);
|
||||
regex = new Regex("REPLACE_BUILD_ID");
|
||||
text = regex.Replace(text, buildIdLine);
|
||||
File.WriteAllText(manifestPath, text);
|
||||
}
|
||||
var androidManifestPath = Path.Combine(dir, "launcher/src/main/AndroidManifest.xml");
|
||||
text = File.ReadAllText(androidManifestPath);
|
||||
regex = new Regex("REPLACE_APPLICATION_ID");
|
||||
text = regex.Replace(text, buildInfo.bundleName);
|
||||
File.WriteAllText(androidManifestPath, text);
|
||||
|
||||
/// <summary>
|
||||
/// 合并gp工程
|
||||
/// </summary>
|
||||
static void MergeGPToReleaseProject(BuildInfo buildInfo)
|
||||
{
|
||||
Debug.Log("[bfinfo]正在整合gp渠道sdk...");
|
||||
|
||||
var javaPath = GradleExcuteProjectPath + "/src/main/java";
|
||||
var manifestPath = GradleExcuteProjectPath + "/src/main/AndroidManifest.xml";
|
||||
|
||||
// 获取到unity打出的build-id
|
||||
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(asProjectPath, dir);
|
||||
// 还有dz_google_apk下的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);
|
||||
// }
|
||||
// 统一替换google-services文件
|
||||
var gsPath = Path.Combine(GoogleServicesProjectPath, Path.Combine(buildInfo.bundleName, "google-services.json"));
|
||||
if (File.Exists(gsPath))
|
||||
{
|
||||
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>
|
||||
@ -413,7 +361,7 @@ namespace BFEditor.Build
|
||||
text2 = regex2.Replace(text2, string.Format("versionName '{0}'", versionName));
|
||||
File.WriteAllText(gradleFilePath2, text2);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 内网Release包接入Bugly
|
||||
/// </summary>
|
||||
@ -429,7 +377,7 @@ namespace BFEditor.Build
|
||||
"implementation 'com.tencent.bugly:crashreport:latest.release'\n" +
|
||||
"implementation 'com.tencent.bugly:nativecrashreport:latest.release'\n");
|
||||
File.WriteAllText(gradleFilePath, text);
|
||||
|
||||
|
||||
// 修改AndroidManifest.xml
|
||||
var manifestPath = GradleExcuteProjectPath + "/src/main/AndroidManifest.xml";
|
||||
text = File.ReadAllText(manifestPath);
|
||||
@ -442,7 +390,7 @@ namespace BFEditor.Build
|
||||
"<uses-permission android:name='android.permission.READ_LOGS' />\n" +
|
||||
"<uses-permission android:name='android.permission.POST_NOTIFICATIONS'/>\n");
|
||||
File.WriteAllText(manifestPath, text);
|
||||
|
||||
|
||||
// 修改UnityPlayerActivity.java
|
||||
var javaPath = GradleExcuteProjectPath + "/src/main/java/com/juzu/ub/release/android/UnityPlayerActivity.java";
|
||||
text = File.ReadAllText(javaPath);
|
||||
@ -458,7 +406,7 @@ namespace BFEditor.Build
|
||||
text = text.Insert(index + length, formatInsertString);
|
||||
File.WriteAllText(javaPath, text);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// release包加密后签名
|
||||
/// </summary>
|
||||
@ -477,7 +425,7 @@ namespace BFEditor.Build
|
||||
});
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// gp包对齐
|
||||
/// </summary>
|
||||
@ -524,7 +472,7 @@ namespace BFEditor.Build
|
||||
{
|
||||
// 将release的so复制到bugly文件下
|
||||
BFEditorUtils.CopyDir(ReleaseSOPath, BuglySOPath);
|
||||
|
||||
|
||||
// 开启Thread处理打包so和上传
|
||||
TryCloseUploadThread();
|
||||
var args = "bugly.sh" + " " + BUGLY_APP_ID + " " + BUGLY_APP_KEY + " " + bundleName + " " + version;
|
||||
@ -532,7 +480,7 @@ namespace BFEditor.Build
|
||||
buglyUploadThread.IsBackground = true;
|
||||
buglyUploadThread.Start();
|
||||
}
|
||||
|
||||
|
||||
static void UploadBuglySymbol(string args)
|
||||
{
|
||||
BFEditorUtils.RunCommond("sh", args, BuglyPath,
|
||||
@ -544,10 +492,10 @@ namespace BFEditor.Build
|
||||
{
|
||||
Debug.LogError("[bferror] UploadBuglySymbol: " + errorMsg);
|
||||
});
|
||||
|
||||
|
||||
TryCloseUploadThread();
|
||||
}
|
||||
|
||||
|
||||
static void TryCloseUploadThread()
|
||||
{
|
||||
if (buglyUploadThread != null)
|
||||
|
||||
@ -1,348 +1,348 @@
|
||||
#if UNITY_EDITOR_OSX
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using System.IO;
|
||||
#endif
|
||||
// #if UNITY_EDITOR_OSX
|
||||
// using UnityEngine;
|
||||
// using UnityEditor;
|
||||
// using UnityEditor.Build.Reporting;
|
||||
// using UnityEditor.iOS.Xcode;
|
||||
// using System.IO;
|
||||
// #endif
|
||||
|
||||
namespace BFEditor.Build
|
||||
{
|
||||
public static class BuildIOSUtils
|
||||
{
|
||||
#if UNITY_EDITOR_OSX
|
||||
const string IOS_DEFINE_SYMBOLS = "THREAD_SAFE;USE_AB";
|
||||
const string DEV_XCODE_LOCAL_PATH = "BFVersions/ios/dev";
|
||||
const string RELEASE_XCODE_LOCAL_PATH = "BFVersions/ios/release";
|
||||
// namespace BFEditor.Build
|
||||
// {
|
||||
// public static class BuildIOSUtils
|
||||
// {
|
||||
// #if UNITY_EDITOR_OSX
|
||||
// const string IOS_DEFINE_SYMBOLS = "THREAD_SAFE;USE_AB";
|
||||
// const string DEV_XCODE_LOCAL_PATH = "BFVersions/ios/dev";
|
||||
// const string RELEASE_XCODE_LOCAL_PATH = "BFVersions/ios/release";
|
||||
|
||||
static string devXCodePath = Application.dataPath + "/../" + DEV_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 releaseOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/release/ExportOptions.plist";
|
||||
static string publishOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dis/ExportOptions.plist";
|
||||
// static string devXCodePath = Application.dataPath + "/../" + DEV_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 releaseOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/release/ExportOptions.plist";
|
||||
// static string publishOptionsPListPath = Application.dataPath + "/../" + "BFVersions/ios/exports/dis/ExportOptions.plist";
|
||||
|
||||
public static bool BuildIOSPlayer(BuildInfo buildInfo)
|
||||
{
|
||||
var buildTarget = BuildTarget.iOS;
|
||||
// public static bool BuildIOSPlayer(BuildInfo buildInfo)
|
||||
// {
|
||||
// var buildTarget = BuildTarget.iOS;
|
||||
|
||||
// 检查平台
|
||||
if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
|
||||
{
|
||||
Debug.LogError("[bferror]当前没有在对应平台");
|
||||
return false;
|
||||
}
|
||||
// // 检查平台
|
||||
// if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
|
||||
// {
|
||||
// Debug.LogError("[bferror]当前没有在对应平台");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// 重新生成XLua
|
||||
CompileScriptsUtils.RegenerateXLuaCode(true);
|
||||
// // 重新生成XLua
|
||||
// CompileScriptsUtils.RegenerateXLuaCode(true);
|
||||
|
||||
// 打包设置
|
||||
BuildSettings(buildInfo);
|
||||
// // 打包设置
|
||||
// BuildSettings(buildInfo);
|
||||
|
||||
// 开始打包
|
||||
var bpOptions = GetBuildOptions(buildInfo);
|
||||
var report = BuildPipeline.BuildPlayer(bpOptions);
|
||||
if (report.summary.result == BuildResult.Succeeded)
|
||||
{
|
||||
return BuildIpaFromXCode(buildInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[bferror]unity打包xcode失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// // 开始打包
|
||||
// var bpOptions = GetBuildOptions(buildInfo);
|
||||
// var report = BuildPipeline.BuildPlayer(bpOptions);
|
||||
// if (report.summary.result == BuildResult.Succeeded)
|
||||
// {
|
||||
// return BuildIpaFromXCode(buildInfo);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("[bferror]unity打包xcode失败");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 打包设置
|
||||
/// </summary>
|
||||
static void BuildSettings(BuildInfo buildInfo)
|
||||
{
|
||||
// 设置bundleVersion
|
||||
PlayerSettings.bundleVersion = buildInfo.version;
|
||||
// /// <summary>
|
||||
// /// 打包设置
|
||||
// /// </summary>
|
||||
// static void BuildSettings(BuildInfo buildInfo)
|
||||
// {
|
||||
// // 设置bundleVersion
|
||||
// PlayerSettings.bundleVersion = buildInfo.version;
|
||||
|
||||
// 设置buildNumber
|
||||
PlayerSettings.iOS.buildNumber = buildInfo.version_code.ToString();
|
||||
// // 设置buildNumber
|
||||
// PlayerSettings.iOS.buildNumber = buildInfo.versionCode.ToString();
|
||||
|
||||
// 设置竖屏
|
||||
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
|
||||
PlayerSettings.allowedAutorotateToPortrait = false;
|
||||
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
|
||||
PlayerSettings.allowedAutorotateToLandscapeLeft = false;
|
||||
PlayerSettings.allowedAutorotateToLandscapeRight = false;
|
||||
// // 设置竖屏
|
||||
// PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
|
||||
// PlayerSettings.allowedAutorotateToPortrait = false;
|
||||
// PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
|
||||
// PlayerSettings.allowedAutorotateToLandscapeLeft = false;
|
||||
// PlayerSettings.allowedAutorotateToLandscapeRight = false;
|
||||
|
||||
// 允许Xcode根据appleDeveloperTeamID自动签署应用程序
|
||||
PlayerSettings.iOS.appleEnableAutomaticSigning = !buildInfo.IsPublish();
|
||||
// // 允许Xcode根据appleDeveloperTeamID自动签署应用程序
|
||||
// PlayerSettings.iOS.appleEnableAutomaticSigning = !buildInfo.IsPublish();
|
||||
|
||||
// 使用手动签名时iOS资源调配配置文件的类型,自动
|
||||
PlayerSettings.iOS.iOSManualProvisioningProfileType = buildInfo.IsPublish() ? ProvisioningProfileType.Distribution : ProvisioningProfileType.Automatic;
|
||||
// // 使用手动签名时iOS资源调配配置文件的类型,自动
|
||||
// PlayerSettings.iOS.iOSManualProvisioningProfileType = buildInfo.IsPublish() ? ProvisioningProfileType.Distribution : ProvisioningProfileType.Automatic;
|
||||
|
||||
// 关闭启动动画
|
||||
PlayerSettings.SplashScreen.show = false;
|
||||
// // 关闭启动动画
|
||||
// PlayerSettings.SplashScreen.show = false;
|
||||
|
||||
// 设置包名
|
||||
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildInfo.bundleName);
|
||||
Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName);
|
||||
// // 设置包名
|
||||
// PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildInfo.bundleName);
|
||||
// Debug.Log("[bfinfo]设置包名:" + buildInfo.bundleName);
|
||||
|
||||
// 是否跳过版本控制
|
||||
var symbols = IOS_DEFINE_SYMBOLS;
|
||||
if (buildInfo.skipVersion)
|
||||
{
|
||||
symbols = symbols + ";SKIP_VERSION;";
|
||||
}
|
||||
// // 是否跳过版本控制
|
||||
// var symbols = IOS_DEFINE_SYMBOLS;
|
||||
// if (buildInfo.skipVersion)
|
||||
// {
|
||||
// symbols = symbols + ";SKIP_VERSION;";
|
||||
// }
|
||||
|
||||
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, symbols);
|
||||
Debug.Log("[bfinfo]设置defineSymbols: " + symbols);
|
||||
// PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, symbols);
|
||||
// Debug.Log("[bfinfo]设置defineSymbols: " + symbols);
|
||||
|
||||
// 是否是dev
|
||||
var development = buildInfo.IsDevChannel();
|
||||
EditorUserBuildSettings.development = development;
|
||||
// // 是否是dev
|
||||
// var development = buildInfo.IsDevChannel();
|
||||
// EditorUserBuildSettings.development = development;
|
||||
|
||||
// 商品名称
|
||||
if (buildInfo.IsPublish())
|
||||
{
|
||||
PlayerSettings.productName = "Heroic Expedition";
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerSettings.productName = development ? "b6-dev" : "b6-release";
|
||||
}
|
||||
// // 商品名称
|
||||
// if (buildInfo.IsPublish())
|
||||
// {
|
||||
// PlayerSettings.productName = "Heroic Expedition";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// PlayerSettings.productName = development ? "b6-dev" : "b6-release";
|
||||
// }
|
||||
|
||||
// BuildType设置dev/release
|
||||
EditorUserBuildSettings.iOSXcodeBuildConfig = development ? XcodeBuildConfig.Debug : XcodeBuildConfig.Release;
|
||||
// // BuildType设置dev/release
|
||||
// EditorUserBuildSettings.iOSXcodeBuildConfig = development ? XcodeBuildConfig.Debug : XcodeBuildConfig.Release;
|
||||
|
||||
// 使用IL2CPP
|
||||
var scriptImp = ScriptingImplementation.IL2CPP;
|
||||
PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, scriptImp);
|
||||
// // 使用IL2CPP
|
||||
// var scriptImp = ScriptingImplementation.IL2CPP;
|
||||
// PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, scriptImp);
|
||||
|
||||
// 目标平台架构,目前支持ARM64
|
||||
PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 1);
|
||||
}
|
||||
// // 目标平台架构,目前支持ARM64
|
||||
// PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 1);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 获取打包参数
|
||||
/// </summary>
|
||||
static BuildPlayerOptions GetBuildOptions(BuildInfo buildInfo)
|
||||
{
|
||||
var bpOptions = new BuildPlayerOptions();
|
||||
bpOptions.scenes = AssetBundleUtils.GetBuildScenes();
|
||||
bpOptions.target = BuildTarget.iOS;
|
||||
// /// <summary>
|
||||
// /// 获取打包参数
|
||||
// /// </summary>
|
||||
// static BuildPlayerOptions GetBuildOptions(BuildInfo buildInfo)
|
||||
// {
|
||||
// var bpOptions = new BuildPlayerOptions();
|
||||
// bpOptions.scenes = AssetBundleUtils.GetBuildScenes();
|
||||
// bpOptions.target = BuildTarget.iOS;
|
||||
|
||||
var path = buildInfo.IsReleaseChannel() ? RELEASE_XCODE_LOCAL_PATH : DEV_XCODE_LOCAL_PATH;
|
||||
bpOptions.locationPathName = path;
|
||||
Debug.Log("[bfinfo]xcode path : " + path);
|
||||
var absolutePath = buildInfo.IsReleaseChannel() ? releaseXCodePath : devXCodePath;
|
||||
if (Directory.Exists(absolutePath))
|
||||
{
|
||||
Directory.Delete(absolutePath, true);
|
||||
}
|
||||
// var path = buildInfo.IsReleaseChannel() ? RELEASE_XCODE_LOCAL_PATH : DEV_XCODE_LOCAL_PATH;
|
||||
// bpOptions.locationPathName = path;
|
||||
// Debug.Log("[bfinfo]xcode path : " + path);
|
||||
// var absolutePath = buildInfo.IsReleaseChannel() ? releaseXCodePath : devXCodePath;
|
||||
// if (Directory.Exists(absolutePath))
|
||||
// {
|
||||
// Directory.Delete(absolutePath, true);
|
||||
// }
|
||||
|
||||
if (!buildInfo.IsPublish())
|
||||
{
|
||||
var options = BuildOptions.Development | BuildOptions.ConnectWithProfiler | BuildOptions.AllowDebugging;
|
||||
bpOptions.options = options;
|
||||
}
|
||||
return bpOptions;
|
||||
}
|
||||
// if (!buildInfo.IsPublish())
|
||||
// {
|
||||
// var options = BuildOptions.Development | BuildOptions.ConnectWithProfiler | BuildOptions.AllowDebugging;
|
||||
// bpOptions.options = options;
|
||||
// }
|
||||
// return bpOptions;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 打包ipa
|
||||
/// </summary>
|
||||
static bool BuildIpaFromXCode(BuildInfo buildInfo)
|
||||
{
|
||||
// 修改XCode设置
|
||||
FixXCodeProject(buildInfo);
|
||||
// /// <summary>
|
||||
// /// 打包ipa
|
||||
// /// </summary>
|
||||
// static bool BuildIpaFromXCode(BuildInfo buildInfo)
|
||||
// {
|
||||
// // 修改XCode设置
|
||||
// FixXCodeProject(buildInfo);
|
||||
|
||||
// 权限
|
||||
UnlockKeyChain();
|
||||
// // 权限
|
||||
// UnlockKeyChain();
|
||||
|
||||
// archive
|
||||
if (!Archive(buildInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// // archive
|
||||
// if (!Archive(buildInfo))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// 导出ipa
|
||||
if (!ExportIpa(buildInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// // 导出ipa
|
||||
// if (!ExportIpa(buildInfo))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// xCode工程设置
|
||||
/// </summary>
|
||||
static void FixXCodeProject(BuildInfo buildInfo)
|
||||
{
|
||||
var isDev = buildInfo.IsDevChannel();
|
||||
var xCodeProjectPath = isDev ? devXCodePath : releaseXCodePath;
|
||||
// /// <summary>
|
||||
// /// xCode工程设置
|
||||
// /// </summary>
|
||||
// static void FixXCodeProject(BuildInfo buildInfo)
|
||||
// {
|
||||
// var isDev = buildInfo.IsDevChannel();
|
||||
// var xCodeProjectPath = isDev ? devXCodePath : releaseXCodePath;
|
||||
|
||||
var path = xCodeProjectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
var pbxProject = new PBXProject();
|
||||
pbxProject.ReadFromFile(path);
|
||||
var targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");
|
||||
pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
|
||||
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
|
||||
pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
|
||||
pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "49QQW8856Q");
|
||||
if (buildInfo.IsPublish())
|
||||
{
|
||||
pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", "ub_appstore_dis");
|
||||
}
|
||||
// var path = xCodeProjectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
// var pbxProject = new PBXProject();
|
||||
// pbxProject.ReadFromFile(path);
|
||||
// var targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");
|
||||
// pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
|
||||
// pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
|
||||
// pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
|
||||
// pbxProject.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", "49QQW8856Q");
|
||||
// if (buildInfo.IsPublish())
|
||||
// {
|
||||
// pbxProject.SetBuildProperty(targetGuid, "PROVISIONING_PROFILE_SPECIFIER", "ub_appstore_dis");
|
||||
// }
|
||||
|
||||
// 添加系统库
|
||||
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libsqlite3.tbd");
|
||||
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libz.1.tbd");
|
||||
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libiconv.2.tbd");
|
||||
AddSystemLibReferenceToProject(pbxProject, targetGuid, "libresolv.9.tbd");
|
||||
// // 添加系统库
|
||||
// AddSystemLibReferenceToProject(pbxProject, targetGuid, "libsqlite3.tbd");
|
||||
// AddSystemLibReferenceToProject(pbxProject, targetGuid, "libz.1.tbd");
|
||||
// AddSystemLibReferenceToProject(pbxProject, targetGuid, "libiconv.2.tbd");
|
||||
// AddSystemLibReferenceToProject(pbxProject, targetGuid, "libresolv.9.tbd");
|
||||
|
||||
var pListPath = Path.Combine(xCodeProjectPath, "Info.plist");
|
||||
var pList = new PlistDocument();
|
||||
pList.ReadFromFile(pListPath);
|
||||
// var pListPath = Path.Combine(xCodeProjectPath, "Info.plist");
|
||||
// var pList = new PlistDocument();
|
||||
// pList.ReadFromFile(pListPath);
|
||||
|
||||
// 版本号
|
||||
var vKey = "CFBundleShortVersionString";
|
||||
var vValue = new PlistElementString(buildInfo.version);
|
||||
var pListRoot = pList.root;
|
||||
var rootDict = pListRoot.values;
|
||||
if (!rootDict.ContainsKey(vKey))
|
||||
{
|
||||
rootDict.Add(vKey, vValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootDict[vKey] = vValue;
|
||||
}
|
||||
// // 版本号
|
||||
// var vKey = "CFBundleShortVersionString";
|
||||
// var vValue = new PlistElementString(buildInfo.version);
|
||||
// var pListRoot = pList.root;
|
||||
// var rootDict = pListRoot.values;
|
||||
// if (!rootDict.ContainsKey(vKey))
|
||||
// {
|
||||
// rootDict.Add(vKey, vValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rootDict[vKey] = vValue;
|
||||
// }
|
||||
|
||||
// VersionCode
|
||||
var vCodeKey = "CFBundleVersion";
|
||||
var vCodeValue = new PlistElementString(buildInfo.version_code.ToString());
|
||||
if (!rootDict.ContainsKey(vCodeKey))
|
||||
{
|
||||
rootDict.Add(vCodeKey, vCodeValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootDict[vCodeKey] = vCodeValue;
|
||||
}
|
||||
// // VersionCode
|
||||
// var vCodeKey = "CFBundleVersion";
|
||||
// var vCodeValue = new PlistElementString(buildInfo.versionCode.ToString());
|
||||
// if (!rootDict.ContainsKey(vCodeKey))
|
||||
// {
|
||||
// rootDict.Add(vCodeKey, vCodeValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rootDict[vCodeKey] = vCodeValue;
|
||||
// }
|
||||
|
||||
// 数美SDK会使用位置,必须加入这个说明
|
||||
var localtionKey = "NSLocationWhenInUseUsageDescription";
|
||||
var localtionValue = new PlistElementString("We use your location to give you a better localization.");
|
||||
if (!rootDict.ContainsKey(localtionKey))
|
||||
{
|
||||
rootDict.Add(localtionKey, localtionValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootDict[localtionKey] = localtionValue;
|
||||
}
|
||||
// // 数美SDK会使用位置,必须加入这个说明
|
||||
// var localtionKey = "NSLocationWhenInUseUsageDescription";
|
||||
// var localtionValue = new PlistElementString("We use your location to give you a better localization.");
|
||||
// if (!rootDict.ContainsKey(localtionKey))
|
||||
// {
|
||||
// rootDict.Add(localtionKey, localtionValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rootDict[localtionKey] = localtionValue;
|
||||
// }
|
||||
|
||||
// 提审提示缺少出口合规证明,这里直接设置为false即可
|
||||
var encryptionKey = "ITSAppUsesNonExemptEncryption";
|
||||
var encryptionValue = new PlistElementBoolean(false);
|
||||
if (!rootDict.ContainsKey(encryptionKey))
|
||||
{
|
||||
rootDict.Add(encryptionKey, encryptionValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootDict[encryptionKey] = encryptionValue;
|
||||
}
|
||||
// // 提审提示缺少出口合规证明,这里直接设置为false即可
|
||||
// var encryptionKey = "ITSAppUsesNonExemptEncryption";
|
||||
// var encryptionValue = new PlistElementBoolean(false);
|
||||
// if (!rootDict.ContainsKey(encryptionKey))
|
||||
// {
|
||||
// rootDict.Add(encryptionKey, encryptionValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rootDict[encryptionKey] = encryptionValue;
|
||||
// }
|
||||
|
||||
pList.WriteToFile(pListPath);
|
||||
pbxProject.WriteToFile(path);
|
||||
}
|
||||
// pList.WriteToFile(pListPath);
|
||||
// pbxProject.WriteToFile(path);
|
||||
// }
|
||||
|
||||
//添加系统lib方法
|
||||
static void AddSystemLibReferenceToProject(PBXProject pbxProject, string targetGuid, string lib)
|
||||
{
|
||||
var fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);
|
||||
pbxProject.AddFileToBuild(targetGuid, fileGuid);
|
||||
}
|
||||
// //添加系统lib方法
|
||||
// static void AddSystemLibReferenceToProject(PBXProject pbxProject, string targetGuid, string lib)
|
||||
// {
|
||||
// var fileGuid = pbxProject.AddFile("usr/lib/" + lib, "Frameworks/" + lib, PBXSourceTree.Sdk);
|
||||
// pbxProject.AddFileToBuild(targetGuid, fileGuid);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Archive
|
||||
/// </summary>
|
||||
static bool Archive(BuildInfo buildInfo)
|
||||
{
|
||||
Debug.Log("[bfinfo]正在archive...");
|
||||
var result = true;
|
||||
var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
|
||||
var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
|
||||
var args = string.Format("archive -scheme Unity-iPhone -configuration Release -archivePath {0}", archivePath);
|
||||
BFEditorUtils.RunCommond("xcodebuild", args, xCodeProjectPath,
|
||||
(info) =>
|
||||
{
|
||||
Debug.Log(info);
|
||||
},
|
||||
(error) =>
|
||||
{
|
||||
if (error.Contains("ARCHIVE FAILED")) // 失败标志
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
Debug.LogError("[bferror] " + error);
|
||||
}
|
||||
);
|
||||
// /// <summary>
|
||||
// /// Archive
|
||||
// /// </summary>
|
||||
// static bool Archive(BuildInfo buildInfo)
|
||||
// {
|
||||
// Debug.Log("[bfinfo]正在archive...");
|
||||
// var result = true;
|
||||
// var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
|
||||
// var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
|
||||
// var args = string.Format("archive -scheme Unity-iPhone -configuration Release -archivePath {0}", archivePath);
|
||||
// BFEditorUtils.RunCommond("xcodebuild", args, xCodeProjectPath,
|
||||
// (info) =>
|
||||
// {
|
||||
// Debug.Log(info);
|
||||
// },
|
||||
// (error) =>
|
||||
// {
|
||||
// if (error.Contains("ARCHIVE FAILED")) // 失败标志
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// Debug.LogError("[bferror] " + error);
|
||||
// }
|
||||
// );
|
||||
|
||||
return result;
|
||||
}
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 导出ipa
|
||||
/// </summary>
|
||||
static bool ExportIpa(BuildInfo buildInfo)
|
||||
{
|
||||
Debug.Log("[bfinfo]正在导出ipa...");
|
||||
var result = false;
|
||||
var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
|
||||
string exportPListPath;
|
||||
if (buildInfo.IsPublish())
|
||||
{
|
||||
exportPListPath = publishOptionsPListPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
exportPListPath = buildInfo.IsDevChannel() ? devOptionsPListPath : releaseOptionsPListPath;
|
||||
}
|
||||
var ipaPath = xCodeProjectPath + "/build/ipa";
|
||||
var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
|
||||
var args = string.Format("-exportArchive -archivePath {0} -exportPath {1} -exportOptionsPlist {2} -allowProvisioningUpdates", archivePath, ipaPath, exportPListPath);
|
||||
BFEditorUtils.RunCommond("xcodebuild", args, null,
|
||||
(info) =>
|
||||
{
|
||||
if(info.Contains("EXPORT SUCCEEDED"))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
},
|
||||
(error) =>
|
||||
{
|
||||
}
|
||||
);
|
||||
// /// <summary>
|
||||
// /// 导出ipa
|
||||
// /// </summary>
|
||||
// static bool ExportIpa(BuildInfo buildInfo)
|
||||
// {
|
||||
// Debug.Log("[bfinfo]正在导出ipa...");
|
||||
// var result = false;
|
||||
// var xCodeProjectPath = buildInfo.IsDevChannel() ? devXCodePath : releaseXCodePath;
|
||||
// string exportPListPath;
|
||||
// if (buildInfo.IsPublish())
|
||||
// {
|
||||
// exportPListPath = publishOptionsPListPath;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// exportPListPath = buildInfo.IsDevChannel() ? devOptionsPListPath : releaseOptionsPListPath;
|
||||
// }
|
||||
// var ipaPath = xCodeProjectPath + "/build/ipa";
|
||||
// var archivePath = xCodeProjectPath + "/build/archive/Unity-iPhone.xcarchive";
|
||||
// var args = string.Format("-exportArchive -archivePath {0} -exportPath {1} -exportOptionsPlist {2} -allowProvisioningUpdates", archivePath, ipaPath, exportPListPath);
|
||||
// BFEditorUtils.RunCommond("xcodebuild", args, null,
|
||||
// (info) =>
|
||||
// {
|
||||
// if(info.Contains("EXPORT SUCCEEDED"))
|
||||
// {
|
||||
// result = true;
|
||||
// }
|
||||
// },
|
||||
// (error) =>
|
||||
// {
|
||||
// }
|
||||
// );
|
||||
|
||||
return result;
|
||||
}
|
||||
// return result;
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 远程打包签名ipa时需要钥匙串权限
|
||||
/// </summary>
|
||||
static void UnlockKeyChain()
|
||||
{
|
||||
BFEditorUtils.RunCommond("security", "-v unlock-keychain -p '123456' /Users/aoddabao/Library/Keychains/login.keychain-db", null,
|
||||
(msg) =>
|
||||
{
|
||||
Debug.Log(msg);
|
||||
},
|
||||
(msg) =>
|
||||
{
|
||||
Debug.LogError(msg);
|
||||
}
|
||||
);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 远程打包签名ipa时需要钥匙串权限
|
||||
// /// </summary>
|
||||
// static void UnlockKeyChain()
|
||||
// {
|
||||
// BFEditorUtils.RunCommond("security", "-v unlock-keychain -p '123456' /Users/aoddabao/Library/Keychains/login.keychain-db", null,
|
||||
// (msg) =>
|
||||
// {
|
||||
// Debug.Log(msg);
|
||||
// },
|
||||
// (msg) =>
|
||||
// {
|
||||
// Debug.LogError(msg);
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user