Error:Execution Failed for Task ':Android:Transformclassesandresources
withproguardforrelease'

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguard
ForRelease' while generating APK

Finally, I have found that MPAndroidChart has a document in which tells you how to configure Proguard.

With the following configuration:

-keep class com.github.mikephil.charting.** { *; }
-dontwarn io.realm.**

I was able to create the obfuscate APK without any warnings.

Also, I have noticed that itextpdf was a library that I used on the past but I did not need it nowadays so I just have to delete it from the dependencies on my gradle file and the warnings also have dissapeared.

Android build error : Error:Execution failed for task ':app:transformClassesAndResourcesWithProguard
ForRelease'

You need to add those lines to your proguard-rules.pro file:

# exclusions for Okio
-dontwarn okio.**

# exclusions for Retrofit
-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions

# exclusions for RxJava
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
-dontwarn sun.misc.Unsafe

Dont' forget to load the correct file during the release build

release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

Execution failed for task ':app:transformClassesAndResourcesWithProguard
ForRelease' with -keep flag

Well it didn't take long but I went into Build -> Edit Build Types and in here I selected release, and manually selected my proguard-rules.txt, clicked OK and it basically added

proguardFile '.../StudioProjects/App/proguard-rules.txt'

which got the build to work successfully.

Error:Execution failed for task ':android:transformClassesAndResourcesWith
ProguardForRelease'

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

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguard
ForRelease

Based on the warnings you are getting, I see that you have dependencies on libraries that rely on parts of the Java Runtime (rt.jar) but are not part of Android's runtime (android.jar), hence the warnings you get from ProGuard.

If your app still works with all these components missing, you can configure ProGuard not to warn you about this, so in your proguard configuration file (e.g. proguard-project.txt) you can try adding these:

-dontwarn javax.servlet.**
-dontwarn org.joda.time.**
-dontwarn org.w3c.dom.**

This should help you address any extra warnings that may remain on your build:

ProGuard Manual > Troubleshooting > Warning: can't find referenced class

Execution failed for task ':app:transformClassesAndResourcesWithProguard
ForRelease'. java.io.IOException: Please correct the above warnings first

There are couple of bugs in your build.gradle. Let's fix them, it should solve the problems for you.

  1. ProGuard config file definition in the Gradle script

This is probably the root cause of your problems. Are you really sure your ProGuard config file proguard-rules.txt is used? Because it doesn't seem so from the build script. You use

android {

buildTypes {
release {
minifyEnabled true
consumerProguardFiles 'proguard-rules.txt'
}
}
}

but that config is not valid for an application, consumerProguardFiles is designed for android library projects only. It tells the library project to package the specified ProGuard config files into the output aar.

In application you have to use

android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-rules.txt', getDefaultProguardFile('proguard-android.txt')
}
}
}

The config proguardFiles tells the build to apply the specified ProGuard config files. So that means it's not defined for your build.

Note that the default ProGuard file contains general Android rules that are necessary for all Android apps (and some rules are added by the Android Gradle plugin).
It seems you copied most of the default rules into your config.
Best practice is to use the default ProGuard config file, don't copy them into your own config.


  1. Adjust ProGuard config rules

You don't need this rule

-keep com.squareup.picasso.** { ; }

Add rules for ignoring those Picasso warnings. You can use either

-dontwarn com.squareup.okhttp.**

or

-dontwarn com.squareup.picasso.OkHttpDownloader

  1. Place useLibrary statement at the correct place.

This is a minor thing, but you should shill fix it. Don't place useLibrary into dependencies closure. It belong into android closure.

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'

}

Btw: it's really advised to get rid of HttpClient. Ideally use OkHttp.



Related Topics



Leave a reply



Submit