What is meant by "multiDexEnabled true" in Android gradle. Why do we use this? What is the effect if it is enabled?
Multidex support for Android 5. 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 classes N . dex files and compiles them into a single .
In Android, the compilers convert your source code into DEX files. This DEX file contains the compiled code used to run the app.
Show activity on this post. You can disable multidex only if your project doesn't exceed either 65k methods limitation or 65k fields limitation. People seems to be unaware about the 65k fields limitation. You can hit the fields limitation if you're using huge total of resources like drawable, string id, etc.
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.
You should read official guide line about Building Apps with Over 64K Methods
Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.
When we say the number of methods, it means
methods written by you + Android Framework methods + Third party library (eg Volley, Retrofit, Facebook SDK etc) methods.
I have read somewhere in a post that
App Compat 24.2.1 contains 16.5k methods
Google Play Services GCM 9.6.1 contains 16.7k methods.
So if you have just written a simple Hello world application which has App Compat 24.2.1 then your application is already having 16.7k methods.
it depends on minSdkVersion of your app
If minSdkVersion >= 21 then you can enable it by writing multidexEnabled = true
if minSdkVersion <21 then you will have to include Multidex Compatibily library in your gradle.
See more on enabling multidex support
multidex allows your applications to have more third-party libraries.
Android applications are compiled into a .dex file/files which in turn zipped to a single .apk file. .dex files have bytecodes which are used by Dalvik Virtual Machine(DVM).
You can read more on .dex and DVM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With