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 text2 = File.ReadAllText(gradleFilePath2);
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);
}

View File

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

View File

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

View File

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