update: 增加 Launcher 模版的 namespace 属性

main
胡宇飞 2024-08-15 13:21:24 +08:00
parent 018fb2c35b
commit 88efffa89f
2 changed files with 22 additions and 21 deletions

View File

@ -5,7 +5,8 @@ dependencies {
} }
android { android {
compileSdkVersion **APIVERSION** namespace "**NAMESPACE**"
compileSdkVersion **TARGETSDKVERSION**
buildToolsVersion '**BUILDTOOLS**' buildToolsVersion '**BUILDTOOLS**'
compileOptions { compileOptions {
@ -22,6 +23,7 @@ android {
} }
versionCode **VERSIONCODE** versionCode **VERSIONCODE**
versionName '**VERSIONNAME**' versionName '**VERSIONNAME**'
multiDexEnabled true
} }
aaptOptions { aaptOptions {

View File

@ -11,28 +11,28 @@ namespace Guru.Editor
public class AndroidProjectMod public class AndroidProjectMod
{ {
private const int TargetSDKVersion = 34; private const int TargetSDKVersion = 34;
private const string K_ANRDROID_PLUGINS_NAME = "Plugins/Android"; private const string K_ANDROID_PLUGINS_NAME = "Plugins/Android";
private const string LauncherName = "launcherTemplate"; private const string LauncherName = "launcherTemplate";
private static string LauncherFullPath = Path.Combine(Application.dataPath, $"{K_ANRDROID_PLUGINS_NAME}/{LauncherName}.gradle"); private static readonly string LauncherFullPath = Path.Combine(Application.dataPath, $"{K_ANDROID_PLUGINS_NAME}/{LauncherName}.gradle");
private const string MainName = "mainTemplate"; private const string MainName = "mainTemplate";
private static string MainFullPath = Path.Combine(Application.dataPath, $"{K_ANRDROID_PLUGINS_NAME}/{MainName}.gradle"); private static readonly string MainFullPath = Path.Combine(Application.dataPath, $"{K_ANDROID_PLUGINS_NAME}/{MainName}.gradle");
private const string BaseProjectName = "baseProjectTemplate"; private const string BaseProjectName = "baseProjectTemplate";
private static string BaseProjectFullPath = Path.Combine(Application.dataPath, $"{K_ANRDROID_PLUGINS_NAME}/{BaseProjectName}.gradle"); private static readonly string BaseProjectFullPath = Path.Combine(Application.dataPath, $"{K_ANDROID_PLUGINS_NAME}/{BaseProjectName}.gradle");
private const string PropertiesName = "gradleTemplate"; private const string PropertiesName = "gradleTemplate";
private const string K_ENABLE_R8 = "android.enableR8"; private const string K_ENABLE_R8 = "android.enableR8";
private static string PropertiesFullPath = Path.Combine(Application.dataPath, $"{K_ANRDROID_PLUGINS_NAME}/{PropertiesName}.properties"); private static readonly string PropertiesFullPath = Path.Combine(Application.dataPath, $"{K_ANDROID_PLUGINS_NAME}/{PropertiesName}.properties");
private const string SettingsName = "settingsTemplate"; private const string SettingsName = "settingsTemplate";
private static string SettingsFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{SettingsName}.gradle"); private static readonly string SettingsFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{SettingsName}.gradle");
private const string K_LINE_UNITYPROJECT = "def unityProjectPath"; private const string K_LINE_UNITY_PROJECT = "def unityProjectPath";
private const string ProguardUserName = "proguard-user"; private const string ProguardUserName = "proguard-user";
private static string ProguardUserFullPath = Path.Combine(Application.dataPath, $"{K_ANRDROID_PLUGINS_NAME}/{ProguardUserName}.txt"); private static readonly string ProguardUserFullPath = Path.Combine(Application.dataPath, $"{K_ANDROID_PLUGINS_NAME}/{ProguardUserName}.txt");
public static void Apply() public static void Apply()
{ {
@ -40,12 +40,11 @@ namespace Guru.Editor
ApplyBaseProjectTemplates(); ApplyBaseProjectTemplates();
ApplyMainTemplates(); ApplyMainTemplates();
ApplyGradleTemplate(); ApplyGradleTemplate();
// ApplySettings(); ApplySettings();
ApplyProguardUser(); ApplyProguardUser();
CheckTargetSDKVersion(); // 强制修复构建版本号 CheckTargetSDKVersion(); // 强制修复构建版本号
} }
private static void ApplyLauncher() private static void ApplyLauncher()
{ {
if (!File.Exists(LauncherFullPath)) if (!File.Exists(LauncherFullPath))
@ -59,10 +58,9 @@ namespace Guru.Editor
var ptn2 = "abortOnError false"; var ptn2 = "abortOnError false";
var lines = File.ReadAllLines(LauncherFullPath); var lines = File.ReadAllLines(LauncherFullPath);
string line = "";
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
{ {
line = lines[i]; var line = lines[i];
if (line.Contains(ptn1)) if (line.Contains(ptn1))
{ {
lines[i] = line.Replace(ptn1, "\n\n\tpackagingOptions {\n\t\texclude(\"META-INF/*.kotlin_module\")\n\t}\n\n"); lines[i] = line.Replace(ptn1, "\n\n\tpackagingOptions {\n\t\texclude(\"META-INF/*.kotlin_module\")\n\t}\n\n");
@ -98,8 +96,6 @@ namespace Guru.Editor
} }
} }
private static void ApplyGradleTemplate() private static void ApplyGradleTemplate()
{ {
if (!File.Exists(PropertiesFullPath)) if (!File.Exists(PropertiesFullPath))
@ -114,6 +110,10 @@ namespace Guru.Editor
} }
} }
/// <summary>
/// 该版本中不再使用 R8
/// </summary>
/// <param name="filePath"></param>
private static void FixGradleTemplate(string filePath) private static void FixGradleTemplate(string filePath)
{ {
if (File.Exists(filePath)) if (File.Exists(filePath))
@ -123,7 +123,7 @@ namespace Guru.Editor
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
{ {
if (lines[i].StartsWith(K_ENABLE_R8)) if (lines[i].Contains(K_ENABLE_R8))
{ {
lines[i] = $"# {lines[i]}"; // 禁用R8 lines[i] = $"# {lines[i]}"; // 禁用R8
isDirty = true; isDirty = true;
@ -137,7 +137,7 @@ namespace Guru.Editor
/// <summary> /// <summary>
/// 写入所有的配置文件 /// 写入 settings.gradle 配置文件
/// </summary> /// </summary>
private static void ApplySettings() private static void ApplySettings()
{ {
@ -148,7 +148,6 @@ namespace Guru.Editor
FixProjectPathInSettings(SettingsFullPath); FixProjectPathInSettings(SettingsFullPath);
} }
private static void FixProjectPathInSettings(string settingsPath) private static void FixProjectPathInSettings(string settingsPath)
{ {
bool isDirty = false; bool isDirty = false;
@ -158,7 +157,7 @@ namespace Guru.Editor
var lines = File.ReadAllLines(settingsPath); var lines = File.ReadAllLines(settingsPath);
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
{ {
if (lines[i].Contains(K_LINE_UNITYPROJECT)) if (lines[i].Contains(K_LINE_UNITY_PROJECT))
{ {
lines[i] = $" def unityProjectPath = $/file:////{projectPath}/$.replace(\"\\\\\", \"/\")"; lines[i] = $" def unityProjectPath = $/file:////{projectPath}/$.replace(\"\\\\\", \"/\")";
isDirty = true; isDirty = true;