The following error typically occurs in Unity 2019 and indicates that your Gradle version does not support AndroidX:
/Temp/gradleOut/launcher/build/intermediates/merged_manifests/release/AndroidManifest.xml:38:
AAPT: error: unexpected element <queries> found in <manifest>.
This error stems from the AdMob SDK. If you are not using AdMob as an ad source for Mediation, clear the AdMob adapter checkbox in the Adapter Configuration settings page of the Unity Editor.
A similar error can occur that requires the same fix:
Error: Missing 'package' key attribute on element package at
See AdMob’s guide on Unity Gradle support to upgrade your project’s version of Gradle to meet the requirements for AdMob. We recommend that you use Gradle version 5.6.4, which is specified by this guide.
After you follow the steps in the AdMob guide, you might encounter this error:
This project uses AndroidX dependencies, but the ‘android.useAndroidX’ property is
not enabled.
To resolve this error:
- In the Unity Editor, go to Project Settings > Player > Publishing Settings and select the Custom Gradle Properties Template checkbox.
- Go to the path listed after the checkbox and add the following two lines to the end of the file:
android.useAndroidX=true
android.enableJetifier=true
Another solution is to go to the Editor folder in your project, create a file called AndroidManifestPostGenerateGradleProject.cs, and then paste the following script into it:
{
public void OnPostGenerateGradleAndroidProject(string path)
{
Debug.Log("Build path : " + path);
string gradlePropertiesFile = path + "/../gradle.properties";
if (File.Exists(gradlePropertiesFile)) {
File.Delete(gradlePropertiesFile);
}
StreamWriter writer = File.CreateText(gradlePropertiesFile);
//writer.WriteLine("org.gradle.jvmargs=-Xmx4096M");
writer.WriteLine("android.useAndroidX=true");
writer.WriteLine("android.enableJetifier=true");
writer.Flush();
writer.Close();
}
}
For more information, see the Unity Mediation documentation.