feat(integration): 添加 AppLovin SDK 集成管理功能

- 实现 AppLovinIntegrationManagerUtils 版本比较工具类
- 添加 AppLovinPackageManager 处理 UPM 和 Assets 包管理
- 实现 AppLovinPluginMigrationHelper 插件迁移辅助功能
- 添加 AppLovinUpmManifest 管理 UPM 清单文件操作
- 支持 mediation adapter 的版本检测和安装管理
- 实现重复适配器检测和删除功能
This commit is contained in:
2026-01-20 19:01:21 +08:00
parent 4da1b3290e
commit 5b3dfd98c2
76 changed files with 3768 additions and 3668 deletions

View File

@@ -8,6 +8,7 @@
#if UNITY_ANDROID
using System.Xml.Linq;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
@@ -18,9 +19,11 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
/// </summary>
public class AppLovinPreProcessAndroid : AppLovinProcessGradleBuildFile, IPreprocessBuildWithReport
{
private const string UmpLegacyDependencyLine = "<androidPackage spec=\"com.google.android.ump:user-messaging-platform:2.1.0\" />";
private const string UmpDependencyLine = "<androidPackage spec=\"com.google.android.ump:user-messaging-platform:2.+\" />";
private const string AndroidPackagesContainerElementString = "androidPackages";
private const string ElementNameAndroidPackages = "androidPackages";
private const string ElementNameAndroidPackage = "androidPackage";
private const string AttributeNameSpec = "spec";
private const string UmpDependencyPackage = "com.google.android.ump:user-messaging-platform:";
private const string UmpDependencyVersion = "2.1.0";
public void OnPreprocessBuild(BuildReport report)
{
@@ -33,33 +36,74 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
// We can only process gradle template file here. If it is not available, we will try again in post build on Unity IDEs newer than 2018_2 (see AppLovinPostProcessGradleProject).
if (!AppLovinIntegrationManager.GradleTemplateEnabled) return;
#if UNITY_2019_3_OR_NEWER
// The publisher could be migrating from older Unity versions to 2019_3 or newer.
// If so, we should delete the plugin from the template. The plugin will be added to the project's application module in the post processing script (AppLovinPostProcessGradleProject).
RemoveAppLovinQualityServiceOrSafeDkPlugin(AppLovinIntegrationManager.GradleTemplatePath);
#else
AddAppLovinQualityServicePlugin(AppLovinIntegrationManager.GradleTemplatePath);
#endif
}
private static void AddGoogleCmpDependencyIfNeeded()
{
// Remove the legacy fixed UMP version if it exists, we'll add the dependency with a dynamic version below.
TryRemoveStringFromDependencyFile(UmpLegacyDependencyLine, AndroidPackagesContainerElementString);
if (AppLovinInternalSettings.Instance.ConsentFlowEnabled)
{
TryAddStringToDependencyFile(UmpDependencyLine, AndroidPackagesContainerElementString);
var umpPackage = new XElement(ElementNameAndroidPackage,
new XAttribute(AttributeNameSpec, UmpDependencyPackage + UmpDependencyVersion));
var success = AddOrUpdateAndroidDependency(UmpDependencyPackage, umpPackage );
if (!success)
{
MaxSdkLogger.UserWarning("Google CMP will not function. Unable to add user-messaging-platform dependency.");
}
}
else
{
TryRemoveStringFromDependencyFile(UmpDependencyLine, AndroidPackagesContainerElementString);
RemoveAndroidDependency(UmpDependencyPackage);
}
}
/// <summary>
/// Adds or updates an Android dependency in the AppLovin Dependencies.xml file.
/// </summary>
/// <param name="package">The package that we are trying to update</param>
/// <param name="newDependency">The new dependency to add if it doesn't exist</param>
/// <returns>Returns true if the file was successfully edited</returns>
private static bool AddOrUpdateAndroidDependency(string package, XElement newDependency)
{
var dependenciesFilePath = AppLovinDependenciesFilePath;
var dependenciesDocument = GetAppLovinDependenciesFile(dependenciesFilePath, AppLovinIntegrationManager.IsPluginInPackageManager);
if (dependenciesDocument == null) return false;
AddOrUpdateDependency(dependenciesDocument,
ElementNameAndroidPackages,
ElementNameAndroidPackage,
AttributeNameSpec,
package,
newDependency);
return SaveDependenciesFile(dependenciesDocument, dependenciesFilePath);
}
/// <summary>
/// Removed an android dependency from the AppLovin Dependencies.xml file.
/// </summary>
/// <param name="package">The package to remove</param>
private static void RemoveAndroidDependency(string package)
{
var dependenciesFilePath = AppLovinDependenciesFilePath;
var dependenciesDocument = GetAppLovinDependenciesFile(dependenciesFilePath);
if (dependenciesDocument == null) return;
var removed = RemoveDependency(dependenciesDocument,
ElementNameAndroidPackages,
ElementNameAndroidPackage,
AttributeNameSpec,
package);
if (!removed) return;
SaveDependenciesFile(dependenciesDocument, dependenciesFilePath);
}
public int callbackOrder
{
get { return int.MaxValue; }
get { return CallbackOrder; }
}
}
}