1

I am trying to run project on Android device as well as on emulator. but unfortunately I am getting two errors.

Error 1:

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

Error 2:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
user3563459
  • 567
  • 1
  • 4
  • 14
  • 2
    try this : http://stackoverflow.com/questions/26609734/how-to-enable-multidexing-with-the-new-android-multidex-support-library – M.Waqas Pervez Aug 29 '16 at 13:35
  • You need to add multidex support – Adnan Aug 29 '16 at 13:38
  • There's a link right in the error message, just follow it and learn what 64k method limit is. Multidex is not the first solution you should be looking at, review the dependencies of your project and eliminate those that are not used. – Egor Aug 29 '16 at 13:42
  • Added "multiDexEnabled true" in defaultConfig and added "compile 'com.android.support:multidex:1.0.0'" in dependency. Also added " MultiDex.install(this);" in Singlton class. Still getting the same error. – user3563459 Aug 30 '16 at 09:31

2 Answers2

1

I had some problems like your first problem too some time ago. I solved it by using multiDexEnabled true in the defaultConfig. You should try that out!

jdstaerk
  • 882
  • 1
  • 13
  • 30
  • Added "multiDexEnabled true" in defaultConfig and added "compile 'com.android.support:multidex:1.0.0'" in dependency. Also added " MultiDex.install(this);" in Singlton class. Still getting the same error. – user3563459 Aug 30 '16 at 09:33
  • Same case with me. :( – ReGaSLZR Aug 29 '17 at 09:18
0

In your build.gradle:

android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

     defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }
}

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

Then you need to extend your application class from MultiDexApplication or include this snippet into it:

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
         MultiDex.install(this);
    }

}

Here is the official guide.

Geralt_Encore
  • 3,721
  • 2
  • 31
  • 46
  • Added "multiDexEnabled true" in defaultConfig and added "compile 'com.android.support:multidex:1.0.0'" in dependency. Also added " MultiDex.install(this);" in Singlton class. Still getting the same error. – user3563459 Aug 30 '16 at 09:33
  • Did you apply your application class in AndroidManifest? – Geralt_Encore Aug 30 '16 at 16:09