Skip to content
Latchkey

Android "Execution failed for task ':app:mergeDexRelease'" in CI

The mergeDexRelease task combines compiled classes into DEX files for the release build. It fails when the app exceeds the single-DEX 64K method-reference limit without multidex, or when the D8 merger runs out of memory.

What this error means

The build fails with "Execution failed for task ':app:mergeDexRelease'." and a cause such as "Cannot fit requested classes in a single dex file (# methods: 70123 > 65536)".

Android
> Execution failed for task ':app:mergeDexRelease'.
  > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex
    archives: Cannot fit requested classes in a single dex file
    (# methods: 70123 > 65536)

Common causes

The app exceeds the single-DEX method limit

A single DEX file references at most 65,536 methods; a large app or many dependencies pushes past that without multidex enabled.

The D8 merger ran out of memory

Merging many DEX inputs on a constrained runner can exhaust heap, failing the merge task.

How to fix it

Enable multidex

  1. Set multiDexEnabled true in the app defaultConfig.
  2. Add the multidex dependency if your minSdk is below 21.
  3. Re-run the release build.
app/build.gradle.kts
android {
  defaultConfig { multiDexEnabled = true }
}

Give the build more heap

If the cause is memory rather than the method count, raise the Gradle JVM heap for the merge.

gradle.properties
org.gradle.jvmargs=-Xmx4g

How to prevent it

  • Enable multidex for apps approaching the method-reference limit.
  • Trim unused dependencies to keep the method count down.
  • Keep the Gradle heap sized for the release merge on CI.

Frequently asked questions

What causes ""Execution failed for task ':app:mergeDexRelease'""?
A single DEX file references at most 65,536 methods; a large app or many dependencies pushes past that without multidex enabled.
How do I fix "Execution failed for task ':app:mergeDexRelease'"?
Enable multidex

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card