50
votes

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

7
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 readyandroid.wordpress.com/… - Ready Android

7 Answers

42
votes

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

4
votes

Remove lines from proguard-rules.txt that contains:

-injars, -outjars, or -libraryjars

and rebuild.

2
votes

Removing minifyEnabled true from release config worked for me.

1
votes

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
0
votes

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
0
votes

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

-keepattributes EnclosingMethod
-5
votes