46
votes

I am getting the exception below when I am trying to run the application using Android Studio:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 2

10
Please try the following: stackoverflow.com/a/32889565 Hope it helps. - Ran Hassid
What is your com.android.tools.build:gradle version? - Jeffrey Mixon

10 Answers

57
votes

I have same issue, after few hour research, i found a solution to fix it.

You should fixed build.gradle :

android {

    compileSdkVersion ..
    buildToolsVersion '...'

    defaultConfig {
       ...
       targetSdkVersion ..
       multiDexEnabled true  // this line will solve this problem
   }
}

If the number of method references in your app exceeds the 65K limit, your app may fail to compile.

For information on how to do this, see Selectively compiling APIs into your executable and Building Apps with Over 65K Methods

14
votes

in my case using android studio 2.0 preview 4 I suddenly got that problem and adding multiDexEnabled true didn't help, and also clean and rebuilt didn't help.

so the only thing that solved it for me is deleting that file:

YOUR_APP_NAME\app\build\intermediates

and run the application and it works.

5
votes

Modify the module-level build.gradle file

 android {
    ...

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

}

add dependencies compile 'com.android.support:multidex:1.0.0'

In your manifest add the MultiDexApplication class

<manifest ...>
<application
    ...
    android:name="android.support.multidex.MultiDexApplication">
    ...
</application>

http://developer.android.com/studio/build/multidex.html

4
votes

For me closing all other Android Studio solved the problem.

I had opened 3 android studios when I was getting the error, after I closed 2 I didn't get any error.

No need to add any code related to multiDex !

Seems like there was some memory issue related to jvm.

2
votes

Just fixed this issue. In my case, rebuilding the project helped for me. So, try to rebuild your project.

0
votes

Add the following line:

multiDexEnabled true

Inside the defaultConfig of build.gradle

Like this:

defaultConfig{
    multiDexEnabled true
}
0
votes

At my case change buildToolsVersion from "24" to "23.0.2", solve the problem. This will solve the problem especially if you're using old Android Studio less than version 2.

0
votes

I found the answer from here: After change the build.grade file with the following

minSdkVersion 21

targetSdkVersion 25

multiDexEnabled true

works fine.

0
votes

in my case - Clean Project and Rebuild

0
votes

In my case I was going back and forth between Expo and Android Studio for react native. Expo wanted one application name in order to build and Android Studio wanted another, once I put it back to the name that android studio wanted it built and deployed fine.

Expo

AppRegistry.registerComponent('main', () => App);

Android Studio

AppRegistry.registerComponent('AwesomeProject', () => App);