Multidex issue with Flutter

In most cases, enough will do the first step. If you don’t have experience with developing android application this information can be helpful otherwise you won’t find anything new.

How to enable multidex for flutter project.

Enable multidex.

Open [project_folder]/app/build.gradle and add following lines.

defaultConfig {
    ...

    multiDexEnabled true
}

and

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

Enable Jetifier.

Open [project_folder]/android/gradle.properties and add following lines.

android.useAndroidX=true
android.enableJetifier=true

Update for beginner devs in 2024 and beyond:

If you’e OK with your project having a minimum Android API level of 21 (it will run on 99.3% of Android devices), all you have to do is this:

Modify minSdkVersion.

Using a text editor, open your “app level build.gradle file” which exists at [your project]\android\app\build.gradle.

defaultConfig {
        // ...
        minSdkVersion [whatever it says here, even if it is not a number]
        // ...
}

Change it to:

defaultConfig {
            // ...
            minSdkVersion 21
            // ...
}

Obviously the 21 can be higher if you want, but not lower.

You’re done!

You don’t have to make ANY other modifications in order for multidex to work correctly.

Apparently, the default minSDK setting for new Flutter projects is STILL 16, so after adding enough dependencies in pubspec.yaml, many new developers will run into the multidex error and go searching online, potentially getting bogged down in old, confusing information which only applies to projects with a minimum level set to less than 21.