ANDROID • GRADLE BUILD SYSTEM
GRADLE BUILD FAILED & MANIFEST MERGER ERROR
UnityEditor.BuildPlayerWindow+BuildMethodException: Gradle build failed. See the Console for details.
⏱️ 5 Min Read
⚡ Android SDK / Gradle
🛡️ Verified Solution
What Is the Error?
Gradle is the build automation tool used by Android to resolve third-party plugins (Google Play Services, AdMob, In-App Purchasing, Firebase), merge XML manifests, and assemble the final .aab or .apk package.
When two plugins import conflicting versions of the same Android library (e.g. androidx.core), or when multiple AndroidManifest.xml files declare conflicting android:theme attributes, the Gradle merger halts the build with an error.
Fixing Android Gradle JVM Out of Memory & NDK Compatibility
Gradle compilation failures during Android APK/AAB builds in Unity typically trace to three root causes: Java Heap OOM errors, conflicting AndroidX support libraries, or incompatible Android NDK/JDK versions.
Increasing Gradle Daemon Memory in gradle.properties
Open Project Settings → Player → Publishing Settings. Check Custom Gradle Properties Template. Locate Assets/Plugins/Android/gradle.properties and add:
org.gradle.jvmargs=-Xmx4096M -XX:MaxMetaspaceSize=1024m
Resolving Duplicate Class and Manifest Merger Collisions
When importing multiple monetization SDKs (like AdMob, Firebase, and AppLovin), conflicting Android library versions trigger duplicate class errors. Enable the External Dependency Manager for Unity (EDM4U) and run Assets → External Dependency Manager → Android Resolver → Force Resolve.