Solution:
None of the answers they gave you were completed. The problem remains in the Multidex. You should include the library in the app gradle :
implementation 'com.android.support:multidex:1.0.3'
After, include in the defaultConfig of the app gradle :
multiDexEnabled true
Your Application should be of the Multidex type.. You should write it in the manifest :
android:name=".MyApplication"
"MyApplication" should be either the Multidex class, or it should enhance it.
Temper your app's or module's build.gradle
android {
defaultConfig {
...
minSdkVersion 21 <----- *here
targetSdkVersion 26
multiDexEnabled true <------ *here
}
...
}
Following official documentation
Multidex backing for Android 5.0 and higher
Android 5.0 (API level 21) and higher employ a runtime named ART which natively clinchs loading multiple DEX files from APK files. ART works pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file accomplished by the Android device. Hence, in case your minSdkVersion is 21 or higher, you do not require the multidex support library.
What are dex files: Android app (APK) files hold executable bytecode files in the form of Dalvik Executable (DEX) files, which hold the compiled code employed to run your app.
Cause for this exception: The DEX specification limits the total number of systems that can be referenced within a single DEX file to 65,536 (64K reference limit) —adding Android framework methods, library methods, and methods in your own code.
Step 01. Include the following dependency as follows
For Non-Androidx Users,
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true //ADD THIS LINE
}
For Androidx Users,
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true //ADD THIS LINE
}
Step 02:
After including those Sync projects and before you run the project ensure that to Build a project before the run. Else, you will get an exception.
Versions of the platform prior to Android 5.0 (API level 21) employ the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. For getting around this limitation, you can include the multidex support library to your project:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
In case your minSdkVersion is fix to 21 or higher, all you require to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
At the time you are using dependencies so your systems increased! google has a solution for that. that named Multidex!
NOTE: ensure that min SDK is over 14.
in your build.gradle :
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
FOR androidX USE :
def multidex_version = "2.0.1"
implementation 'androidx.multidex:multidex:$multidex_version'