50

Every time I am getting this error when running my project. I can do a Clean and then Run again, and it works. But it is not an optimal solution. Any ideas?

Error:Execution failed for task ':android:transformClassesAndResourcesWithProguardForRelease'.

java.io.IOException: Failed to rename android\build\intermediates\transforms\proguard\release\folders\3\1f\main\classes.jar to android\build\intermediates\transforms\proguard\release\jars\3\1f\classes.jar

Deividi Cavarzan
  • 10,034
  • 13
  • 66
  • 80
Z0q
  • 1,689
  • 3
  • 28
  • 57
  • 2
    This issue is coming due to pro-guard enable in the release config of the app. So the solution is either remove pro-guard or put the indicated code snippet as in the link https://readyandroid.wordpress.com/errorexecution-failed-for-task-apptransformclassesandresourceswithproguardforrelease/ – Ready Android May 02 '18 at 13:40

7 Answers7

42

This bug happens when the versions of SDK, Build Tools and Gradle Plugins doesn't match (in terms of compatibility). The solution is to verify if you are using the latest versions of them. The gradle plugins are placed in the build.gradle file of the project. Other versions are in the build.gradle file of the module. For example, for SDK 23, you must use the Build Tools 23.0.1 and gradle plugins version 1.3.1.

Clean the project after changing settings. (Solved my problem, and never seen it again.)

refer this question

dell116
  • 5,835
  • 9
  • 52
  • 70
Blue_Alien
  • 2,148
  • 2
  • 25
  • 29
  • 17
    I tried it with **SDK 24**, **Build Tools 24.0.0** and gradle **plugin version 2.1.2**, I'me having the same problem.. – Sohayb Hassoun Jun 26 '16 at 15:03
  • 2
    @sohayb Perhaps you have an issue in your proguard file with some of the 3rd party libraries? That happened in my case...I just added the correct rules for the external library and it was sufficient. – box Oct 24 '16 at 12:28
  • I am using: compileSdkVersion 27, buildToolsVersion "27.0.3", minSdkVersion 16, targetSdkVersion 25 and gradle plugin version 3.0.1 I am facing the same problem. What should I do? – salvi shahzad Nov 01 '18 at 05:33
  • same problem @salvishahzad actually you dont need the "buildToolsVersion" so you can comment that line and android get the version that works with gradle in my case i can solve the problem adding --dontwarn retrofit2.Platform$Java8 like in https://stackoverflow.com/questions/36010942/getting-warnings-with-proguard-with-external-libraries/36011233#36011233 – imaginabit Nov 25 '18 at 22:51
  • In my case Issue was : "The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.3.1" – Ali Akram Feb 20 '19 at 08:28
4

Remove lines from proguard-rules.txt that contains:

-injars, -outjars, or -libraryjars

and rebuild.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
user1367713
  • 286
  • 2
  • 4
  • 11
1

in my case it was okhttp proguard rules after adding them it worked fine

#OKhttp RULES START
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
#OKhttp RULES END

#picasso rules START
-dontwarn com.squareup.okhttp.**
#picasso rules END
Mateen Chaudhry
  • 631
  • 12
  • 32
1

Removing minifyEnabled true from release config worked for me.

Sabri Meviş
  • 2,231
  • 1
  • 32
  • 38
  • I think that's only a temporary solution for someone who is not wanted to do it. like disable R8, or not using proguard – petrov Jan 28 '22 at 12:04
0

In my case the problem was fixed by downgrading the Proguard version used by Gradle to generate the signed apk. You can downgrade it by placing this block inside the project level build.gradle file. Place it into the buildscript block.

configurations.all {
    resolutionStrategy {
        force 'net.sf.proguard:proguard-gradle:5.2.1'
    }
}

You can check the current version of Proguard by executing this command at the project root folder:

./gradlew buildEnvironment | grep proguard

Here is part of the Proguard stacktrace to help others find the problem I was having.

Caused by: java.io.IOException: java.lang.NullPointerException
at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:283)
at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:63)
at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:173)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:225)
Caused by: java.lang.NullPointerException
at proguard.optimize.info.NonEmptyStackReturnMarker.setReturnsWithNonEmptyStack(NonEmptyStackReturnMarker.java:102)
at proguard.optimize.info.NonEmptyStackReturnMarker.markReturnWithNonEmptyStack(NonEmptyStackReturnMarker.java:95)
at proguard.optimize.info.NonEmptyStackReturnMarker.visitSimpleInstruction(NonEmptyStackReturnMarker.java:76)
...
at proguard.optimize.Optimizer.execute(Optimizer.java:649)
at proguard.ProGuard.optimize(ProGuard.java:328)
at proguard.ProGuard.execute(ProGuard.java:127)
at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:54)
at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:254)
... 5 more
Shumoapp
  • 1,489
  • 16
  • 15
  • Hi I also have the same problem , can you help, for the issue please follow this link https://stackoverflow.com/questions/45629710/build-fails-with-apptransformclassesandresourceswithproguardforrelease-on-upgra – Awadesh Aug 12 '17 at 05:00
0

You should try this: add in proguard-rules.pro

-keepattributes EnclosingMethod
Muhammad Usman Ghani
  • 1,279
  • 13
  • 19
  • Add this line in your `proguard-rules.pro` file to fix this problem . @salvishahzad `-ignorewarnings` – Sanche Feb 18 '19 at 06:25
-5

It's works when you modify minifyEnabled to false.

refer this Android Studio Signed APK ':app:transformClassesAndResourcesWithProguardForRelease'

mya
  • 81
  • 11