The Google Mobile Ads Android SDK 22.4.0
added a <property>
element in its Android manifest. Building against this version or higher
requires using Gradle 6.7.1 or higher and Android Gradle plugin
4.2.0 or higher. This guide instructs you on how to make sure your Unity editor
is compatible.
Prerequisites
Complete the Get started guide. Make sure to:
- Set Minimum API level to 21
- Set Target API level to 33 or higher
- Enable Custom Main Gradle Template and Custom Gradle Properties Template settings
Unity 2022.2 and later
Unity 2022.2 and higher comes with newer versions of Gradle for Android by default. No additional action is required to support Google Mobile Ads Android SDK 22.4.0.
Unity 2022.1 and earlier
Unity 2022.2 and earlier use an older version of Gradle for Android which is not supported by Google Mobile Ads Android SDK 22.4.0. The following steps show how to upgrade to the minimally required Gradle version based on your build process:
Enable custom Gradle templates
Go to Project Settings > Player > Android > Publishing Settings > Build, and select:
- Custom Base Gradle Template
Modify Base Gradle Template
Open the Assets/Plugins/Android/baseProjectTemplate.gradle file and set the dependencies to use Gradle build tools 4.2.0.
allprojects { buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.2.0' **BUILD_SCRIPT_DEPS** } } } ...
Update Gradle
Update your Gradle version to 6.7.1. The steps for this are slightly different depending on whether you export your project as an Android Studio project as part of your build process.
Unity Integrated Builds
Install Gradle
Download Gradle version 6.7.1.
Set Gradle path in Unity
In Unity, open Unity Preferences > External Tools and set the custom Gradle path.
Android Studio Builds
Export the Android Studio project
Open the File > Build Settings menu, enable Export Project is checked, and press the Export button. Once exported, open the project in Android Studio.
Update Gradle wrapper
Open the ./gradle/wrapper/gradle-wrapper.properties file and set the distributionUrl to use Gradle 6.7.1.
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip