What does “multiDexEnabled true” means in Android Studio?

KUNAL PASRICHA
2 min readJun 25, 2021

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply allows you to build apps with over 64k methods.

But I will never write 65536 methods!

When we say the number of methods, it means
methods written by you + Android Framework methods + Third party library (eg Retrofit, Google Ads SDK, SmartRecyclerView, Firebase SDK etc) methods.”

Multidex support for Android 5.0 and higher

Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher multidex is enabled by default, and you do not need the multidex library. For more checkout this google documentation

Configure your app for multidex

If your minSdkVersion is set to 21 or higher, multidex is enabled by default and you do not need the multidex library.

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex library and make the following modifications to your app project:

  1. Modify the build.gradle(module) file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}

dependencies {
implementation "androidx.multidex:multidex:2.0.1"
}

For more information see here — https://developer.android.com/studio/build/multidex

--

--