AppLovinMax InMobi Adapter failes the build with gradle error about "queries" keywords in Unity 2019.4

The problem:

  • You add the InMobi adapter in AppLovin Integration manager, resolve dependencies and try to build and it fails with a lot of exceptions, one of them says “AAPT: error: unexpected element &ltqueries> found in &ltmainfest>.”

Actually I’ve solve it after 8hrs of pain but want to share the answer with the internet because I’ve found no info, I’ll provide the solution in the answer below. Hope this will help someone in the future, maybe not exactly with AppLovin or InMobi.

The Solution:

  • Download version of Gradle 5.6.4+ (I used 6.7)

  • Set it in Preferences → ExternalTools as gradle to use

  • Open Player Settings → Publishing Settings and enable “Custom Base Gradle Template”, It will create a file Assets/Plugins/Android/baseProjectTemplate.gradle

  • Open it with any text editor and find “classpath ‘com.android.tools.build:gradle:3.4.0’” row. It’s located in “allprojects/buildscript/dependencies” object

  • Replace 3.4.0 with 3.6.0 or higher, I used 4.0.1

  • Save the file and try to build, It should work

Why does this happen?

  • Some third party library (in my case InMobi) adds keyword to gradle build manifest which is supported from Android Gradle Plugin 3.6.0 or higher. Android gradle plugin version 3.6.0 is supported from gradle version 5.6.4 or higher (yeah there are 2 different types of gradle version you should have to build. Source here:

Android Gradle plugin release notes  |  Android Studio  |  Android Developers)

  • Unity by default provides gradle 5.1.1 or lower with editor (if I understood correctly), so it doesn’t support gradle plugin 3.6.0 and keyword and builds with gradle plugin 3.4.0 by default:

Hey everyone,

Just a heads up, the best fix is to skip updating Gradle as it might lead to further issues and use Android Gradle Plugin version 3.4.3 (at least for most versions of Unity).
So you should change this line

classpath 'com.android.tools.build:gradle:3.4.0'

to

classpath 'com.android.tools.build:gradle:3.4.3'

in the baseProjectTemplate.gradle file.

This issue and a fix for it is actually described in the AppLovin MAX documentation here: MAX Mediation Documentation

I did the steps but the error remains the same.
My path for ExternalTools is /opt/gradle/gradle-6.7.1

Spent the whole day stressing over this issue! It’s night time now, I’ve already clocked more than 10 hours! And just as I’m about to give up, I find this post! Thank you!