Open In App

How to fix “Execution failed for task ‘:app:transformClassesWithDexForRelease’ in Android Studio?

Last Updated : 24 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Method  1

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),

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

and, in gradle file, you should do this changes and this will help you in resolving this error.

defaultConfig {

   applicationId “yourProjectPackage”

   minSdkVersion 15

   versionCode 1

   versionName “1.0”

   targetSdkVersion 23

   multiDexEnabled true //important

}

Method 2

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.

Method 3

If you make multiDexEnabled = true in defaultConfig of the app (Gradle File), you will be able to resolve this error.

defaultConfig {

   minSdkVersion 14

   targetSdkVersion 22

   multiDexEnabled = true

}

Method 4

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.

android {

// snippet

// add this into your existing ‘android’ block

   dexOptions {

   javaMaxHeapSize “4g”

   }

// snip

}

Note: 4g is 4 Gigabytes and this is a maximum heap size for dex operation.

  • Step 3: Try your build again.

Method 5

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

Method 6

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:

compile ‘com.google.android.gms:play-services:7.5.0’

to

compile ‘com.google.android.gms:play-services:9.0.0’


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads