2020-09-10 11:47:18 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System;
|
2020-09-18 17:44:02 +08:00
|
|
|
|
using GameEditor.FrameTool;
|
2021-06-01 10:41:03 +08:00
|
|
|
|
using GameEditor.Util;
|
2021-09-17 19:22:45 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
|
2021-09-17 19:22:45 +08:00
|
|
|
|
public class PackConfig
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
public string name;
|
|
|
|
|
public string scene;
|
|
|
|
|
public string project;
|
|
|
|
|
public string version;
|
|
|
|
|
public string bench;
|
|
|
|
|
public PackConfig(string _name, string _scene, string _project, string _version, string _bench)
|
2021-05-27 10:12:22 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
name = _name;
|
|
|
|
|
scene = _scene;
|
|
|
|
|
project = _project;
|
|
|
|
|
version= _version;
|
|
|
|
|
bench = _bench;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
2021-09-17 19:22:45 +08:00
|
|
|
|
|
|
|
|
|
public class AutoPack : EditorWindow
|
|
|
|
|
{
|
|
|
|
|
static List<PackConfig> PackConfig = new List<PackConfig>();
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
#if UNITY_ANDROID
|
|
|
|
|
static string Platform = "Android";
|
|
|
|
|
static string ConfigFileName = "config.txt";
|
|
|
|
|
static string VersionFileName = "version.txt";
|
|
|
|
|
#elif UNITY_IOS
|
|
|
|
|
static string Platform = "IOS";
|
|
|
|
|
static string ConfigFileName = "config.txt";
|
2021-12-06 13:19:33 +08:00
|
|
|
|
static string VersionFileName = "version.txt";
|
2021-05-27 10:59:34 +08:00
|
|
|
|
#else
|
|
|
|
|
static string Platform = "Android";
|
|
|
|
|
static string ConfigFileName = "config.txt";
|
|
|
|
|
static string VersionFileName = "version.txt";
|
2021-05-27 10:12:22 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static string MomPackPath;
|
|
|
|
|
static string ExportPackPath;
|
|
|
|
|
static string ScenePath;
|
|
|
|
|
static string ABPath;
|
2021-06-01 10:41:03 +08:00
|
|
|
|
static string APKPath;
|
|
|
|
|
static string PackTime;
|
2021-06-01 11:01:04 +08:00
|
|
|
|
static bool CommitToGit;
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
// 判断是否要重新导出工程
|
|
|
|
|
static string[] ExportTypeList =
|
|
|
|
|
{
|
|
|
|
|
"导出工程,替换出包",
|
|
|
|
|
"只替换AB出包",
|
|
|
|
|
"只出包"
|
|
|
|
|
};
|
|
|
|
|
static int ExportType;
|
|
|
|
|
static bool[] Chooser;
|
2020-09-14 16:20:36 +08:00
|
|
|
|
static bool isObb = false;
|
2021-06-17 11:16:11 +08:00
|
|
|
|
static string benchName; // 当前所在分支
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
MomPackPath = EditorPrefs.GetString("MomPackPath", "");
|
|
|
|
|
ExportPackPath = Application.dataPath.Replace("Assets", "ExportProject");
|
|
|
|
|
ScenePath = Application.dataPath + "/LuaFramework/Scenes/";
|
|
|
|
|
ABPath = Application.dataPath + "/../BuildABs/" + Platform + "/";
|
|
|
|
|
ExportType = 2;
|
2021-09-17 19:22:45 +08:00
|
|
|
|
// 加载配置
|
|
|
|
|
LoadConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void LoadConfig()
|
|
|
|
|
{
|
2021-09-18 09:50:37 +08:00
|
|
|
|
PackConfig.Clear();
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Hashtable config = ClientConfigManager.Instance.GetAutoPackConfig();
|
|
|
|
|
foreach (string k in config.Keys)
|
|
|
|
|
{
|
|
|
|
|
Hashtable ht = config[k] as Hashtable;
|
|
|
|
|
string name = k;
|
|
|
|
|
string scene = ht["scene"] as string;
|
|
|
|
|
string project = ht["project"] as string;
|
|
|
|
|
string version = ht["version"] as string;
|
|
|
|
|
string bench = ht["bench"] as string;
|
|
|
|
|
PackConfig.Add(new PackConfig(name, scene, project, version, bench));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Chooser = new bool[PackConfig.Count];
|
2021-05-27 10:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 版本文件路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
static string _MomPackPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MomPackPath + "/" + Platform + "/";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//bool isBuild = false;
|
|
|
|
|
//static bool isZs = false;
|
|
|
|
|
//static string[] versionArr = new string[15];
|
|
|
|
|
//static int verIndex = 0;
|
|
|
|
|
//static string curProjectDir;
|
|
|
|
|
//static string m_ExcelPath;
|
|
|
|
|
//static string[] excelArr;
|
|
|
|
|
//static int excelIndex=0;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
//打包数据
|
|
|
|
|
[MenuItem("自动化打包/一键导出")]
|
|
|
|
|
private static void EzBuildPack()
|
|
|
|
|
{
|
2021-06-17 11:16:11 +08:00
|
|
|
|
|
|
|
|
|
benchName = GitUtil.GetCurBenchName();
|
|
|
|
|
UnityEngine.Debug.Log("当前分支:" + benchName);
|
2020-09-10 11:47:18 +08:00
|
|
|
|
//创建窗口
|
2021-09-18 09:50:37 +08:00
|
|
|
|
Rect wr = new Rect(0, 0, 500, 1000);
|
2020-09-10 11:47:18 +08:00
|
|
|
|
var buildWin = GetWindowWithRect<AutoPack>(wr, true);
|
|
|
|
|
buildWin.titleContent = new GUIContent("打包工具");
|
2021-06-03 21:32:44 +08:00
|
|
|
|
buildWin.Show();
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
2021-06-03 21:32:44 +08:00
|
|
|
|
//[MenuItem("自动化打包/一键导出2")]
|
|
|
|
|
//private static void EzBuildPack2()
|
|
|
|
|
//{
|
|
|
|
|
// //创建窗口
|
|
|
|
|
// string[] ss = ProcessUtil.OpenFileWin();
|
|
|
|
|
// foreach(string s in ss)
|
|
|
|
|
// {
|
|
|
|
|
// Debug.Log(s);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2021-05-31 11:24:20 +08:00
|
|
|
|
|
2020-09-10 11:47:18 +08:00
|
|
|
|
private void OnGUI()
|
2020-09-18 17:44:02 +08:00
|
|
|
|
{
|
2020-09-10 11:47:18 +08:00
|
|
|
|
EditorGUILayout.BeginVertical();
|
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
|
EditorGUILayout.Space();
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
//EditorGUILayout.LabelField("");
|
|
|
|
|
MomPackPath = EditorGUILayout.TextField("母包工程地址:", MomPackPath);
|
2021-05-31 11:24:20 +08:00
|
|
|
|
if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
|
|
|
|
|
{
|
|
|
|
|
MomPackPath = EditorUtility.OpenFolderPanel("Resource path", MomPackPath, MomPackPath);
|
|
|
|
|
EditorPrefs.SetString("MomPackPath", MomPackPath);
|
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
|
EditorGUILayout.LabelField("请选择要打的包:");
|
2021-09-17 19:22:45 +08:00
|
|
|
|
for(int i = 0; i < PackConfig.Count; i++)
|
2020-09-18 17:44:02 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
if (PackConfig[i].bench.Equals(benchName))
|
2020-09-18 17:44:02 +08:00
|
|
|
|
{
|
2021-06-17 11:16:11 +08:00
|
|
|
|
EditorGUILayout.BeginVertical();
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Chooser[i] = EditorGUILayout.ToggleLeft(PackConfig[i].name, Chooser[i]);
|
2021-12-01 17:21:48 +08:00
|
|
|
|
if (Chooser[i])
|
2021-06-17 11:16:11 +08:00
|
|
|
|
{
|
2021-12-01 17:21:48 +08:00
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
if (GUILayout.Button("编辑Config", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
string tpath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[i].version + "/" + ConfigFileName;
|
|
|
|
|
GameEditor.Util.ProcessUtil.OpenText(tpath);
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.Button("编辑Version", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
string tpath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[i].version + "/" + VersionFileName;
|
|
|
|
|
GameEditor.Util.ProcessUtil.OpenText(tpath);
|
|
|
|
|
}
|
2021-12-06 13:19:33 +08:00
|
|
|
|
if (GameLogic.AppConst.PlatformPath.Equals("Android"))
|
2021-12-01 17:21:48 +08:00
|
|
|
|
{
|
2021-12-06 13:19:33 +08:00
|
|
|
|
if (GUILayout.Button("编辑Gradle", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
string tpath = _MomPackPath + PackConfig[i].project + "/build.gradle";
|
|
|
|
|
GameEditor.Util.ProcessUtil.OpenText(tpath);
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.Button("更新蓝鲸SDK", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
File.Copy(_MomPackPath + "BlueWhaleJar/app/build/outputs/aar/app-release.aar", _MomPackPath + PackConfig[i].project + "/libs/BlueWhale.aar", true);
|
|
|
|
|
Debug.Log("更新完成");
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 17:21:48 +08:00
|
|
|
|
}
|
2021-12-06 13:19:33 +08:00
|
|
|
|
else
|
2021-12-01 17:21:48 +08:00
|
|
|
|
{
|
2021-12-06 13:19:33 +08:00
|
|
|
|
if (GUILayout.Button("同步配置文件", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
ReplaceConfigAndVersion(i);
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.Button("开始混淆", GUILayout.Height(20f)))
|
|
|
|
|
{
|
|
|
|
|
EncryptAB(i);
|
|
|
|
|
}
|
2021-12-01 17:21:48 +08:00
|
|
|
|
}
|
2021-12-06 13:19:33 +08:00
|
|
|
|
|
2021-12-01 17:21:48 +08:00
|
|
|
|
EditorGUILayout.EndHorizontal();
|
2021-06-17 11:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
|
EditorGUILayout.Space();
|
2020-09-18 17:44:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
ExportType = EditorGUILayout.Popup("请选择出包方式", ExportType, ExportTypeList);
|
2020-09-18 17:44:02 +08:00
|
|
|
|
EditorGUILayout.Space();
|
2021-06-01 11:01:04 +08:00
|
|
|
|
CommitToGit = EditorGUILayout.ToggleLeft("是否要提交到Git", CommitToGit);
|
2020-09-18 17:44:02 +08:00
|
|
|
|
EditorGUILayout.Space();
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("开始", GUILayout.Height(40f)))
|
|
|
|
|
{
|
|
|
|
|
StartExport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void StartExport()
|
|
|
|
|
{
|
|
|
|
|
if (MomPackPath.Equals(""))
|
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayDialog("提示", "母包工程地址错误", "确定");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool check_result = false;
|
|
|
|
|
for (int i = 0; i < Chooser.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!Chooser[i]) continue;
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string sceneFilePath = ScenePath + PackConfig[i].scene;
|
2021-05-27 10:12:22 +08:00
|
|
|
|
if (!File.Exists(sceneFilePath + ".unity"))
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.LogError(PackConfig[i].name + " 未找到场景:" + sceneFilePath);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
check_result = true;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string momPath = _MomPackPath + PackConfig[i].project;
|
2021-05-27 10:12:22 +08:00
|
|
|
|
if (!Directory.Exists(momPath))
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.LogError(PackConfig[i].name + " 未找到母包:" + momPath);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
check_result = true;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
if (check_result)
|
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayDialog("提示", "包路径错误", "确定");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 开始导出
|
|
|
|
|
for (int i = 0; i < Chooser.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!Chooser[i]) continue;
|
|
|
|
|
|
|
|
|
|
switch (ExportType) {
|
|
|
|
|
case 0: // 导出工程
|
|
|
|
|
ExportAS(i);
|
|
|
|
|
ReplaceFromProject(i);
|
|
|
|
|
ReplaceConfigAndVersion(i);
|
2021-12-02 22:59:05 +08:00
|
|
|
|
//EncryptAB(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitUpdate(i);
|
2021-06-01 10:41:03 +08:00
|
|
|
|
CreateLogFile(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
StartGradleBuild(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitCommit(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1: // 只替换AB
|
|
|
|
|
ReplaceFromAB(i);
|
|
|
|
|
ReplaceConfigAndVersion(i);
|
2021-12-02 22:59:05 +08:00
|
|
|
|
//EncryptAB(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitUpdate(i);
|
2021-06-01 10:41:03 +08:00
|
|
|
|
CreateLogFile(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
StartGradleBuild(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitCommit(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2: // 只重新打包
|
2021-05-27 22:11:32 +08:00
|
|
|
|
ReplaceConfigAndVersion(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitUpdate(i);
|
2021-06-01 10:41:03 +08:00
|
|
|
|
CreateLogFile(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
StartGradleBuild(i);
|
2021-06-01 10:56:20 +08:00
|
|
|
|
GitCommit(i);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
break;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
2021-06-01 10:41:03 +08:00
|
|
|
|
public static void CreateLogFile(int index)
|
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
APKPath = _MomPackPath + PackConfig[index].project + "/APK/";
|
2021-06-01 10:41:03 +08:00
|
|
|
|
if (!Directory.Exists(APKPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(APKPath);
|
|
|
|
|
}
|
2021-06-09 20:30:10 +08:00
|
|
|
|
PackTime = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
|
2021-06-01 10:41:03 +08:00
|
|
|
|
APKPath += PackTime;
|
|
|
|
|
if (!Directory.Exists(APKPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(APKPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
// 导出android 工程
|
|
|
|
|
public static void ExportAS(int index)
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string pName = PackConfig[index].scene + "__" + PackConfig[index].project;
|
2021-05-27 10:12:22 +08:00
|
|
|
|
PlayerSettings.productName = pName;
|
|
|
|
|
PlayerSettings.Android.useAPKExpansionFiles = isObb;
|
2020-09-14 16:20:36 +08:00
|
|
|
|
if (isObb)
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-05-27 10:12:22 +08:00
|
|
|
|
pName += "__obb";
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(ExportPackPath))
|
2020-09-10 11:47:18 +08:00
|
|
|
|
{
|
2021-05-27 10:12:22 +08:00
|
|
|
|
Directory.CreateDirectory(ExportPackPath);
|
|
|
|
|
}
|
|
|
|
|
if (Directory.Exists(ExportPackPath + "/" + pName))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(ExportPackPath + "/" + pName, true);
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
|
|
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
2020-09-17 12:08:08 +08:00
|
|
|
|
EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
// 设置需要打包的场景
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string launchScene = "Assets/LuaFramework/Scenes/" + PackConfig[index].scene + ".unity";
|
|
|
|
|
Debug.Log(PackConfig[index].name + ":打包场景:" + launchScene);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
BuildPlayerOptions bpo = new BuildPlayerOptions();
|
|
|
|
|
bpo.locationPathName = ExportPackPath;
|
|
|
|
|
bpo.options = BuildOptions.None;
|
|
|
|
|
//bpo.options |= BuildOptions.AcceptExternalModificationsToPlayer;
|
|
|
|
|
bpo.scenes = new[] { launchScene };
|
|
|
|
|
bpo.target = BuildTarget.Android;
|
2020-09-10 11:47:18 +08:00
|
|
|
|
// 调用开始打包
|
2021-05-27 10:12:22 +08:00
|
|
|
|
BuildPipeline.BuildPlayer(bpo);
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name + ":android工程导出路径" + ExportPackPath + "/" + pName);
|
|
|
|
|
Debug.Log(PackConfig[index].name + ":android工程导出完成");
|
2020-09-14 16:20:36 +08:00
|
|
|
|
}
|
2020-09-10 11:47:18 +08:00
|
|
|
|
|
2021-05-27 10:12:22 +08:00
|
|
|
|
static string[] ReplaceDir = new string[]
|
|
|
|
|
{
|
|
|
|
|
"/src/main/assets/Android",
|
2021-07-23 17:45:35 +08:00
|
|
|
|
"/src/main/assets/bin"
|
|
|
|
|
};
|
|
|
|
|
static string[] CopyDir = new string[]
|
|
|
|
|
{
|
2021-05-27 10:12:22 +08:00
|
|
|
|
"/src/main/jniLibs"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 从工程中替换
|
|
|
|
|
private static void ReplaceFromProject(int index)
|
2020-09-14 16:20:36 +08:00
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string fromPath = ExportPackPath + "/" + PackConfig[index].scene + "__" + PackConfig[index].project;
|
|
|
|
|
string toPath = _MomPackPath + PackConfig[index].project;
|
2021-05-27 10:12:22 +08:00
|
|
|
|
for (int i = 0; i < ReplaceDir.Length; i++)
|
2020-09-14 16:20:36 +08:00
|
|
|
|
{
|
2021-05-27 10:12:22 +08:00
|
|
|
|
string dir = ReplaceDir[i];
|
|
|
|
|
string to = toPath + dir;
|
2021-07-23 17:45:35 +08:00
|
|
|
|
GameCore.FileUtils.ReplaceDir(fromPath + dir, to, (string dirName, string fileName, float progress)=>
|
2021-05-31 21:54:13 +08:00
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayProgressBar("正在复制:"+ dirName, fileName, progress);
|
|
|
|
|
});
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
2020-09-14 16:20:36 +08:00
|
|
|
|
}
|
2021-07-23 17:45:35 +08:00
|
|
|
|
for (int i = 0; i < CopyDir.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string dir = CopyDir[i];
|
|
|
|
|
string to = toPath + dir;
|
|
|
|
|
GameCore.FileUtils.CopyDir(fromPath + dir, to, (string dirName, string fileName, float progress) =>
|
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayProgressBar("正在复制:" + dirName, fileName, progress);
|
|
|
|
|
});
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
}
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name + ":母包工程资源替换完成");
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
|
|
|
|
// 替换build-id
|
2021-05-31 20:24:15 +08:00
|
|
|
|
|
2021-05-31 21:54:13 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("重写AndroidManifest", "", 0.5f);
|
2021-05-27 10:12:22 +08:00
|
|
|
|
RewriteManifest(fromPath + "/src/main/AndroidManifest.xml", toPath + "/src/main/AndroidManifest.xml");
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name + ":母包Manifest修改完成");
|
2021-05-31 20:24:15 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
2021-05-27 10:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
private static void RewriteManifest(string f, string t)
|
|
|
|
|
{
|
|
|
|
|
// 找到要替换的内容
|
|
|
|
|
string[] flines = File.ReadAllLines(f, System.Text.Encoding.UTF8);
|
|
|
|
|
string rpl = "";
|
|
|
|
|
for (int fi = 0; fi < flines.Length; fi++)
|
|
|
|
|
{
|
|
|
|
|
if (flines[fi].Contains("unity.build-id"))
|
|
|
|
|
{
|
|
|
|
|
rpl = flines[fi];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 判断是否正确
|
|
|
|
|
if (rpl.Equals(""))
|
2020-09-14 16:20:36 +08:00
|
|
|
|
{
|
2021-05-27 10:12:22 +08:00
|
|
|
|
return;
|
2020-09-14 16:20:36 +08:00
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
// 替换到母包中
|
|
|
|
|
string[] tlines = File.ReadAllLines(t, System.Text.Encoding.UTF8);
|
|
|
|
|
string[] wlines = new string[tlines.Length - 1];
|
|
|
|
|
string lastLine = "";
|
|
|
|
|
for (int ti = 0; ti < tlines.Length; ti++)
|
|
|
|
|
{
|
|
|
|
|
if (tlines[ti].Contains("unity.build-id"))
|
|
|
|
|
{
|
|
|
|
|
tlines[ti] = rpl;
|
|
|
|
|
}
|
|
|
|
|
if (ti == tlines.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
lastLine = tlines[ti];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wlines[ti] = tlines[ti];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
File.WriteAllLines(t, wlines, System.Text.Encoding.UTF8);
|
|
|
|
|
File.AppendAllText(t, lastLine, System.Text.Encoding.UTF8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从AB包替换
|
|
|
|
|
private static void ReplaceFromAB(int index)
|
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android";
|
2021-05-27 10:12:22 +08:00
|
|
|
|
if (Directory.Exists(toPath)) Directory.Delete(toPath, true);
|
|
|
|
|
Directory.CreateDirectory(toPath);
|
2021-07-23 17:45:35 +08:00
|
|
|
|
GameCore.FileUtils.ReplaceDir(ABPath, toPath, (string dirName, string fileName, float progress) =>
|
2021-05-31 21:54:13 +08:00
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayProgressBar("正在复制:" + dirName, fileName, progress);
|
|
|
|
|
});
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name + ":替换AB包完成");
|
2021-05-27 10:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 21:32:16 +08:00
|
|
|
|
// 加密AB包
|
|
|
|
|
private static void EncryptAB(int index)
|
|
|
|
|
{
|
|
|
|
|
string toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android";
|
2021-12-06 13:19:33 +08:00
|
|
|
|
if (GameLogic.AppConst.PlatformPath.Equals("IOS"))
|
|
|
|
|
{
|
|
|
|
|
toPath = _MomPackPath + PackConfig[index].project + "/Data/Raw/IOS";
|
|
|
|
|
}
|
2021-12-01 21:32:16 +08:00
|
|
|
|
|
|
|
|
|
string json = File.ReadAllText(toPath + "/"+ VersionFileName);
|
|
|
|
|
VersionTxt version = JsonUtility.FromJson<VersionTxt>(json);
|
|
|
|
|
if (version.EncyptKey != null && version.EncyptKey != "")
|
|
|
|
|
{
|
|
|
|
|
string[] pathList = Directory.GetFiles(toPath, "*.unity3d", SearchOption.AllDirectories);
|
|
|
|
|
float i = 0f;
|
|
|
|
|
Debug.Log("文件数量;" + pathList.Length);
|
|
|
|
|
foreach (string path in pathList)
|
|
|
|
|
{
|
|
|
|
|
GameLogic.MEncyptUtil.EncyptAB(path, version.EncyptKey);
|
|
|
|
|
EditorUtility.DisplayProgressBar("正在加密:", path, i++ / pathList.Length);
|
|
|
|
|
}
|
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
Debug.Log(PackConfig[index].name + ":加密AB包完成");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
Debug.Log(PackConfig[index].name + ":无需加密");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-27 10:12:22 +08:00
|
|
|
|
// 替换配置文件
|
|
|
|
|
private static void ReplaceConfigAndVersion(int index)
|
|
|
|
|
{
|
2021-12-06 13:19:33 +08:00
|
|
|
|
if (GameLogic.AppConst.PlatformPath.Equals("Android")) {
|
|
|
|
|
|
|
|
|
|
//EditorUtility.DisplayProgressBar("替换配置文件1", "", 0.5f);
|
|
|
|
|
string fromPath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[index].version + "/";
|
|
|
|
|
string toPath = _MomPackPath + PackConfig[index].project + "/Config/";
|
|
|
|
|
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
|
|
|
|
|
File.Copy(fromPath + VersionFileName, toPath + VersionFileName, true);
|
|
|
|
|
//EditorUtility.DisplayProgressBar("替换配置文件2", "", 0.5f);
|
|
|
|
|
fromPath = toPath;
|
|
|
|
|
toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android/";
|
|
|
|
|
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
|
|
|
|
|
File.Copy(fromPath + VersionFileName, toPath + VersionFileName, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//EditorUtility.DisplayProgressBar("替换配置文件", "", 0.5f);
|
|
|
|
|
string fromPath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[index].version + "/";
|
|
|
|
|
string toPath = _MomPackPath + PackConfig[index].project + "/Data/Raw/IOS/";
|
|
|
|
|
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
|
|
|
|
|
File.Copy(fromPath + VersionFileName, toPath + VersionFileName, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name+":配置文件替换完成");
|
2021-05-31 20:24:15 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
2021-05-27 10:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 开始生成apk
|
|
|
|
|
private static void StartGradleBuild(int index)
|
|
|
|
|
{
|
2021-06-01 10:41:03 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("正在生成APK", "", 0f);
|
2021-09-17 19:22:45 +08:00
|
|
|
|
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index].project, "gradlew assembleRelease>>" + APKPath + "/_log.txt");
|
2021-05-31 20:24:15 +08:00
|
|
|
|
|
2021-06-01 10:41:03 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("正在导出APK", "", 1f);
|
2021-08-05 14:42:34 +08:00
|
|
|
|
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string versionStr = GetAPKVersionStr(PackConfig[index].project);
|
|
|
|
|
string apkFilePath = _MomPackPath + PackConfig[index].project + "/build/outputs/apk/release/" + PackConfig[index].project + "-release.apk";
|
2021-05-31 20:24:15 +08:00
|
|
|
|
if (File.Exists(apkFilePath))
|
|
|
|
|
{
|
2021-09-22 17:07:51 +08:00
|
|
|
|
File.Copy(apkFilePath, APKPath + "/" + PackConfig[index].name +"_" + versionStr + "_" + PackTime + ".apk");
|
2021-05-31 20:24:15 +08:00
|
|
|
|
}
|
2021-09-17 19:22:45 +08:00
|
|
|
|
Debug.Log(PackConfig[index].name + ":打包完成");
|
2021-05-31 20:24:15 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|
2021-05-27 10:12:22 +08:00
|
|
|
|
|
2021-08-05 14:42:34 +08:00
|
|
|
|
private static string GetAPKVersionStr(string folder)
|
|
|
|
|
{
|
|
|
|
|
string tpath = _MomPackPath + folder + "/build.gradle";
|
|
|
|
|
string[] lines = File.ReadAllLines(tpath);
|
|
|
|
|
string versionCode = "";
|
|
|
|
|
string versionName = "";
|
2021-09-22 17:07:51 +08:00
|
|
|
|
string applicationId = "";
|
2021-08-05 14:42:34 +08:00
|
|
|
|
foreach (string l in lines)
|
|
|
|
|
{
|
|
|
|
|
string lt = l.Trim();
|
|
|
|
|
if (lt.StartsWith("versionCode"))
|
|
|
|
|
{
|
|
|
|
|
versionCode = lt.Split(' ')[1];
|
|
|
|
|
}else if (lt.StartsWith("versionName"))
|
|
|
|
|
{
|
|
|
|
|
versionName = lt.Split('\'')[1];
|
|
|
|
|
}
|
2021-09-22 17:07:51 +08:00
|
|
|
|
else if (lt.StartsWith("applicationId"))
|
|
|
|
|
{
|
|
|
|
|
applicationId = lt.Split('\'')[1];
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 14:42:34 +08:00
|
|
|
|
}
|
2021-09-22 17:07:51 +08:00
|
|
|
|
return string.Format("{0}_{1}({2})", applicationId, versionName, versionCode);
|
2021-08-05 14:42:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 10:41:03 +08:00
|
|
|
|
private static void GitUpdate(int index)
|
|
|
|
|
{
|
|
|
|
|
EditorUtility.DisplayProgressBar("正在更新母包", "", 0f);
|
2021-06-03 14:37:28 +08:00
|
|
|
|
ProcessUtil.ProcessCommand(_MomPackPath, "git pull>>" + APKPath + "/_log.txt");
|
2021-06-01 10:41:03 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
}
|
|
|
|
|
private static void GitCommit(int index)
|
|
|
|
|
{
|
2021-06-01 11:01:04 +08:00
|
|
|
|
if (CommitToGit)
|
|
|
|
|
{
|
2021-09-17 19:22:45 +08:00
|
|
|
|
string versionStr = GetAPKVersionStr(PackConfig[index].project);
|
2021-06-01 11:01:04 +08:00
|
|
|
|
EditorUtility.DisplayProgressBar("正在提交修改", "", 0f);
|
2021-06-03 14:37:28 +08:00
|
|
|
|
string printlog = ">>" + APKPath + "/_log.txt";
|
|
|
|
|
string[] commands = new string[]{
|
|
|
|
|
"echo git add ." + printlog,
|
|
|
|
|
"git add ." + printlog,
|
2021-09-22 17:07:51 +08:00
|
|
|
|
"echo git commit -m 'AutoPack:" + PackConfig[index].name +"_" + versionStr + "_" + PackTime + ".apk'" + printlog,
|
|
|
|
|
"git commit -m 'AutoPack:" + PackConfig[index].name +"_" + versionStr + "_" + PackTime + ".apk'" + printlog,
|
2021-06-15 15:23:05 +08:00
|
|
|
|
"git push",
|
2021-06-03 14:37:28 +08:00
|
|
|
|
};
|
2021-09-17 19:22:45 +08:00
|
|
|
|
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index].project, commands);
|
2021-06-01 11:01:04 +08:00
|
|
|
|
EditorUtility.ClearProgressBar();
|
|
|
|
|
}
|
2021-06-01 10:41:03 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 10:12:22 +08:00
|
|
|
|
//private static void ExportXcode(string _sceneName)
|
|
|
|
|
//{
|
|
|
|
|
// PlayerSettings.productName = "太初行";
|
|
|
|
|
// string mainXcodePath =
|
|
|
|
|
// isZs? "/Volumes/ELEMENTS/JieLing/Packager/IOS/MHT_HW_RELEASE": "/Volumes/ELEMENTS/JieLing/Packager/IOS/MHT_HW_TEST";
|
|
|
|
|
// string outPath = isZs?"/Volumes/ELEMENTS/JieLing/Packager/IOS/exXcodePro_Release":"/Volumes/ELEMENTS/JieLing/Packager/IOS/exXcodePro_Test";
|
|
|
|
|
// if (Directory.Exists(outPath))
|
|
|
|
|
// {
|
|
|
|
|
// Directory.Delete(outPath, true);
|
|
|
|
|
// }
|
|
|
|
|
// // 设置需要打包的场景
|
|
|
|
|
// string launchScene = _sceneName;
|
|
|
|
|
// Debug.Log("打包场景:" + launchScene);
|
|
|
|
|
// BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|
|
|
|
// buildPlayerOptions.locationPathName = outPath;
|
|
|
|
|
// buildPlayerOptions.options = BuildOptions.None;
|
|
|
|
|
// buildPlayerOptions.options |= BuildOptions.AcceptExternalModificationsToPlayer;
|
|
|
|
|
// buildPlayerOptions.scenes = new[] { launchScene };
|
|
|
|
|
// buildPlayerOptions.target = BuildTarget.iOS;
|
|
|
|
|
// // 调用开始打包
|
|
|
|
|
// BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|
|
|
|
// Debug.Log("打包完成");
|
|
|
|
|
// Debug.Log("导出工程路径:"+ outPath);
|
|
|
|
|
// if (Directory.Exists(mainXcodePath)&& Directory.Exists(outPath))
|
|
|
|
|
// {
|
|
|
|
|
// Debug.Log("替换xcode资源");
|
|
|
|
|
// Directory.Delete(mainXcodePath+"/Data", true);
|
|
|
|
|
// Directory.Move(outPath+"/Data",mainXcodePath+"/Data");
|
|
|
|
|
// Directory.Delete(mainXcodePath+"/Classes/Native", true);
|
|
|
|
|
// Directory.Move(outPath+"/Classes/Native",mainXcodePath+"/Classes/Native");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-09-10 11:47:18 +08:00
|
|
|
|
}
|