android build_error ai_generated true

Cannot fit requested classes in a single dex file (# methods: 78291 > 65536)

ID: android/dex-method-limit

Also available as: JSON · Markdown
95%Fix Rate
93%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active
14 active

Root Cause

App exceeds the 64K DEX method reference limit. Too many dependencies or minSdk < 21 without multidex.

generic

Workarounds

  1. 95% success Enable multidex in build.gradle
    android { defaultConfig { multiDexEnabled true } }  // automatic on minSdk >= 21

    Sources: https://developer.android.com/reference/

  2. 90% success For minSdk < 21, add the multidex support library
    implementation 'androidx.multidex:multidex:2.0.1'; Application class extends MultiDexApplication
  3. 85% success Enable R8 minification to reduce method count
    buildTypes { release { minifyEnabled true; proguardFiles getDefaultProguardFile('proguard-android-optimize.txt') } }

Dead Ends

Common approaches that don't work:

  1. Remove dependencies to get under 65536 methods 85% fail

    Unsustainable for real apps. Multidex is the standard solution and has zero runtime cost on API 21+.

  2. Use ProGuard/R8 minification alone without enabling multidex 68% fail

    R8 helps reduce methods but may not get below 65536. Enable multidex as the reliable fix.