Cannot fit requested classes in a single dex file (# methods: 111608 > 65536 ; # fields: 71862 > 65536) code example

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

defaultConfig {
    ...

    multiDexEnabled true
}

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

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

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

android {
    defaultConfig {
        ...
        minSdkVersion 21 <----- *here
        targetSdkVersion 26
        multiDexEnabled true <------ *here
    }
    ...
}

Tags:

Misc Example