打包脚本
This commit is contained in:
parent
4316bca531
commit
01427a9f4c
@ -197,5 +197,11 @@ namespace BFEditor.Build
|
||||
{
|
||||
BuildProjectWindow.ShowWindow();
|
||||
}
|
||||
|
||||
[MenuItem("打包工具/Android转换为AAB工程", priority = 401)]
|
||||
static void ConvertAndroidStudioToAAB()
|
||||
{
|
||||
BuildAndroidUtils.ConvertToAAB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using UnityEditor;
|
||||
using System.IO;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
@ -32,6 +33,11 @@ namespace BFEditor.Build
|
||||
static string PublishAsProjectPath = Application.dataPath + "/../BFVersions/android/publish_release";
|
||||
static string SignShellPath = Application.dataPath + "/../BFFiles/androidkey";
|
||||
static string GpAlginShellPath = Application.dataPath + "/../BFFiles/androidkey";
|
||||
static HashSet<string> AABInPackageFileHashSet = new HashSet<string>()
|
||||
{
|
||||
"bin",
|
||||
"UnityServicesProjectConfiguration.json"
|
||||
};
|
||||
|
||||
static BuildAndroidUtils()
|
||||
{
|
||||
@ -551,5 +557,83 @@ namespace BFEditor.Build
|
||||
tmp.Abort();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ConvertToAAB()
|
||||
{
|
||||
var installTimePackDirPath = Path.Combine(PublishAsProjectPath, "../", "dz_google_abb", "install_time_pack");
|
||||
var targetDirPath = Path.Combine(PublishAsProjectPath, "install_time_pack");
|
||||
if (Directory.Exists(targetDirPath))
|
||||
{
|
||||
Directory.Delete(targetDirPath, true);
|
||||
Directory.CreateDirectory(targetDirPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(targetDirPath);
|
||||
}
|
||||
|
||||
BFEditorUtils.CopyDir(installTimePackDirPath, targetDirPath);
|
||||
|
||||
var abDirPath = Path.Combine(PublishAsProjectPath, "unityLibrary/src/main/assets");
|
||||
var destFolderName = Path.Combine(PublishAsProjectPath, "install_time_pack/src/main/assets");
|
||||
var dirInfo = new DirectoryInfo(abDirPath);
|
||||
var floders = dirInfo.GetDirectories();
|
||||
for (var i = 0; i < floders.Length; i++)
|
||||
{
|
||||
if (AABInPackageFileHashSet.Contains(floders[i].Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var newDir = Path.Combine(destFolderName, floders[i].Name);
|
||||
if (!Directory.Exists(newDir))
|
||||
{
|
||||
Directory.CreateDirectory(newDir);
|
||||
}
|
||||
BFEditorUtils.CopyDir(floders[i].FullName, newDir);
|
||||
Directory.Delete(floders[i].FullName, true);
|
||||
}
|
||||
|
||||
var files = dirInfo.GetFiles();
|
||||
for (var i = 0; i < files.Length; i++)
|
||||
{
|
||||
var file = files[i];
|
||||
if (AABInPackageFileHashSet.Contains(file.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var destFile = Path.Combine(destFolderName, file.Name);
|
||||
if (File.Exists(destFile))
|
||||
{
|
||||
File.Delete(destFile);
|
||||
}
|
||||
File.Move(file.FullName, destFile);
|
||||
}
|
||||
|
||||
var settingsGradleFilePath = Path.Combine(PublishAsProjectPath, "settings.gradle");
|
||||
var text = File.ReadAllText(settingsGradleFilePath);
|
||||
var appendText = "include ':install_time_pack'";
|
||||
if (!text.EndsWith(appendText))
|
||||
{
|
||||
text = text + "\n" + appendText;
|
||||
}
|
||||
File.WriteAllText(settingsGradleFilePath, text);
|
||||
|
||||
var buildGradlePath = Path.Combine(PublishAsProjectPath, "launcher/build.gradle");
|
||||
var buildGradleText = File.ReadAllText(buildGradlePath);
|
||||
var regex1 = new Regex("implementation 'com.google.android.play:core:1.10.0'");
|
||||
if (!regex1.IsMatch(buildGradleText))
|
||||
{
|
||||
var regex12 = new Regex("dependencies {");
|
||||
buildGradleText = regex12.Replace(buildGradleText, "dependencies {\n implementation 'com.google.android.play:core:1.10.0'");
|
||||
}
|
||||
var regex2 = new Regex("assetPacks = [\":install_time_pack\"]");
|
||||
if (!regex2.IsMatch(buildGradleText))
|
||||
{
|
||||
var regex22 = new Regex("android {");
|
||||
buildGradleText = regex22.Replace(buildGradleText, "android {\n assetPacks = [\":install_time_pack\"]");
|
||||
}
|
||||
File.WriteAllText(buildGradlePath, buildGradleText);
|
||||
Debug.Log("Android转换为AAB工程完成");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user