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
How to Have the Code Pause for a Couple of Seconds in Android
Can't Run Junit 4 Test Case in Eclipse Android Project
How to Remove Specific Permission When Build Android App with Gradle
How to Start a New Android Activity Using Class Name in a String
How to Include the Spongy Castle Jar in Android
Difference Between Google() and Maven { Url 'Https://Maven.Google.Com' }
Creating an Arraylist of Objects
Android and Getting a View with Id Cast as a String
How to Persist Permission in Android API 19 (Kitkat)
File Exists and Is Directory, But Listfiles() Returns Null
String-Date Conversion with Nanoseconds
Polygon Touch Detection Google Map API V2
How to Get Country Phone Prefix from Iso
Sending Http Post Request with Android
Android Resource Not Found Exception
Android Proguard JavaScript Interface Fail
How to Convert Rgb Color to Int in Java
How to Resume Android Activity Programmatically from Background