Android "Cannot fit requested classes in a single dex file" (64K)
A single DEX file can reference at most 65,536 methods. Your app plus its dependencies crossed that limit, so the build cannot pack everything into one DEX without multidex or shrinking.
What this error means
The build fails with "Cannot fit requested classes in a single dex file (# methods: 70000 > 65536)". It appears as the app and its libraries grow, typically on minSdk < 21 without multidex.
com.android.tools.r8.errors.CompilationFailedException:
Cannot fit requested classes in a single dex file (# methods: 71284 > 65536)Common causes
Too many methods for one DEX
The combined method count of your code and dependencies exceeds 65,536, which a single DEX file cannot reference.
Multidex not enabled on older minSdk
On minSdk < 21, multidex is not automatic - you must enable it explicitly or the single-DEX limit is enforced.
How to fix it
Enable multidex
Turn on multidex so the build can split across multiple DEX files.
// app/build.gradle(.kts)
android {
defaultConfig {
minSdk = 21
multiDexEnabled = true
}
}Shrink with R8 to cut the method count
Enabling code shrinking removes unused methods, often bringing you back under the limit.
// app/build.gradle(.kts) - release build type
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}How to prevent it
- Enable multidex (or
minSdk >= 21) for large apps. - Use R8/ProGuard shrinking on release builds to trim methods.
- Audit dependencies - drop heavyweight libraries you barely use.