Error:Cannot Fit Requested Classes in a Single Dex File.Try Supplying a Main-Dex List. # Methods: 72477 > 65536

Android gives error Cannot fit requested classes in a single dex file

In root build.gradle file do something like:

dependencies {

// ...

implementation 'androidx.multidex:multidex:2.0.1'
}

android {
defaultConfig {

// ...

multiDexEnabled true
}
}

More details here: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

D8: Cannot fit requested classes in a single dex file

Add multiDex to your app-level build.gradle file.
Under defaultConfig add this line

multiDexEnabled true

Then in dependencies add multidex and check versions

implementation 'androidx.multidex:multidex: 2.0.1'

Error : Cannot fit requested classes in a single dex file (# methods: 65978 65536)

You must add the library in the app gradle :

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

After, add in the defaultConfig of the app gradle :

multiDexEnabled true

Cannot fit requested classes in a single dex file after updating android studio

If you want to stay away from multiDex you have two options. Actually one option, the other one is just crippled form of the main option. By the way, I just copy-pasted all your gradle file and tested it.

Option 1. (Recommended)

Step 1. Create a proguard file for your debug. Let's say debug-proguard-rules.pro and add the following line to your debug proguard file. This line will force the compiler to keep classes and class memebers' names as-is during debug build which is quite helpful:

-dontobfuscate

Step 2. Add debug build type to your gradle. This will apply proguard rules from both proguard-rules.pro and proguard-rules-debug.pro files.

buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro', 'proguard-rules-debug.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}

Option 2.

If you don't care about your classes and class members being obfuscated in debug build, then just add the following line to your build types:

buildTypes {
debug {
minifyEnabled true
}
release {
//........
}
}


Related Topics



Leave a reply



Submit