How To Fix “Cannot fit requested classes in a single dex file. Try supplying a main-dex list”?
Are you having problems with the issue “Cannot fit requested classes in a single dex file. Try supplying a main-dex list“? How to fix it? In today’s article, I will provide solutions for you to solve the issues. Please follow the below steps to get the problem resolved now
How did “Cannot fit requested classes in a single dex file. Try supplying a main-dex list” occur?
Cannot fit requested classes in a single dex file. Try supplying a main-dex list
When you work with JAVA, you may get the issue Cannot fit requested classes in a single dex file. Try supplying a main-dex list. Don’t worry, we are here to provide you solutions in order to resolve your problem.
How to fix “Cannot fit requested classes in a single dex file. Try supplying a main-dex list”?
To Solve Cannot accommodate requested classes in one dex file. To solve the main-dex error, you can add androidx.multidex:multidex:2.0.1 dependency to build.gradle
. Simply type this: implementation 'androidx.multidex:multidex:2.0.1'. Also, you need to change multiDexEnabled from true. In build.gradle
’s defaultConfig
section, add: multiDexEnabled true .
Solution 1: Add dependency to build.gradle
Simply add androidx.multidex:multidex:2.0.1 dependency to the build.gradle
file. As simple as that.
implementation 'androidx.multidex:multidex:2.0.1'
Also, you need to change multiDexEnabled from true in build.gradle
‘s section defaultConfig
add.
android {
defaultConfig {
...
minSdkVersion 21 <----- *OPTIONAL
targetSdkVersion 26
multiDexEnabled true <------ *here
}
...
}
Now, your error must be fixed.
Solution 2: $strongTag9
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true //ADD THIS LINE
}
Final words
The above are useful solutions that can help you fix “Cannot fit requested classes in a single dex file. Try supplying a main-dex list” problem, if you can’t solve it well. Please leave a message.