Flutter project exceeds .dex Method Reference Count limit

I had the same problem and the fix for me was increasing the minSdkVersion in the app/build.bradle like this

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        minSdkVersion 21 // change this to 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

in your android/app/build file increase the minsdkversion from 16 to 21 under defautConfig. Some have even increased it to 28 but it worked for me at 21. Here is the link to the issue on git

Edit: multiDexEnabled: true also works for some under the same defautConfig.


If you are using minSdkVersion less than 21, you can do the following to enable multidex. In your app level build.gradle change as follows:

  1. Add multiDexEnabled true to defaultConfig
defaultConfig {
    minSdkVersion 15 
    targetSdkVersion 28
    ...
    multiDexEnabled true
}
  1. Add multidex dependency
dependencies {
    ...
    implementation 'androidx.multidex:multidex:2.0.1'
}

You can refer this for more information.