Configure App for Multidex with Gradle

This guide is writing for those who get 64K method limit exceeded error while building APK. Normally app is compiled into DEX, Dalvik Executable, file inside APK(a zip format). For a dex file it has methods compiled it and there is limit of 64k (exactly 65,536—including Android framework methods) methods per dex file. If this limit exceeds then you get build error.

It gets often when you use large number of dependencies. for example pay services, image loading libraries , HTTP request libraries , json encode and decode libraries etc. These libraries are very much required for applications these days. It helps us saving time by simply adding it into dependency section in the gradle file.

MultiDex means splitting dex into multiple dex file so each has less than 64K methods.

Enable MultiDex In Gradle

Enable multidexing in main module (by default it is app). Also add support library for multidexing in dependency section if your minSdkVersion is lower than 21.