# Android Gradle Multidex ###### tags: `Android Gradle` [TOC] # Introduction First we have to know that according to **[android main website](https://developer.android.com/studio/build/multidex)**: We can **only have** 65,536 methods in our project. >Android app (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. [color=red] # What is Multidex? Knowing we can only have 65,536 methods in total, what if we want more than that? Then we will need to allow **Multidex**. However, allowing multidex way differs according to the android version you are targeting, whether it is: * **>=21 (multidexEnabled = true)** * **<21 (implement dependency)** ## >=21 (multidexEnabled true) In **build.gradle(:app)** in side **android{}**, you may see condiguration sector, where you usually set up the min SDK, there we can just enable the multidex by using **multiDexEnabled true**. **build.gradle(:app):** ```java= defaultConfig { minSdkVersion 19 targetSdkVersion 30 versionCode 1 versionName "1.0" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] includeCompileClasspath = true } } } ``` ## <21 (implement dependency) In **build.gradle(:app)** just go to dependencies and add it as a dependency below. ```java= def multidex_version = '1.0.2' implementation com.android.support:multidex:${multidex_version} ``` # How do we calculate the amount of methods in project? Number of methods is equal to: >methods written by you + Android Framework methods + Third party library (eg Volley, Retrofit, Facebook SDK etc) methods.[color=pink] # Reference [StackOverflow: What does “multiDexEnabled true” mean?](https://stackoverflow.com/questions/36856068/what-does-multidexenabled-true-mean)