2024-01-24 02:08:49 +00:00
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
|
|
|
|
|
namespace Guru.Editor
|
|
|
|
|
{
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2024-01-24 02:08:49 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
|
2023-12-26 03:40:48 +00:00
|
|
|
public class AndroidProjectMod
|
|
|
|
|
{
|
2024-08-14 07:07:04 +00:00
|
|
|
private static readonly int TargetSDKVersion = 34;
|
2023-12-26 03:40:48 +00:00
|
|
|
|
|
|
|
|
private static readonly string LauncherName = "launcherTemplate";
|
|
|
|
|
private static string LauncherFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{LauncherName}.gradle");
|
|
|
|
|
|
|
|
|
|
private static readonly string MainName = "mainTemplate";
|
|
|
|
|
private static string MainFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{MainName}.gradle");
|
|
|
|
|
|
|
|
|
|
private static readonly string PropertiesName = "gradleTemplate";
|
|
|
|
|
private static string PropertiesFullPath = Path.Combine(Application.dataPath, $"Plugins/Android/{PropertiesName}.properties");
|
|
|
|
|
|
|
|
|
|
public static void Apply()
|
|
|
|
|
{
|
|
|
|
|
FixLauncher();
|
|
|
|
|
FixMain();
|
|
|
|
|
FixProperties();
|
|
|
|
|
CheckTargetSDKVersion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void FixLauncher()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(LauncherFullPath))
|
|
|
|
|
{
|
|
|
|
|
CopyFile($"{LauncherName}.txt", LauncherFullPath);
|
|
|
|
|
Debug.Log($"[MOD] --- Copy file to: {LauncherFullPath}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ptn1 = "**PACKAGING_OPTIONS**";
|
|
|
|
|
var ptn2 = "abortOnError false";
|
|
|
|
|
var lines = File.ReadAllLines(LauncherFullPath);
|
|
|
|
|
|
|
|
|
|
string line = "";
|
|
|
|
|
for (int i = 0; i < lines.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (line.Contains(ptn2))
|
|
|
|
|
{
|
|
|
|
|
if (lines[i + 1].Contains("}"))
|
|
|
|
|
{
|
|
|
|
|
lines[i + 1] = lines[i + 1].Replace("}", "\tcheckReleaseBuilds false\n\t}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Debug.Log($"[MOD] --- Fix file at: {LauncherFullPath}");
|
|
|
|
|
File.WriteAllLines(LauncherFullPath, lines);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private static void FixMain()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(MainFullPath))
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[MOD] --- Copy file to: {MainFullPath}");
|
|
|
|
|
CopyFile($"{MainName}.txt", MainFullPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void FixProperties()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(PropertiesFullPath))
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[MOD] --- Copy file to: {PropertiesFullPath}");
|
|
|
|
|
CopyFile($"{PropertiesName}.txt", PropertiesFullPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void CheckTargetSDKVersion()
|
|
|
|
|
{
|
|
|
|
|
var ver = (int) PlayerSettings.Android.targetSdkVersion;
|
|
|
|
|
if (ver < TargetSDKVersion)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[MOD] --- Fix target sdk version -> {TargetSDKVersion}");
|
|
|
|
|
PlayerSettings.Android.targetSdkVersion = (AndroidSdkVersions)TargetSDKVersion;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region File IO
|
|
|
|
|
|
|
|
|
|
private static string GetMoveFilePath(string fileName)
|
|
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
var path = GuruEditorHelper.GetAssetPath(nameof(AndroidProjectMod), "Script", true);
|
2024-01-24 02:08:49 +00:00
|
|
|
var files = Path.GetFullPath($"{path}/../../Files");
|
2023-12-26 03:40:48 +00:00
|
|
|
return $"{files}/{fileName}";
|
|
|
|
|
}
|
|
|
|
|
private static void CopyFile(string fileName, string toPath)
|
|
|
|
|
{
|
|
|
|
|
var from = GetMoveFilePath(fileName);
|
|
|
|
|
if (!string.IsNullOrEmpty(from))
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(from))
|
|
|
|
|
{
|
|
|
|
|
File.Copy(from, toPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|