sdk升级

This commit is contained in:
xiekaidong 2023-09-18 11:26:51 +08:00
parent 45ab702c1c
commit 74681e64c7
5 changed files with 878 additions and 878 deletions

View File

@ -410,7 +410,7 @@ namespace BFEditor.Build
var gradleFilePath2 = Path.Combine(PublishAsProjectPath, "unityLibrary", "build.gradle"); var gradleFilePath2 = Path.Combine(PublishAsProjectPath, "unityLibrary", "build.gradle");
var text2 = File.ReadAllText(gradleFilePath2); var text2 = File.ReadAllText(gradleFilePath2);
text2 = regex.Replace(text2, string.Format("versionCode {0}", versionCode)); text2 = regex.Replace(text2, string.Format("versionCode {0}", versionCode));
text2 = regex2.Replace(text, string.Format("versionName '{0}'", versionName)); text2 = regex2.Replace(text2, string.Format("versionName '{0}'", versionName));
File.WriteAllText(gradleFilePath2, text2); File.WriteAllText(gradleFilePath2, text2);
} }

View File

@ -23,250 +23,250 @@ namespace AppLovinMax.Scripts.Editor
/// <summary> /// <summary>
/// A post processor used to update the Android project once it is generated. /// A post processor used to update the Android project once it is generated.
/// </summary> /// </summary>
public class MaxPostProcessBuildAndroid : IPostGenerateGradleAndroidProject // public class MaxPostProcessBuildAndroid : IPostGenerateGradleAndroidProject
{ // {
#if UNITY_2019_3_OR_NEWER // #if UNITY_2019_3_OR_NEWER
private const string PropertyAndroidX = "android.useAndroidX"; // private const string PropertyAndroidX = "android.useAndroidX";
private const string PropertyJetifier = "android.enableJetifier"; // private const string PropertyJetifier = "android.enableJetifier";
private const string EnableProperty = "=true"; // private const string EnableProperty = "=true";
#endif // #endif
private const string PropertyDexingArtifactTransform = "android.enableDexingArtifactTransform"; // private const string PropertyDexingArtifactTransform = "android.enableDexingArtifactTransform";
private const string DisableProperty = "=false"; // private const string DisableProperty = "=false";
private const string KeyMetaDataAppLovinSdkKey = "applovin.sdk.key"; // private const string KeyMetaDataAppLovinSdkKey = "applovin.sdk.key";
private const string KeyMetaDataAppLovinVerboseLoggingOn = "applovin.sdk.verbose_logging"; // private const string KeyMetaDataAppLovinVerboseLoggingOn = "applovin.sdk.verbose_logging";
private const string KeyMetaDataGoogleApplicationId = "com.google.android.gms.ads.APPLICATION_ID"; // private const string KeyMetaDataGoogleApplicationId = "com.google.android.gms.ads.APPLICATION_ID";
private const string KeyMetaDataGoogleAdManagerApp = "com.google.android.gms.ads.AD_MANAGER_APP"; // private const string KeyMetaDataGoogleAdManagerApp = "com.google.android.gms.ads.AD_MANAGER_APP";
private static readonly XNamespace AndroidNamespace = "http://schemas.android.com/apk/res/android"; // private static readonly XNamespace AndroidNamespace = "http://schemas.android.com/apk/res/android";
private static string PluginMediationDirectory // private static string PluginMediationDirectory
{ // {
get // get
{ // {
var pluginParentDir = AppLovinIntegrationManager.MediationSpecificPluginParentDirectory; // var pluginParentDir = AppLovinIntegrationManager.MediationSpecificPluginParentDirectory;
return Path.Combine(pluginParentDir, "MaxSdk/Mediation/"); // return Path.Combine(pluginParentDir, "MaxSdk/Mediation/");
} // }
} // }
public void OnPostGenerateGradleAndroidProject(string path) // public void OnPostGenerateGradleAndroidProject(string path)
{ // {
#if UNITY_2019_3_OR_NEWER // #if UNITY_2019_3_OR_NEWER
var gradlePropertiesPath = Path.Combine(path, "../gradle.properties"); // var gradlePropertiesPath = Path.Combine(path, "../gradle.properties");
#else // #else
var gradlePropertiesPath = Path.Combine(path, "gradle.properties"); // var gradlePropertiesPath = Path.Combine(path, "gradle.properties");
#endif // #endif
var gradlePropertiesUpdated = new List<string>(); // var gradlePropertiesUpdated = new List<string>();
// If the gradle properties file already exists, make sure to add any previous properties. // // If the gradle properties file already exists, make sure to add any previous properties.
if (File.Exists(gradlePropertiesPath)) // if (File.Exists(gradlePropertiesPath))
{ // {
var lines = File.ReadAllLines(gradlePropertiesPath); // var lines = File.ReadAllLines(gradlePropertiesPath);
#if UNITY_2019_3_OR_NEWER // #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. // // 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))); // gradlePropertiesUpdated.AddRange(lines.Where(line => !line.Contains(PropertyAndroidX) && !line.Contains(PropertyJetifier) && !line.Contains(PropertyDexingArtifactTransform)));
#else // #else
// Add all properties except DexingArtifactTransform since it may already exist. We will re-add it below. // // Add all properties except DexingArtifactTransform since it may already exist. We will re-add it below.
gradlePropertiesUpdated.AddRange(lines.Where(line => !line.Contains(PropertyDexingArtifactTransform))); // gradlePropertiesUpdated.AddRange(lines.Where(line => !line.Contains(PropertyDexingArtifactTransform)));
#endif // #endif
} // }
#if UNITY_2019_3_OR_NEWER // #if UNITY_2019_3_OR_NEWER
// Enable AndroidX and Jetifier properties // // Enable AndroidX and Jetifier properties
gradlePropertiesUpdated.Add(PropertyAndroidX + EnableProperty); // gradlePropertiesUpdated.Add(PropertyAndroidX + EnableProperty);
gradlePropertiesUpdated.Add(PropertyJetifier + EnableProperty); // gradlePropertiesUpdated.Add(PropertyJetifier + EnableProperty);
#endif // #endif
// Disable dexing using artifact transform (it causes issues for ExoPlayer with Gradle plugin 3.5.0+) // // Disable dexing using artifact transform (it causes issues for ExoPlayer with Gradle plugin 3.5.0+)
gradlePropertiesUpdated.Add(PropertyDexingArtifactTransform + DisableProperty); // gradlePropertiesUpdated.Add(PropertyDexingArtifactTransform + DisableProperty);
try // try
{ // {
File.WriteAllText(gradlePropertiesPath, string.Join("\n", gradlePropertiesUpdated.ToArray()) + "\n"); // File.WriteAllText(gradlePropertiesPath, string.Join("\n", gradlePropertiesUpdated.ToArray()) + "\n");
} // }
catch (Exception exception) // catch (Exception exception)
{ // {
MaxSdkLogger.UserError("Failed to enable AndroidX and Jetifier. gradle.properties file write failed."); // MaxSdkLogger.UserError("Failed to enable AndroidX and Jetifier. gradle.properties file write failed.");
Console.WriteLine(exception); // Console.WriteLine(exception);
} // }
ProcessAndroidManifest(path); // ProcessAndroidManifest(path);
var rawResourceDirectory = Path.Combine(path, "src/main/res/raw"); // var rawResourceDirectory = Path.Combine(path, "src/main/res/raw");
if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager) // if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager)
{ // {
// For Unity 2018.1 or older, the consent flow is enabled in AppLovinPreProcessAndroid. // // For Unity 2018.1 or older, the consent flow is enabled in AppLovinPreProcessAndroid.
AppLovinPreProcessAndroid.EnableConsentFlowIfNeeded(rawResourceDirectory); // AppLovinPreProcessAndroid.EnableConsentFlowIfNeeded(rawResourceDirectory);
} // }
else // else
{ // {
AppLovinPreProcessAndroid.EnableTermsFlowIfNeeded(rawResourceDirectory); // AppLovinPreProcessAndroid.EnableTermsFlowIfNeeded(rawResourceDirectory);
} // }
} // }
public int callbackOrder // public int callbackOrder
{ // {
get { return int.MaxValue; } // get { return int.MaxValue; }
} // }
private static void ProcessAndroidManifest(string path) // private static void ProcessAndroidManifest(string path)
{ // {
var manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml"); // var manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");
XDocument manifest; // XDocument manifest;
try // try
{ // {
manifest = XDocument.Load(manifestPath); // manifest = XDocument.Load(manifestPath);
} // }
#pragma warning disable 0168 // #pragma warning disable 0168
catch (IOException exception) // catch (IOException exception)
#pragma warning restore 0168 // #pragma warning restore 0168
{ // {
MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is missing."); // MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is missing.");
return; // return;
} // }
// Get the `manifest` element. // // Get the `manifest` element.
var elementManifest = manifest.Element("manifest"); // var elementManifest = manifest.Element("manifest");
if (elementManifest == null) // if (elementManifest == null)
{ // {
MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid."); // MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid.");
return; // return;
} // }
var elementApplication = elementManifest.Element("application"); // var elementApplication = elementManifest.Element("application");
if (elementApplication == null) // if (elementApplication == null)
{ // {
MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid."); // MaxSdkLogger.UserWarning("[AppLovin MAX] AndroidManifest.xml is invalid.");
return; // return;
} // }
var metaDataElements = elementApplication.Descendants().Where(element => element.Name.LocalName.Equals("meta-data")); // var metaDataElements = elementApplication.Descendants().Where(element => element.Name.LocalName.Equals("meta-data"));
AddSdkKeyIfNeeded(elementApplication); // AddSdkKeyIfNeeded(elementApplication);
EnableVerboseLoggingIfNeeded(elementApplication); // EnableVerboseLoggingIfNeeded(elementApplication);
AddGoogleApplicationIdIfNeeded(elementApplication, metaDataElements); // AddGoogleApplicationIdIfNeeded(elementApplication, metaDataElements);
// Save the updated manifest file. // // Save the updated manifest file.
manifest.Save(manifestPath); // manifest.Save(manifestPath);
} // }
private static void AddSdkKeyIfNeeded(XElement elementApplication) // private static void AddSdkKeyIfNeeded(XElement elementApplication)
{ // {
var sdkKey = AppLovinSettings.Instance.SdkKey; // var sdkKey = AppLovinSettings.Instance.SdkKey;
if (string.IsNullOrEmpty(sdkKey)) return; // if (string.IsNullOrEmpty(sdkKey)) return;
var descendants = elementApplication.Descendants(); // var descendants = elementApplication.Descendants();
var sdkKeyMetaData = descendants.FirstOrDefault(descendant => descendant.FirstAttribute != null && // var sdkKeyMetaData = descendants.FirstOrDefault(descendant => descendant.FirstAttribute != null &&
descendant.FirstAttribute.Name.LocalName.Equals("name") && // descendant.FirstAttribute.Name.LocalName.Equals("name") &&
descendant.FirstAttribute.Value.Equals(KeyMetaDataAppLovinSdkKey) && // descendant.FirstAttribute.Value.Equals(KeyMetaDataAppLovinSdkKey) &&
descendant.LastAttribute != null && // descendant.LastAttribute != null &&
descendant.LastAttribute.Name.LocalName.Equals("value")); // descendant.LastAttribute.Name.LocalName.Equals("value"));
// check if applovin.sdk.key meta data exists. // // check if applovin.sdk.key meta data exists.
if (sdkKeyMetaData != null) // if (sdkKeyMetaData != null)
{ // {
sdkKeyMetaData.LastAttribute.Value = sdkKey; // sdkKeyMetaData.LastAttribute.Value = sdkKey;
} // }
else // else
{ // {
// add applovin.sdk.key meta data if it does not exist. // // add applovin.sdk.key meta data if it does not exist.
var metaData = CreateMetaDataElement(KeyMetaDataAppLovinSdkKey, sdkKey); // var metaData = CreateMetaDataElement(KeyMetaDataAppLovinSdkKey, sdkKey);
elementApplication.Add(metaData); // elementApplication.Add(metaData);
} // }
} // }
private static void EnableVerboseLoggingIfNeeded(XElement elementApplication) // private static void EnableVerboseLoggingIfNeeded(XElement elementApplication)
{ // {
var enabled = EditorPrefs.GetBool(MaxSdkLogger.KeyVerboseLoggingEnabled, false); // var enabled = EditorPrefs.GetBool(MaxSdkLogger.KeyVerboseLoggingEnabled, false);
var descendants = elementApplication.Descendants(); // var descendants = elementApplication.Descendants();
var verboseLoggingMetaData = descendants.FirstOrDefault(descendant => descendant.FirstAttribute != null && // var verboseLoggingMetaData = descendants.FirstOrDefault(descendant => descendant.FirstAttribute != null &&
descendant.FirstAttribute.Name.LocalName.Equals("name") && // descendant.FirstAttribute.Name.LocalName.Equals("name") &&
descendant.FirstAttribute.Value.Equals(KeyMetaDataAppLovinVerboseLoggingOn) && // descendant.FirstAttribute.Value.Equals(KeyMetaDataAppLovinVerboseLoggingOn) &&
descendant.LastAttribute != null && // descendant.LastAttribute != null &&
descendant.LastAttribute.Name.LocalName.Equals("value")); // descendant.LastAttribute.Name.LocalName.Equals("value"));
// check if applovin.sdk.verbose_logging meta data exists. // // check if applovin.sdk.verbose_logging meta data exists.
if (verboseLoggingMetaData != null) // if (verboseLoggingMetaData != null)
{ // {
if (enabled) // if (enabled)
{ // {
// update applovin.sdk.verbose_logging meta data value. // // update applovin.sdk.verbose_logging meta data value.
verboseLoggingMetaData.LastAttribute.Value = enabled.ToString(); // verboseLoggingMetaData.LastAttribute.Value = enabled.ToString();
} // }
else // else
{ // {
// remove applovin.sdk.verbose_logging meta data. // // remove applovin.sdk.verbose_logging meta data.
verboseLoggingMetaData.Remove(); // verboseLoggingMetaData.Remove();
} // }
} // }
else // else
{ // {
if (enabled) // if (enabled)
{ // {
// add applovin.sdk.verbose_logging meta data if it does not exist. // // add applovin.sdk.verbose_logging meta data if it does not exist.
var metaData = CreateMetaDataElement(KeyMetaDataAppLovinVerboseLoggingOn, enabled.ToString()); // var metaData = CreateMetaDataElement(KeyMetaDataAppLovinVerboseLoggingOn, enabled.ToString());
elementApplication.Add(metaData); // elementApplication.Add(metaData);
} // }
} // }
} // }
private static void AddGoogleApplicationIdIfNeeded(XElement elementApplication, IEnumerable<XElement> metaDataElements) // private static void AddGoogleApplicationIdIfNeeded(XElement elementApplication, IEnumerable<XElement> metaDataElements)
{ // {
if (!AppLovinIntegrationManager.IsAdapterInstalled("Google") && !AppLovinIntegrationManager.IsAdapterInstalled("GoogleAdManager")) return; // if (!AppLovinIntegrationManager.IsAdapterInstalled("Google") && !AppLovinIntegrationManager.IsAdapterInstalled("GoogleAdManager")) return;
var googleApplicationIdMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataGoogleApplicationId); // var googleApplicationIdMetaData = GetMetaDataElement(metaDataElements, KeyMetaDataGoogleApplicationId);
var appId = AppLovinSettings.Instance.AdMobAndroidAppId; // var appId = AppLovinSettings.Instance.AdMobAndroidAppId;
// Log error if the App ID is not set. // // Log error if the App ID is not set.
if (string.IsNullOrEmpty(appId) || !appId.StartsWith("ca-app-pub-")) // if (string.IsNullOrEmpty(appId) || !appId.StartsWith("ca-app-pub-"))
{ // {
MaxSdkLogger.UserError("Google App ID is not set. Please enter a valid app ID within the AppLovin Integration Manager window."); // MaxSdkLogger.UserError("Google App ID is not set. Please enter a valid app ID within the AppLovin Integration Manager window.");
return; // return;
} // }
// Check if the Google App ID meta data already exists. Update if it already exists. // // Check if the Google App ID meta data already exists. Update if it already exists.
if (googleApplicationIdMetaData != null) // if (googleApplicationIdMetaData != null)
{ // {
googleApplicationIdMetaData.SetAttributeValue(AndroidNamespace + "value", appId); // googleApplicationIdMetaData.SetAttributeValue(AndroidNamespace + "value", appId);
} // }
// Meta data doesn't exist, add it. // // Meta data doesn't exist, add it.
else // else
{ // {
elementApplication.Add(CreateMetaDataElement(KeyMetaDataGoogleApplicationId, appId)); // elementApplication.Add(CreateMetaDataElement(KeyMetaDataGoogleApplicationId, appId));
} // }
} // }
/// <summary> // /// <summary>
/// Creates and returns a <c>meta-data</c> element with the given name and value. // /// Creates and returns a <c>meta-data</c> element with the given name and value.
/// </summary> // /// </summary>
private static XElement CreateMetaDataElement(string name, object value) // private static XElement CreateMetaDataElement(string name, object value)
{ // {
var metaData = new XElement("meta-data"); // var metaData = new XElement("meta-data");
metaData.Add(new XAttribute(AndroidNamespace + "name", name)); // metaData.Add(new XAttribute(AndroidNamespace + "name", name));
metaData.Add(new XAttribute(AndroidNamespace + "value", value)); // metaData.Add(new XAttribute(AndroidNamespace + "value", value));
return metaData; // return metaData;
} // }
/// <summary> // /// <summary>
/// Looks through all the given meta-data elements to check if the required one exists. Returns <c>null</c> if it doesn't exist. // /// Looks through all the given meta-data elements to check if the required one exists. Returns <c>null</c> if it doesn't exist.
/// </summary> // /// </summary>
private static XElement GetMetaDataElement(IEnumerable<XElement> metaDataElements, string metaDataName) // private static XElement GetMetaDataElement(IEnumerable<XElement> metaDataElements, string metaDataName)
{ // {
foreach (var metaDataElement in metaDataElements) // foreach (var metaDataElement in metaDataElements)
{ // {
var attributes = metaDataElement.Attributes(); // var attributes = metaDataElement.Attributes();
if (attributes.Any(attribute => attribute.Name.Namespace.Equals(AndroidNamespace) // if (attributes.Any(attribute => attribute.Name.Namespace.Equals(AndroidNamespace)
&& attribute.Name.LocalName.Equals("name") // && attribute.Name.LocalName.Equals("name")
&& attribute.Value.Equals(metaDataName))) // && attribute.Value.Equals(metaDataName)))
{ // {
return metaDataElement; // return metaDataElement;
} // }
} // }
return null; // return null;
} // }
} // }
} }
#endif #endif

View File

@ -17,49 +17,49 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
/// <summary> /// <summary>
/// Adds Quality Service plugin to the Gradle project once the project has been exported. See <see cref="AppLovinProcessGradleBuildFile"/> for more details. /// Adds Quality Service plugin to the Gradle project once the project has been exported. See <see cref="AppLovinProcessGradleBuildFile"/> for more details.
/// </summary> /// </summary>
public class AppLovinPostProcessGradleProject : AppLovinProcessGradleBuildFile, IPostGenerateGradleAndroidProject // public class AppLovinPostProcessGradleProject : AppLovinProcessGradleBuildFile, IPostGenerateGradleAndroidProject
{ // {
public void OnPostGenerateGradleAndroidProject(string path) // public void OnPostGenerateGradleAndroidProject(string path)
{ // {
if (!AppLovinSettings.Instance.QualityServiceEnabled) return; // if (!AppLovinSettings.Instance.QualityServiceEnabled) return;
#if UNITY_2019_3_OR_NEWER // #if UNITY_2019_3_OR_NEWER
// On Unity 2019.3+, the path returned is the path to the unityLibrary's module. // // On Unity 2019.3+, the path returned is the path to the unityLibrary's module.
// The AppLovin Quality Service buildscript closure related lines need to be added to the root build.gradle file. // // The AppLovin Quality Service buildscript closure related lines need to be added to the root build.gradle file.
var rootGradleBuildFilePath = Path.Combine(path, "../build.gradle"); // var rootGradleBuildFilePath = Path.Combine(path, "../build.gradle");
#if UNITY_2022_2_OR_NEWER // #if UNITY_2022_2_OR_NEWER
if (!AddPluginToRootGradleBuildFile(rootGradleBuildFilePath)) return; // if (!AddPluginToRootGradleBuildFile(rootGradleBuildFilePath)) return;
var rootSettingsGradleFilePath = Path.Combine(path, "../settings.gradle"); // var rootSettingsGradleFilePath = Path.Combine(path, "../settings.gradle");
if (!AddAppLovinRepository(rootSettingsGradleFilePath)) return; // if (!AddAppLovinRepository(rootSettingsGradleFilePath)) return;
#else // #else
var buildScriptChangesAdded = AddQualityServiceBuildScriptLines(rootGradleBuildFilePath); // var buildScriptChangesAdded = AddQualityServiceBuildScriptLines(rootGradleBuildFilePath);
if (!buildScriptChangesAdded) return; // if (!buildScriptChangesAdded) return;
#endif // #endif
// The plugin needs to be added to the application module (named launcher) // // The plugin needs to be added to the application module (named launcher)
var applicationGradleBuildFilePath = Path.Combine(path, "../launcher/build.gradle"); // var applicationGradleBuildFilePath = Path.Combine(path, "../launcher/build.gradle");
#else // #else
// If Gradle template is enabled, we would have already updated the plugin. // // If Gradle template is enabled, we would have already updated the plugin.
if (AppLovinIntegrationManager.GradleTemplateEnabled) return; // if (AppLovinIntegrationManager.GradleTemplateEnabled) return;
var applicationGradleBuildFilePath = Path.Combine(path, "build.gradle"); // var applicationGradleBuildFilePath = Path.Combine(path, "build.gradle");
#endif // #endif
if (!File.Exists(applicationGradleBuildFilePath)) // if (!File.Exists(applicationGradleBuildFilePath))
{ // {
MaxSdkLogger.UserWarning("Couldn't find build.gradle file. Failed to add AppLovin Quality Service plugin to the gradle project."); // MaxSdkLogger.UserWarning("Couldn't find build.gradle file. Failed to add AppLovin Quality Service plugin to the gradle project.");
return; // return;
} // }
AddAppLovinQualityServicePlugin(applicationGradleBuildFilePath); // AddAppLovinQualityServicePlugin(applicationGradleBuildFilePath);
} // }
public int callbackOrder // public int callbackOrder
{ // {
get { return int.MaxValue; } // get { return int.MaxValue; }
} // }
} // }
} }
#endif #endif

View File

@ -26,166 +26,166 @@ namespace AppLovinMax.Scripts.IntegrationManager.Editor
/// <summary> /// <summary>
/// Adds the AppLovin Quality Service plugin to the gradle template file. See <see cref="AppLovinProcessGradleBuildFile"/> for more details. /// Adds the AppLovin Quality Service plugin to the gradle template file. See <see cref="AppLovinProcessGradleBuildFile"/> for more details.
/// </summary> /// </summary>
public class AppLovinPreProcessAndroid : AppLovinProcessGradleBuildFile, // public class AppLovinPreProcessAndroid : AppLovinProcessGradleBuildFile,
#if UNITY_2018_1_OR_NEWER // #if UNITY_2018_1_OR_NEWER
IPreprocessBuildWithReport // IPreprocessBuildWithReport
#else // #else
IPreprocessBuild // IPreprocessBuild
#endif // #endif
{ // {
private const string AppLovinSettingsFileName = "applovin_settings.json"; // private const string AppLovinSettingsFileName = "applovin_settings.json";
private const string KeyTermsFlowSettings = "terms_flow_settings"; // private const string KeyTermsFlowSettings = "terms_flow_settings";
private const string KeyTermsFlowEnabled = "terms_flow_enabled"; // private const string KeyTermsFlowEnabled = "terms_flow_enabled";
private const string KeyTermsFlowTermsOfService = "terms_flow_terms_of_service"; // private const string KeyTermsFlowTermsOfService = "terms_flow_terms_of_service";
private const string KeyTermsFlowPrivacyPolicy = "terms_flow_privacy_policy"; // private const string KeyTermsFlowPrivacyPolicy = "terms_flow_privacy_policy";
private const string KeyConsentFlowSettings = "consent_flow_settings"; // private const string KeyConsentFlowSettings = "consent_flow_settings";
private const string KeyConsentFlowEnabled = "consent_flow_enabled"; // private const string KeyConsentFlowEnabled = "consent_flow_enabled";
private const string KeyConsentFlowTermsOfService = "consent_flow_terms_of_service"; // private const string KeyConsentFlowTermsOfService = "consent_flow_terms_of_service";
private const string KeyConsentFlowPrivacyPolicy = "consent_flow_privacy_policy"; // private const string KeyConsentFlowPrivacyPolicy = "consent_flow_privacy_policy";
private const string KeyConsentFlowAdvertisingPartners = "consent_flow_advertising_partners"; // private const string KeyConsentFlowAdvertisingPartners = "consent_flow_advertising_partners";
private const string KeyConsentFlowIncludeDefaultAdvertisingPartners = "consent_flow_should_include_default_advertising_partners"; // private const string KeyConsentFlowIncludeDefaultAdvertisingPartners = "consent_flow_should_include_default_advertising_partners";
private const string KeyConsentFlowAnalyticsPartners = "consent_flow_analytics_partners"; // private const string KeyConsentFlowAnalyticsPartners = "consent_flow_analytics_partners";
private const string KeyConsentFlowIncludeDefaultAnalyticsPartners = "consent_flow_should_include_default_analytics_partners"; // private const string KeyConsentFlowIncludeDefaultAnalyticsPartners = "consent_flow_should_include_default_analytics_partners";
#if UNITY_2018_1_OR_NEWER // #if UNITY_2018_1_OR_NEWER
public void OnPreprocessBuild(BuildReport report) // public void OnPreprocessBuild(BuildReport report)
#else // #else
public void OnPreprocessBuild(BuildTarget target, string path) // public void OnPreprocessBuild(BuildTarget target, string path)
#endif // #endif
{ // {
// 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). // // 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 (!AppLovinIntegrationManager.GradleTemplateEnabled) return;
#if UNITY_2019_3_OR_NEWER // #if UNITY_2019_3_OR_NEWER
// The publisher could be migrating from older Unity versions to 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). // // 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); // RemoveAppLovinQualityServiceOrSafeDkPlugin(AppLovinIntegrationManager.GradleTemplatePath);
#else // #else
AddAppLovinQualityServicePlugin(AppLovinIntegrationManager.GradleTemplatePath); // AddAppLovinQualityServicePlugin(AppLovinIntegrationManager.GradleTemplatePath);
#endif // #endif
// For Unity 2018.2 or newer, the consent flow is enabled in MaxPostProcessBuildAndroid. // // For Unity 2018.2 or newer, the consent flow is enabled in MaxPostProcessBuildAndroid.
#if !UNITY_2018_2_OR_NEWER // #if !UNITY_2018_2_OR_NEWER
if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager) // if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager)
{ // {
var consentFlowSettingsFilePath = Path.Combine("Assets", "Plugin/Android/res/raw/"); // var consentFlowSettingsFilePath = Path.Combine("Assets", "Plugin/Android/res/raw/");
EnableConsentFlowIfNeeded(consentFlowSettingsFilePath); // EnableConsentFlowIfNeeded(consentFlowSettingsFilePath);
} // }
#endif // #endif
} // }
public static void EnableConsentFlowIfNeeded(string rawResourceDirectory) // public static void EnableConsentFlowIfNeeded(string rawResourceDirectory)
{ // {
// Check if consent flow is enabled. No need to create the applovin_consent_flow_settings.json if consent flow is disabled. // // Check if consent flow is enabled. No need to create the applovin_consent_flow_settings.json if consent flow is disabled.
var consentFlowEnabled = AppLovinInternalSettings.Instance.ConsentFlowEnabled; // var consentFlowEnabled = AppLovinInternalSettings.Instance.ConsentFlowEnabled;
if (!consentFlowEnabled) return; // if (!consentFlowEnabled) return;
var privacyPolicyUrl = AppLovinInternalSettings.Instance.ConsentFlowPrivacyPolicyUrl; // var privacyPolicyUrl = AppLovinInternalSettings.Instance.ConsentFlowPrivacyPolicyUrl;
if (string.IsNullOrEmpty(privacyPolicyUrl)) // 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."); // 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. // // No need to update the applovin_consent_flow_settings.json here. Default consent flow state will be determined on the SDK side.
return; // return;
} // }
var consentFlowSettings = new Dictionary<string, object>(); // var consentFlowSettings = new Dictionary<string, object>();
consentFlowSettings[KeyConsentFlowEnabled] = consentFlowEnabled; // consentFlowSettings[KeyConsentFlowEnabled] = consentFlowEnabled;
consentFlowSettings[KeyConsentFlowPrivacyPolicy] = privacyPolicyUrl; // consentFlowSettings[KeyConsentFlowPrivacyPolicy] = privacyPolicyUrl;
var termsOfServiceUrl = AppLovinInternalSettings.Instance.ConsentFlowTermsOfServiceUrl; // var termsOfServiceUrl = AppLovinInternalSettings.Instance.ConsentFlowTermsOfServiceUrl;
if (MaxSdkUtils.IsValidString(termsOfServiceUrl)) // if (MaxSdkUtils.IsValidString(termsOfServiceUrl))
{ // {
consentFlowSettings[KeyConsentFlowTermsOfService] = termsOfServiceUrl; // consentFlowSettings[KeyConsentFlowTermsOfService] = termsOfServiceUrl;
} // }
consentFlowSettings[KeyConsentFlowIncludeDefaultAdvertisingPartners] = AppLovinInternalSettings.Instance.ConsentFlowIncludeDefaultAdvertisingPartnerUrls; // consentFlowSettings[KeyConsentFlowIncludeDefaultAdvertisingPartners] = AppLovinInternalSettings.Instance.ConsentFlowIncludeDefaultAdvertisingPartnerUrls;
var advertisingPartnerUrls = AppLovinInternalSettings.Instance.ConsentFlowAdvertisingPartnerUrls; // var advertisingPartnerUrls = AppLovinInternalSettings.Instance.ConsentFlowAdvertisingPartnerUrls;
if (MaxSdkUtils.IsValidString(advertisingPartnerUrls)) // if (MaxSdkUtils.IsValidString(advertisingPartnerUrls))
{ // {
var advertisingPartnerUrlsList = advertisingPartnerUrls.Split(',').ToList(); // var advertisingPartnerUrlsList = advertisingPartnerUrls.Split(',').ToList();
consentFlowSettings[KeyConsentFlowAdvertisingPartners] = advertisingPartnerUrlsList; // consentFlowSettings[KeyConsentFlowAdvertisingPartners] = advertisingPartnerUrlsList;
} // }
consentFlowSettings[KeyConsentFlowIncludeDefaultAnalyticsPartners] = AppLovinInternalSettings.Instance.ConsentFlowIncludeDefaultAnalyticsPartnerUrls; // consentFlowSettings[KeyConsentFlowIncludeDefaultAnalyticsPartners] = AppLovinInternalSettings.Instance.ConsentFlowIncludeDefaultAnalyticsPartnerUrls;
var analyticsPartnerUrls = AppLovinInternalSettings.Instance.ConsentFlowAnalyticsPartnerUrls; // var analyticsPartnerUrls = AppLovinInternalSettings.Instance.ConsentFlowAnalyticsPartnerUrls;
if (MaxSdkUtils.IsValidString(analyticsPartnerUrls)) // if (MaxSdkUtils.IsValidString(analyticsPartnerUrls))
{ // {
var analyticsPartnerUrlsList = analyticsPartnerUrls.Split(',').ToList(); // var analyticsPartnerUrlsList = analyticsPartnerUrls.Split(',').ToList();
consentFlowSettings[KeyConsentFlowAnalyticsPartners] = analyticsPartnerUrlsList; // consentFlowSettings[KeyConsentFlowAnalyticsPartners] = analyticsPartnerUrlsList;
} // }
var applovinSdkSettings = new Dictionary<string, object>(); // var applovinSdkSettings = new Dictionary<string, object>();
applovinSdkSettings[KeyConsentFlowSettings] = consentFlowSettings; // applovinSdkSettings[KeyConsentFlowSettings] = consentFlowSettings;
var applovinSdkSettingsJson = Json.Serialize(applovinSdkSettings); // var applovinSdkSettingsJson = Json.Serialize(applovinSdkSettings);
WriteAppLovinSettingsRawResourceFile(applovinSdkSettingsJson, rawResourceDirectory); // WriteAppLovinSettingsRawResourceFile(applovinSdkSettingsJson, rawResourceDirectory);
} // }
public static void EnableTermsFlowIfNeeded(string rawResourceDirectory) // public static void EnableTermsFlowIfNeeded(string rawResourceDirectory)
{ // {
if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager) return; // if (AppLovinSettings.Instance.ShowInternalSettingsInIntegrationManager) return;
// Check if terms flow is enabled. No need to create the applovin_consent_flow_settings.json if consent flow is disabled. // // Check if terms flow is enabled. No need to create the applovin_consent_flow_settings.json if consent flow is disabled.
var consentFlowEnabled = AppLovinSettings.Instance.ConsentFlowEnabled; // var consentFlowEnabled = AppLovinSettings.Instance.ConsentFlowEnabled;
if (!consentFlowEnabled) return; // if (!consentFlowEnabled) return;
// Check if terms flow is enabled for this format. // // Check if terms flow is enabled for this format.
var consentFlowPlatform = AppLovinSettings.Instance.ConsentFlowPlatform; // var consentFlowPlatform = AppLovinSettings.Instance.ConsentFlowPlatform;
if (consentFlowPlatform != Platform.All && consentFlowPlatform != Platform.Android) return; // if (consentFlowPlatform != Platform.All && consentFlowPlatform != Platform.Android) return;
var privacyPolicyUrl = AppLovinSettings.Instance.ConsentFlowPrivacyPolicyUrl; // var privacyPolicyUrl = AppLovinSettings.Instance.ConsentFlowPrivacyPolicyUrl;
if (string.IsNullOrEmpty(privacyPolicyUrl)) // 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."); // 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. // // No need to update the applovin_consent_flow_settings.json here. Default consent flow state will be determined on the SDK side.
return; // return;
} // }
var consentFlowSettings = new Dictionary<string, object>(); // var consentFlowSettings = new Dictionary<string, object>();
consentFlowSettings[KeyTermsFlowEnabled] = consentFlowEnabled; // consentFlowSettings[KeyTermsFlowEnabled] = consentFlowEnabled;
consentFlowSettings[KeyTermsFlowPrivacyPolicy] = privacyPolicyUrl; // consentFlowSettings[KeyTermsFlowPrivacyPolicy] = privacyPolicyUrl;
var termsOfServiceUrl = AppLovinSettings.Instance.ConsentFlowTermsOfServiceUrl; // var termsOfServiceUrl = AppLovinSettings.Instance.ConsentFlowTermsOfServiceUrl;
if (MaxSdkUtils.IsValidString(termsOfServiceUrl)) // if (MaxSdkUtils.IsValidString(termsOfServiceUrl))
{ // {
consentFlowSettings[KeyTermsFlowTermsOfService] = termsOfServiceUrl; // consentFlowSettings[KeyTermsFlowTermsOfService] = termsOfServiceUrl;
} // }
var applovinSdkSettings = new Dictionary<string, object>(); // var applovinSdkSettings = new Dictionary<string, object>();
applovinSdkSettings[KeyTermsFlowSettings] = consentFlowSettings; // applovinSdkSettings[KeyTermsFlowSettings] = consentFlowSettings;
var applovinSdkSettingsJson = Json.Serialize(applovinSdkSettings); // var applovinSdkSettingsJson = Json.Serialize(applovinSdkSettings);
WriteAppLovinSettingsRawResourceFile(applovinSdkSettingsJson, rawResourceDirectory); // WriteAppLovinSettingsRawResourceFile(applovinSdkSettingsJson, rawResourceDirectory);
} // }
private static void WriteAppLovinSettingsRawResourceFile(string applovinSdkSettingsJson, string rawResourceDirectory) // private static void WriteAppLovinSettingsRawResourceFile(string applovinSdkSettingsJson, string rawResourceDirectory)
{ // {
if (!Directory.Exists(rawResourceDirectory)) // if (!Directory.Exists(rawResourceDirectory))
{ // {
Directory.CreateDirectory(rawResourceDirectory); // Directory.CreateDirectory(rawResourceDirectory);
} // }
var consentFlowSettingsFilePath = Path.Combine(rawResourceDirectory, AppLovinSettingsFileName); // var consentFlowSettingsFilePath = Path.Combine(rawResourceDirectory, AppLovinSettingsFileName);
try // try
{ // {
File.WriteAllText(consentFlowSettingsFilePath, applovinSdkSettingsJson + "\n"); // File.WriteAllText(consentFlowSettingsFilePath, applovinSdkSettingsJson + "\n");
} // }
catch (Exception exception) // catch (Exception exception)
{ // {
MaxSdkLogger.UserError("applovin_settings.json file write failed due to: " + exception.Message); // MaxSdkLogger.UserError("applovin_settings.json file write failed due to: " + exception.Message);
Console.WriteLine(exception); // Console.WriteLine(exception);
} // }
} // }
public int callbackOrder // public int callbackOrder
{ // {
get { return int.MaxValue; } // get { return int.MaxValue; }
} // }
} // }
} }
#endif #endif