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

@@ -24,11 +24,9 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
/// </summary>
public class AppLovinPostProcessAndroid : IPostGenerateGradleAndroidProject
{
#if UNITY_2019_3_OR_NEWER
private const string PropertyAndroidX = "android.useAndroidX";
private const string PropertyJetifier = "android.enableJetifier";
private const string EnableProperty = "=true";
#endif
private const string PropertyDexingArtifactTransform = "android.enableDexingArtifactTransform";
private const string DisableProperty = "=false";
@@ -44,16 +42,12 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
private const string AppLovinSettingsFileName = "applovin_settings.json";
private const string KeyTermsFlowSettings = "terms_flow_settings";
private const string KeyTermsFlowEnabled = "terms_flow_enabled";
private const string KeyTermsFlowTermsOfService = "terms_flow_terms_of_service";
private const string KeyTermsFlowPrivacyPolicy = "terms_flow_privacy_policy";
private const string KeySdkKey = "sdk_key";
private const string KeyConsentFlowSettings = "consent_flow_settings";
private const string KeyConsentFlowEnabled = "consent_flow_enabled";
private const string KeyConsentFlowTermsOfService = "consent_flow_terms_of_service";
private const string KeyConsentFlowPrivacyPolicy = "consent_flow_privacy_policy";
private const string KeyConsentFlowShowTermsAndPrivacyPolicyAlertInGDPR = "consent_flow_show_terms_and_privacy_policy_alert_in_gdpr";
private const string KeyConsentFlowDebugUserGeography = "consent_flow_debug_user_geography";
private const string KeyRenderOutsideSafeArea = "render_outside_safe_area";
@@ -72,26 +66,11 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
private static readonly XNamespace AndroidNamespace = "http://schemas.android.com/apk/res/android";
private static string PluginMediationDirectory
{
get
{
var pluginParentDir = AppLovinIntegrationManager.MediationSpecificPluginParentDirectory;
return Path.Combine(pluginParentDir, "MaxSdk/Mediation/");
}
}
public void OnPostGenerateGradleAndroidProject(string path)
{
#if UNITY_2019_3_OR_NEWER
var rootGradleBuildFilePath = Path.Combine(path, "../build.gradle");
var gradlePropertiesPath = Path.Combine(path, "../gradle.properties");
var gradleWrapperPropertiesPath = Path.Combine(path, "../gradle/wrapper/gradle-wrapper.properties");
#else
var rootGradleBuildFilePath = Path.Combine(path, "build.gradle");
var gradlePropertiesPath = Path.Combine(path, "gradle.properties");
var gradleWrapperPropertiesPath = Path.Combine(path, "gradle/wrapper/gradle-wrapper.properties");
#endif
UpdateGradleVersionsIfNeeded(gradleWrapperPropertiesPath, rootGradleBuildFilePath);
@@ -102,20 +81,13 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
{
var lines = File.ReadAllLines(gradlePropertiesPath);
#if UNITY_2019_3_OR_NEWER
// Add all properties except AndroidX, Jetifier, and DexingArtifactTransform since they may already exist. We will re-add them below.
gradlePropertiesUpdated.AddRange(lines.Where(line => !line.Contains(PropertyAndroidX) && !line.Contains(PropertyJetifier) && !line.Contains(PropertyDexingArtifactTransform)));
#else
// Add all properties except DexingArtifactTransform since it may already exist. We will re-add it below.
gradlePropertiesUpdated.AddRange(lines.Where(line => !line.Contains(PropertyDexingArtifactTransform)));
#endif
}
#if UNITY_2019_3_OR_NEWER
// Enable AndroidX and Jetifier properties
gradlePropertiesUpdated.Add(PropertyAndroidX + EnableProperty);
gradlePropertiesUpdated.Add(PropertyJetifier + EnableProperty);
#endif
// `DexingArtifactTransform` has been removed in Gradle 8+ which is the default Gradle version for Unity 6.
#if !UNITY_6000_0_OR_NEWER
@@ -139,7 +111,7 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
public int callbackOrder
{
get { return int.MaxValue; }
get { return AppLovinPreProcess.CallbackOrder; }
}
private static void ProcessAndroidManifest(string path)
@@ -223,7 +195,7 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
private static void AddGoogleApplicationIdIfNeeded(XElement elementApplication, IEnumerable<XElement> metaDataElements)
{
if (!AppLovinIntegrationManager.IsAdapterInstalled("Google") && !AppLovinIntegrationManager.IsAdapterInstalled("GoogleAdManager")) return;
if (!AppLovinPackageManager.IsAdapterInstalled("Google") && !AppLovinPackageManager.IsAdapterInstalled("GoogleAdManager")) return;
var googleApplicationIdMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataGoogleApplicationId);
var appId = AppLovinSettings.Instance.AdMobAndroidAppId;
@@ -248,7 +220,7 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
private static void AddGoogleOptimizationFlagsIfNeeded(XElement elementApplication, IEnumerable<XElement> metaDataElements)
{
if (!AppLovinIntegrationManager.IsAdapterInstalled("Google") && !AppLovinIntegrationManager.IsAdapterInstalled("GoogleAdManager")) return;
if (!AppLovinPackageManager.IsAdapterInstalled("Google") && !AppLovinPackageManager.IsAdapterInstalled("GoogleAdManager")) return;
var googleOptimizeInitializationMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataGoogleOptimizeInitialization);
// If meta data doesn't exist, add it
@@ -267,7 +239,7 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
private static void DisableAutoInitIfNeeded(XElement elementApplication, IEnumerable<XElement> metaDataElements)
{
if (AppLovinIntegrationManager.IsAdapterInstalled("MobileFuse"))
if (AppLovinPackageManager.IsAdapterInstalled("MobileFuse"))
{
var mobileFuseMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataMobileFuseAutoInit);
// If MobileFuse meta data doesn't exist, add it
@@ -277,7 +249,7 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
}
}
if (AppLovinIntegrationManager.IsAdapterInstalled("MyTarget"))
if (AppLovinPackageManager.IsAdapterInstalled("MyTarget"))
{
var myTargetMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataMyTargetAutoInit);
// If MyTarget meta data doesn't exist, add it
@@ -358,15 +330,8 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
appLovinSdkSettings[KeySdkKey] = AppLovinSettings.Instance.SdkKey;
appLovinSdkSettings[KeyRenderOutsideSafeArea] = PlayerSettings.Android.renderOutsideSafeArea;
// Add the Consent/Terms flow settings if needed.
if (AppLovinInternalSettings.Instance.ConsentFlowEnabled)
{
EnableConsentFlowIfNeeded(rawResourceDirectory, appLovinSdkSettings);
}
else
{
EnableTermsFlowIfNeeded(rawResourceDirectory, appLovinSdkSettings);
}
// Add the Terms and Privacy Policy flow settings if needed.
EnableConsentFlowIfNeeded(rawResourceDirectory, appLovinSdkSettings);
WriteAppLovinSettings(rawResourceDirectory, appLovinSdkSettings);
}
@@ -399,6 +364,8 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
{
consentFlowSettings[KeyConsentFlowTermsOfService] = termsOfServiceUrl;
}
consentFlowSettings[KeyConsentFlowShowTermsAndPrivacyPolicyAlertInGDPR] = AppLovinInternalSettings.Instance.ShouldShowTermsAndPrivacyPolicyAlertInGDPR;
var debugUserGeography = AppLovinInternalSettings.Instance.DebugUserGeography;
if (debugUserGeography == MaxSdkBase.ConsentFlowUserGeography.Gdpr)
@@ -409,41 +376,6 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
applovinSdkSettings[KeyConsentFlowSettings] = consentFlowSettings;
}
private static void EnableTermsFlowIfNeeded(string rawResourceDirectory, Dictionary<string, object> applovinSdkSettings)
{
if (AppLovinInternalSettings.Instance.ConsentFlowEnabled) return;
// Check if terms flow is enabled for this format. No need to create the applovin_consent_flow_settings.json if consent flow is disabled.
var consentFlowEnabled = AppLovinSettings.Instance.ConsentFlowEnabled;
var consentFlowPlatform = AppLovinSettings.Instance.ConsentFlowPlatform;
if (!consentFlowEnabled || (consentFlowPlatform != Platform.All && consentFlowPlatform != Platform.Android))
{
RemoveAppLovinSettingsRawResourceFileIfNeeded(rawResourceDirectory);
return;
}
var privacyPolicyUrl = AppLovinSettings.Instance.ConsentFlowPrivacyPolicyUrl;
if (string.IsNullOrEmpty(privacyPolicyUrl))
{
AppLovinIntegrationManager.ShowBuildFailureDialog("You cannot use the AppLovin SDK's consent flow without defining a Privacy Policy URL in the AppLovin Integration Manager.");
// No need to update the applovin_consent_flow_settings.json here. Default consent flow state will be determined on the SDK side.
return;
}
var consentFlowSettings = new Dictionary<string, object>();
consentFlowSettings[KeyTermsFlowEnabled] = consentFlowEnabled;
consentFlowSettings[KeyTermsFlowPrivacyPolicy] = privacyPolicyUrl;
var termsOfServiceUrl = AppLovinSettings.Instance.ConsentFlowTermsOfServiceUrl;
if (MaxSdkUtils.IsValidString(termsOfServiceUrl))
{
consentFlowSettings[KeyTermsFlowTermsOfService] = termsOfServiceUrl;
}
applovinSdkSettings[KeyTermsFlowSettings] = consentFlowSettings;
}
private static void WriteAppLovinSettingsRawResourceFile(string applovinSdkSettingsJson, string rawResourceDirectory)
{
if (!Directory.Exists(rawResourceDirectory))