When we run our app in debug mode in Android Studio, it runs successfully but when we switch to release mode, it fails and throws the error:
**FAILURE: Build failed with an exception.**
> Execution failed for task ‘:app:transformClassesWithDexForRelease’.
> 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 1
So, In this article, we will discuss 6 different methods for fixing the “Execution failed for task ‘:app:transformClassesWithDexForRelease” error in Android Studio.
We can fix this error by adding few lines of code in the “local.properties” file and also in “gradle” file.
In local.properties (The local.properties file goes in the project’s root level),
and, in gradle file, you should do this changes and this will help you in resolving this error.
multiDexEnabled true //important
This error “Execution failed for task ‘:app:transformClassesWithDexForRelease” in Android Studio can also be resolved after the removal of jar file from your project which seems that one of the jar files inside your project was using an older version of google play services.
If you make multiDexEnabled = true in defaultConfig of the app (Gradle File), you will be able to resolve this error.
multiDexEnabled = true
We can also resolve this issue by following these steps:
- Step 1: Open your app’s build.gradle (not the one in the project root).
- Step 2: Add this Code Snippet.
// add this into your existing ‘android’ block
Note: 4g is 4 Gigabytes and this is a maximum heap size for dex operation.
- Step 3: Try your build again.
Another issue that could be causing this may be some sort of external library you are using, that is referencing a prior version of your dependency. Follow these steps in that case:
- Go to SDK manager, and install any updates to your dependencies
- Make sure that your build.gradle file shows the latest version. To get the latest version, use this link: https://developers.google.com/android/guides/setup
- Edit your library (or install an updated version if that exists), to reference the latest version
This error “Execution failed for task ‘:app:transformClassesWithDexForRelease’ in Android Studio can also occurred when we upgrading Google play services to 9.0 from 7.5. So, to resolve this–
Change this code snippet: