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

Hello Guys. Many times we Face Flutter Firestore causing D8: Cannot fit requested classes in a single dex file (# methods: 71610 > 65536) in Android Studio. So in this tutorial, we are going to solve this error.

What is Error ?

I am facing this error when I Use firestore with flutter app.

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

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\Users\Milan\AndroidStudioProjects\Milan_flutter_projects\bakery\bakery\build\app\intermediates\transforms\dexBuilder\debug\2.jar, 
  The number of method references in a .dex file cannot exceed 64K.
  Learn how to reso

Question: How to solve Flutter Firestore causing D8: Cannot fit requested classes in a single dex ?
Answer: By default, Flutter supports Android SDK v16 (Jelly Bean, released 2012), but multidex doesn’t really work with Jelly Bean out of the box. So we have to do 2 task to solve this error.

How to solve Flutter Firestore causing D8: Cannot fit requested classes in a single dex ?

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

So we have to do 2 task to solve this error.

  1. 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.

2. Enable multidex.

  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'
}

Here is official Document Official guide.

Solution 2

Enable multidex.

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

defaultConfig {
    ...

    multiDexEnabled true
}

then

dependencies {
    ...

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

If you have migrated to AndroidX, you’ll want this instead.

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

Now, Flutter Firestore causing D8: Cannot fit requested classes in a single dex file (# methods: 71610 > 65536) in Android Studio Error is solved. If you still facing this error so Comment below your error with code. I Will Help You. Comment below Your thoughts and your queries. And Also Comment on your suggestion here.

Also Read

Milan Dhameliya is an Information Technology Engineer. By profession, he is a Full Stack developer with knowledge of multiple back-end platforms (e.g., PHP, Node.js, Python) and frontend Flutter frameworks.

Leave a Comment