Try adding multiDexEnabled true
to your app build.gradle file.
defaultConfig {
multiDexEnabled true
}
EDIT:
Try Steve's answer first. In case it happens frequently or first step didn't help multiDexEnabled
might help. For those who love to dig deeper here is couple similar issues (with more answers):
:app:dexDebug ExecException finished with non-zero exit value 2
Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException
Another thing to watch for, is that you don't use
compile 'com.google.android.gms:play-services:8.3.0'
That will import ALL the play services, and it'll only take little more than a hello world to exceed the 65535 method limit of a single dex APK.
Always specify only the services you need, for instance:
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
I just had to Clean my project and then it built successfully afterwards.
This error began appearing for me when I added some new methods to my project. I knew that I was nowhere near the 65k method limit and did not want to enable multiDex support for my project if I could help it.
I resolved it by increasing the memory available to the :app:transformClassesForDexForDebug
task. I did this by specifying javaMaxHeapSize in gradle.build
.
gradle.build
android {
...
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
}
}
I tried this after having had no success with other common solutions to this problem:
clean
/app/build
and /build
directories from my projectError
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 '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Note: increasing the memory available to the DEX task can cause performance problems on systems with lower memory - link.
I also faced similar issue in Android Studio 1.5.1 and gradle 1.5.0. I just have to remove unwanted libraries from dependencies which may be automatically added in my app's build.gradle file. One was : compile 'com.google.android.gms:play-services:8.4.0'. So for best practices try to only include specific play services library like for ads include only
dependencies {
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
Although
defaultConfig {
multiDexEnabled true
}
this will also solve the issue, but provides with a lot of Notes in gradle console, making it confusing to find the other real issues during build
you can see the documentation of Android
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<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>
I'm using AS 1.5.1 and encountered the same problem. But just cleaning the project just wont do, so I tried something.
This worked with me, so I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With