ANDROID • GRADLE BUILD SYSTEM

GRADLE BUILD FAILED & MANIFEST MERGER ERROR

UnityEditor.BuildPlayerWindow+BuildMethodException: Gradle build failed. See the Console for details.

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.

Step-by-Step Resolution

  1. Enable Custom Base Gradle Template:

    Go to Project Settings > Player > Android > Publishing Settings. Under Build, check:
    • Custom Main Gradle Template (mainTemplate.gradle)
    • Custom Gradle Properties Template (gradleTemplate.properties)

  2. Enable AndroidX & Jetifier in gradleTemplate.properties:

    Open Assets/Plugins/Android/gradleTemplate.properties and add the following flags to automatically migrate legacy support libraries:

    android.useAndroidX=true
    android.enableJetifier=true
  3. Run External Dependency Manager (EDM4U) Force Resolve:

    If using Google Mobile Ads or Firebase, go to Assets > External Dependency Manager > Android Resolver > Force Resolve. This deduplicates overlapping .aar dependencies.

  4. Enable Minify (ProGuard / R8) with Custom Keep Rules:

    If the dex limit (64k methods) is exceeded, enable Custom Proguard File in Publishing Settings.

Related Troubleshooting Guides

Frequently Asked Questions

This typically occurs when signing the release APK with an invalid Keystore password, or when Windows file path length exceeds 260 characters (MAX_PATH). Move your Unity project to a short directory path like D:/Projects/Game/ to avoid Gradle path truncation bugs.