41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
using UnityEditor.Build;
|
|
using UnityEditor.Build.Reporting;
|
|
using UnityEngine;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
|
|
public class BuildPostProcessor : IPreprocessBuildWithReport
|
|
{
|
|
public int callbackOrder => 0;
|
|
|
|
public void OnPreprocessBuild(BuildReport report)
|
|
{
|
|
if (report.summary.platform == BuildTarget.Android)
|
|
{
|
|
UpdateAndroidManifest();
|
|
}
|
|
}
|
|
|
|
private void UpdateAndroidManifest()
|
|
{
|
|
string manifestPath = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
|
|
|
|
if (File.Exists(manifestPath))
|
|
{
|
|
string manifestContent = File.ReadAllText(manifestPath);
|
|
string packageName = PlayerSettings.applicationIdentifier;
|
|
|
|
// 使用正则表达式匹配并替换 android:path 的值
|
|
string updatedContent = Regex.Replace(manifestContent,
|
|
@"android:path=""[^""]*""",
|
|
$"android:path=\"/{packageName}\"");
|
|
|
|
File.WriteAllText(manifestPath, updatedContent);
|
|
Debug.Log($"Updated AndroidManifest.xml with package name: {packageName}");
|
|
}
|
|
}
|
|
}
|
|
#endif
|