-3

My app is running fine on Lollipop devices. But when I try to run the app on below Lollipop devices it is giving error everytime.

the error is given below:

Error:The number of method references in a .dex file cannot exceed 64K. :app:transformClassesWithDexForDebug FAILED Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

My gradle file is below:

defaultConfig {
    applicationId "com.ielts.touchstone.touchstone"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.4"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
Sandeep Singh
  • 1,013
  • 1
  • 11
  • 25

3 Answers3

2

Try adding multiDexEnabled true to your app build.gradle file.

 defaultConfig {
    multiDexEnabled true
}

Also , Clean Your Project first.

karanatwal.github.io
  • 3,613
  • 3
  • 25
  • 57
1

Your app has more than 64K methods which are not supported by default prior to android 5.0, hence the exception. To support more than 64K methods below 5.0 add multidex support to your app. Add the following code in your app module's gradle file

android {
    .
    .
    .

    defaultConfig {
        ... 
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

and in your manifest add the MultiDexApplication class from the multidex support library to the application element.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

More details can be found here

Talha Mir
  • 1,228
  • 11
  • 19
0

Your application is crossing 64K method limit. Upto API 19, android system uses dalvik processors which is having limit of 64k methods. But from API 21, android system uses Android Runtimes, so that you have to add multiDexEnabled true if you are building your app for API 21 n above. It will Configure Apps with Over 64K Methods.

Check this - https://developer.android.com/studio/build/multidex.html

Hope it will help :)

Onkar Nene
  • 1,359
  • 1
  • 17
  • 23