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)".
> 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
- Set
multiDexEnabled truein the appdefaultConfig. - Add the multidex dependency if your
minSdkis below 21. - Re-run the release build.
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.
org.gradle.jvmargs=-Xmx4gHow 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.