What is meant by "multiDexEnabled true" in Android gradle. Why do we use this? What is the effect if it is enabled?
-
Possible duplicate of [Android support multidex library implementation](http://stackoverflow.com/questions/26925264/android-support-multidex-library-implementation) – N J Apr 26 '16 at 05:43
3 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

- 18,571
- 11
- 90
- 141

- 74,896
- 15
- 165
- 198
-
21
-
2@fobbymaster have a look here http://stackoverflow.com/questions/6226290/default-value-of-boolean-in-java – IntelliJ Amiya Aug 13 '16 at 05:32
-
1well one reason for it to be false is this bug :) https://stackoverflow.com/a/29458974/1397821 – M. Usman Khan Sep 19 '19 at 15:33
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

- 1
- 1

- 16,950
- 7
- 90
- 88
-
It still will have the 64k limit per `.dex` - but as the name suggests, it's multi-dex (more than one dex file). – Martin Zeitler Jan 25 '20 at 17:29
-
is there any problem in building an app with more than 64k methods – Asbah Riyas Jul 07 '20 at 13:17
It allows you to build apps with over 64k methods. For more information see here http://developer.android.com/intl/es/tools/building/multidex.html

- 12,667
- 7
- 37
- 64