问题
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
回答1:
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
回答2:
Remove lines from proguard-rules.txt that contains:
-injars
, -outjars
, or -libraryjars
and rebuild.
回答3:
Removing minifyEnabled true
from release config worked for me.
回答4:
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
回答5:
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
回答6:
You should try this: add in proguard-rules.pro
-keepattributes EnclosingMethod
回答7:
It's works when you modify minifyEnabled to false.
refer this Android Studio Signed APK ':app:transformClassesAndResourcesWithProguardForRelease'
来源:https://stackoverflow.com/questions/33877134/errorexecution-failed-for-task-androidtransformclassesandresourceswithprogua