From 88efffa89f12427837ee2ec750a0dd594ac7f4ec Mon Sep 17 00:00:00 2001 From: huyufei Date: Thu, 15 Aug 2024 13:21:24 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=A2=9E=E5=8A=A0=20Launcher=20?= =?UTF-8?q?=E6=A8=A1=E7=89=88=E7=9A=84=20namespace=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/GuruManager/Files/launcherTemplate.txt | 4 +- .../GuruManager/Helper/AndroidProjectMod.cs | 39 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Editor/GuruManager/Files/launcherTemplate.txt b/Editor/GuruManager/Files/launcherTemplate.txt index 192f928..02b575f 100644 --- a/Editor/GuruManager/Files/launcherTemplate.txt +++ b/Editor/GuruManager/Files/launcherTemplate.txt @@ -5,7 +5,8 @@ dependencies { } android { - compileSdkVersion **APIVERSION** + namespace "**NAMESPACE**" + compileSdkVersion **TARGETSDKVERSION** buildToolsVersion '**BUILDTOOLS**' compileOptions { @@ -22,6 +23,7 @@ android { } versionCode **VERSIONCODE** versionName '**VERSIONNAME**' + multiDexEnabled true } aaptOptions { diff --git a/Editor/GuruManager/Helper/AndroidProjectMod.cs b/Editor/GuruManager/Helper/AndroidProjectMod.cs index 9cc885f..7d3b830 100644 --- a/Editor/GuruManager/Helper/AndroidProjectMod.cs +++ b/Editor/GuruManager/Helper/AndroidProjectMod.cs @@ -11,28 +11,28 @@ namespace Guru.Editor public class AndroidProjectMod { 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 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 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 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 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 static string SettingsFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{SettingsName}.gradle"); - private const string K_LINE_UNITYPROJECT = "def unityProjectPath"; + private static readonly string SettingsFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{SettingsName}.gradle"); + private const string K_LINE_UNITY_PROJECT = "def unityProjectPath"; 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() { @@ -40,12 +40,11 @@ namespace Guru.Editor ApplyBaseProjectTemplates(); ApplyMainTemplates(); ApplyGradleTemplate(); - // ApplySettings(); + ApplySettings(); ApplyProguardUser(); CheckTargetSDKVersion(); // 强制修复构建版本号 } - - + private static void ApplyLauncher() { if (!File.Exists(LauncherFullPath)) @@ -59,10 +58,9 @@ namespace Guru.Editor var ptn2 = "abortOnError false"; var lines = File.ReadAllLines(LauncherFullPath); - string line = ""; for (int i = 0; i < lines.Length; i++) { - line = lines[i]; + var line = lines[i]; if (line.Contains(ptn1)) { 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() { if (!File.Exists(PropertiesFullPath)) @@ -114,6 +110,10 @@ namespace Guru.Editor } } + /// + /// 该版本中不再使用 R8 + /// + /// private static void FixGradleTemplate(string filePath) { if (File.Exists(filePath)) @@ -123,7 +123,7 @@ namespace Guru.Editor 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 isDirty = true; @@ -137,7 +137,7 @@ namespace Guru.Editor /// - /// 写入所有的配置文件 + /// 写入 settings.gradle 配置文件 /// private static void ApplySettings() { @@ -147,8 +147,7 @@ namespace Guru.Editor } FixProjectPathInSettings(SettingsFullPath); } - - + private static void FixProjectPathInSettings(string settingsPath) { bool isDirty = false; @@ -158,7 +157,7 @@ namespace Guru.Editor var lines = File.ReadAllLines(settingsPath); 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(\"\\\\\", \"/\")"; isDirty = true;