You've already forked Commercialization.topon
1.0.10
This commit is contained in:
94
Assets/Topon_Adapter/Editor/AD_BuildAndroidProcess.cs
Normal file
94
Assets/Topon_Adapter/Editor/AD_BuildAndroidProcess.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
#if UNITY_ANDROID
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Android;
|
||||
|
||||
namespace Topon_Adapter.Editor
|
||||
{
|
||||
public class AD_BuildAndroidProcess : IPostGenerateGradleAndroidProject
|
||||
{
|
||||
private static readonly XNamespace AndroidNamespace = "http://schemas.android.com/apk/res/android";
|
||||
private static readonly XNamespace ToolsNamespace = "http://schemas.android.com/tools";
|
||||
|
||||
|
||||
public void OnPostGenerateGradleAndroidProject(string path)
|
||||
{
|
||||
ProcessAndroidManifest(path);
|
||||
}
|
||||
|
||||
|
||||
public static void ProcessAndroidManifest(string path)
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
var manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");
|
||||
#else
|
||||
var manifestPath = Path.Combine(path, "unityLibrary/src/main/AndroidManifest.xml");
|
||||
#endif
|
||||
// var manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");
|
||||
XDocument manifest;
|
||||
try
|
||||
{
|
||||
manifest = XDocument.Load(manifestPath);
|
||||
}
|
||||
#pragma warning disable 0168
|
||||
catch (IOException exception)
|
||||
#pragma warning restore 0168
|
||||
{
|
||||
ATLog.log("[BuildAndroidProcess] AndroidManifest.xml is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the `manifest` element.
|
||||
var elementManifest = manifest.Element("manifest");
|
||||
if (elementManifest == null)
|
||||
{
|
||||
ATLog.log("[BuildAndroidProcess] AndroidManifest.xml is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
var elementApplication = elementManifest.Element("application");
|
||||
if (elementApplication == null)
|
||||
{
|
||||
ATLog.log("[BuildAndroidProcess] AndroidManifest.xml is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
elementManifest.Add(CreateQueries());
|
||||
elementApplication.Add(CreateActivityXML());
|
||||
|
||||
// Save the updated manifest file.
|
||||
manifest.Save(manifestPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加微信开放平台的适配
|
||||
/// </summary>
|
||||
public static XElement CreateActivityXML()
|
||||
{
|
||||
|
||||
var metaData = new XElement("activity");
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "name", ".wxapi.WXEntryActivity"));
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "label", "@string/app_name"));
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "theme", "@android:style/Theme.Translucent.NoTitleBar"));
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "exported", "true"));
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "taskAffinity", Application.identifier));
|
||||
metaData.Add(new XAttribute(AndroidNamespace + "launchMode", "singleTask"));
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public static XElement CreateQueries()
|
||||
{
|
||||
var metaData = new XElement("queries");
|
||||
var packageData = new XElement("package");
|
||||
packageData.Add(new XAttribute(AndroidNamespace + "name", "com.tencent.mm"));
|
||||
metaData.Add(packageData);
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public int callbackOrder { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user