update: 增加 Launcher 模版的 namespace 属性
parent
018fb2c35b
commit
88efffa89f
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该版本中不再使用 R8
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
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
|
|||
|
||||
|
||||
/// <summary>
|
||||
/// 写入所有的配置文件
|
||||
/// 写入 settings.gradle 配置文件
|
||||
/// </summary>
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue