Flutter Firestore causing D8: Cannot fit requested classes in a single dex file (# methods: 71610 > 65536) in Android Studio

Enable multidex.

Open project/app/build.gradle and add the following lines.

defaultConfig {
    ...

    multiDexEnabled true
}

and

dependencies {
    ...

    implementation 'com.android.support:multidex:1.0.3'
}

If you have migrated to AndroidX, you'll want this instead (tip by Touré Holder):

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

By default, Flutter supports Android SDK v16 (Jelly Bean, released 2012), but multidex doesn't really work with Jelly Bean out of the box.

A) Change minimum target SDK

  1. Open android/app/build.gradle, then find the line that says minSdkVersion 16.
  2. Change that line to minSdkVersion 21.
  3. Save the file.

B) Enable multidex.

If you want to support older Android versions you can use the multidex support library.

  1. Open and modify project/app/build.gradle file to enable multidex and add the multidex library as a dependency, as shown here :
android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

Official guide here


Add this to android/app/build.gradle:

defaultConfig {
    ...
    multiDexEnabled true
}