May 18, 2017

Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

While building an android app in Android Studio, I got the below error and the build was failed.

Error: The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

The solution to avoid this error is, add the property "multiDexEnabled true" under defaultConfig in app's build.graddle file. It will look like below.

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.sonuappz.app"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }


Update:

The above solution works for the issue but the root cause is because of multiple libraries added in the app may have same references inside. Try to identify what library exactly needed for the app and remove the extras. If still the issue occurs, above is the solution for it.