AppLovinPostProcessAndroidGradle.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // AppLovinBuildPostProcessor.cs
  3. // AppLovin MAX Unity Plugin
  4. //
  5. // Created by Santosh Bagadi on 8/29/19.
  6. // Copyright © 2019 AppLovin. All rights reserved.
  7. //
  8. #if UNITY_ANDROID
  9. using System.IO;
  10. using UnityEditor.Android;
  11. namespace AppLovinMax.Scripts.IntegrationManager.Editor
  12. {
  13. /// <summary>
  14. /// Adds Quality Service plugin to the Gradle project once the project has been exported. See <see cref="AppLovinProcessGradleBuildFile"/> for more details.
  15. /// </summary>
  16. public class AppLovinPostProcessGradleProject : AppLovinProcessGradleBuildFile, IPostGenerateGradleAndroidProject
  17. {
  18. public void OnPostGenerateGradleAndroidProject(string path)
  19. {
  20. if (!AppLovinSettings.Instance.QualityServiceEnabled) return;
  21. #if UNITY_2019_3_OR_NEWER
  22. // On Unity 2019.3+, the path returned is the path to the unityLibrary's module.
  23. // The AppLovin Quality Service buildscript closure related lines need to be added to the root build.gradle file.
  24. var rootGradleBuildFilePath = Path.Combine(path, "../build.gradle");
  25. var shouldAddQualityServiceToDependencies = ShouldAddQualityServiceToDependencies(rootGradleBuildFilePath);
  26. var failedToAddPlugin = false;
  27. if (shouldAddQualityServiceToDependencies)
  28. {
  29. // Add the Quality Service Plugin to the dependencies block in the root build.gradle file
  30. var buildScriptChangesAdded = AddQualityServiceBuildScriptLines(rootGradleBuildFilePath);
  31. failedToAddPlugin = !buildScriptChangesAdded;
  32. }
  33. else
  34. {
  35. // Add the Quality Service Plugin to the plugin block in the root build.gradle file
  36. var rootSettingsGradleFilePath = Path.Combine(path, "../settings.gradle");
  37. var qualityServiceAdded = AddPluginToRootGradleBuildFile(rootGradleBuildFilePath);
  38. var appLovinRepositoryAdded = AddAppLovinRepository(rootSettingsGradleFilePath);
  39. failedToAddPlugin = !(qualityServiceAdded && appLovinRepositoryAdded);
  40. }
  41. if (failedToAddPlugin)
  42. {
  43. MaxSdkLogger.UserWarning("Failed to add AppLovin Quality Service plugin to the gradle project.");
  44. return;
  45. }
  46. // The plugin needs to be added to the application module (named launcher)
  47. var applicationGradleBuildFilePath = Path.Combine(path, "../launcher/build.gradle");
  48. #else
  49. // If Gradle template is enabled, we would have already updated the plugin.
  50. if (AppLovinIntegrationManager.GradleTemplateEnabled) return;
  51. var applicationGradleBuildFilePath = Path.Combine(path, "build.gradle");
  52. #endif
  53. if (!File.Exists(applicationGradleBuildFilePath))
  54. {
  55. MaxSdkLogger.UserWarning("Couldn't find build.gradle file. Failed to add AppLovin Quality Service plugin to the gradle project.");
  56. return;
  57. }
  58. AddAppLovinQualityServicePlugin(applicationGradleBuildFilePath);
  59. }
  60. public int callbackOrder
  61. {
  62. get { return CallbackOrder; }
  63. }
  64. }
  65. }
  66. #endif