Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "multiDexEnabled true" mean?

What is meant by "multiDexEnabled true" in Android gradle. Why do we use this? What is the effect if it is enabled?

like image 402
shekhar pande Avatar asked Apr 26 '16 05:04

shekhar pande


People also ask

What is multi Dex 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 .

What is the use of multidex in Android?

In Android, the compilers convert your source code into DEX files. This DEX file contains the compiled code used to run the app.

How do I disable multidex?

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.


2 Answers

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

like image 95
IntelliJ Amiya Avatar answered Nov 13 '22 07:11

IntelliJ Amiya


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.

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 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.

How to enable multidex support

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

Advantage of multiDex

multidex allows your applications to have more third-party libraries.

More on .dex files

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

like image 39
Rohit Singh Avatar answered Nov 13 '22 06:11

Rohit Singh