transformClassesAndResourcesWithProguardForRelease FAILED

AndroidGradleAndroid Gradle-Pluginbuild.gradleProguard

Android Problem Overview


I am trying to Build my Android application with Gradle in console. But getting below error about task ':app:transformClassesAndResourcesWithProguardForRelease':

build.gradle:

buildscript {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.2'
    defaultConfig {
        applicationId "com.XXX.XXX"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "0.1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile('com.squareup.retrofit2:retrofit:2.1.0') {
        exclude module: 'okhttp'
    }
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    compile 'com.squareup.retrofit2:converter-moshi:2.1.0'
    compile 'moe.banana:moshi-jsonapi:2.2.0'
    compile 'com.squareup.moshi:moshi-adapters:1.3.1'
    compile 'com.google.android.gms:play-services-maps:9.6.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.firebase:firebase-core:9.6.0'
    compile 'com.google.firebase:firebase-crash:9.6.0'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

./gradlew build --stacktrace

This is the exception I am receiving:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task
':app:transformClassesAndResourcesWithProguardForRelease'.

Android Solutions


Solution 1 - Android

Try adding this code to your proGuard rules, it worked for me

-ignorewarnings
-keep class * {
    public private *;
}

The answer was posted here: https://stackoverflow.com/questions/41362386/execution-failed-for-task-apptransformclassesandresourceswithproguardforrelea

Solution 2 - Android

add this code to ..your-project/app/proguard-rules.pro

 -ignorewarnings

your signed apk will be generated successfully...

> Update : > > That's better to fix your warning messages using -dontwarn or -keep > keys on your proguard-rules.pro... Because if you use (maybe your libraries) java reflection in your code the application will be crashed...

Solution 3 - Android

It worked for me I also had to add following in a pro-gaurd.txt file

#### -- Picasso --
 -dontwarn com.squareup.picasso.**

 #### -- OkHttp --

 -dontwarn com.squareup.okhttp.internal.**

 #### -- Apache Commons --

 -dontwarn org.apache.commons.logging.**

     -ignorewarnings 
-keep class * {
public private protected *;
}

Solution 4 - Android

I have changed nothing just comment

// shrinkResources true
// minifyEnabled true

you don't want to change any proguard file I have already searched for this issue after 2days wasted

Solution 5 - Android

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

Please remove above mentioned code in your gradle. This worked for me. This is only for given problem.

Solution 6 - Android

got this issue due to warning from Android
See comment: https://github.com/flutter/flutter/issues/40218#issuecomment-531047713

add the following rule to /android/app/proguard-rules.pro:
-dontwarn android.**

Solution 7 - Android

Use this code in 'proguard-rules.pro' may be resolve.

-keep class * {
public private protected *;
}

or

-keep class * {*;}
  • note : above commands ignore obfuscates

  • can use this instead above for save obfuscates state

    -keepnames class * {*;}

Solution 8 - Android

In Android Studio click "Rebuild Project" in the "Build" menu.

Solution 9 - Android

I have struggled with proguard-rules.pro for quite some time and am by no means a pro here! I am posting my file to show that you should not -keep class * without any parameters as this turns off all obfuscation. You can however protect every class that extends from a certain class or any class that implements a certain interface. You can also protect any class that has a constructor having specific elements. Please note that I did not comment every single line as I am not 100% sure of what everything does - it's more like an educated guess. My project includes ksoap2 (okhttp3, okio, XmlPull) that's what many rules are for.

Maybe this can be a starting point for you - you still may need to put some additional rules for your classes in.

-android
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.app.Activity
-keepclasseswithmembers class * extends com.way4net.oner.lifa.plugin.ThemedFragment
-keepclasseswithmembers class * extends com.way4net.oner.lifa.plugin.ThemedActivity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keepattributes Signature #there were 1 classes trying to access generic signatures using reflection emfehlung von proguard selbst

-keep public class * extends android.view.View {
      public <init>(android.content.Context);
      public <init>(android.content.Context, android.util.AttributeSet);
      public <init>(android.content.Context, android.util.AttributeSet, int);
      public void set*(...);
}

-keepclasseswithmembers class * {
     public <init>(android.content.Context, android.util.AttributeSet);
 }

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
    public void *(android.view.View);
    public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn android.support.v4.**
#-dontwarn javax.annotation.**
#-dontwarn org.xmlpull.v1.**
-dontnote android.net.http.*
-dontnote org.apache.commons.codec.**
-dontnote org.apache.http.**
-dontnote okhttp3.**
-dontnote org.kobjects.util.**
-dontnote org.xmlpull.v1.**
-keep class okhttp3.** {
      *;
 }

-keep class org.xmlpull.v1.XmlSerializer {
    *;
}
-keep class org.xmlpull.v1.XmlPullParser{
    *;
}
-dontwarn org.xmlpull.v1.XmlPullParser

-keep class org.xmlpull.v1.XmlSerializer {
    *;
}
-dontwarn org.xmlpull.v1.XmlSerializer

-keep class org.kobjects.** { *; }
-keep class org.ksoap2.** { *; }
-keep class okio.** { *; }
-keep class org.kxml2.** { *; }
-keep class org.xmlpull.** { *; }

Solution 10 - Android

I got the same error message when I was trying to build release build in android after install react-native-firebase.

These are the steps I followed,

  1. Do all the configurations they mention in the react-native-firebase documentation.

  2. Build an android app using this command

    ./gradlew assembleRelease

  3. Got this error message.

> FAILURE: Build failed with an exception. > > * What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. > > Job failed, see logs for details

Resolved this issue by changing this code line in android/app/build.gradle

minifyEnabled true

to this

minifyEnabled enableProguardInReleaseBuilds

This was the only change I did. It works for me.

Solution 11 - Android

add -ignorewarnings in your proguard file and keep only those class that you did not want to obfuscate. Some of the libraries suggest to keep some of their classes if you are using proguard rules. Visit your libraries for details

Solution 12 - Android

add this line to gradle properties

android.enableR8=true

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMo MirmousaviView Question on Stackoverflow
Solution 1 - AndroidJohn SpaxView Answer on Stackoverflow
Solution 2 - Androidultra.deepView Answer on Stackoverflow
Solution 3 - AndroidHaris DurraniView Answer on Stackoverflow
Solution 4 - AndroidBrijesh TanwarView Answer on Stackoverflow
Solution 5 - AndroidAyaz MuhammadView Answer on Stackoverflow
Solution 6 - AndroidkenView Answer on Stackoverflow
Solution 7 - AndroidAli BagheriView Answer on Stackoverflow
Solution 8 - AndroidNiclinView Answer on Stackoverflow
Solution 9 - AndroidFrankKrumnowView Answer on Stackoverflow
Solution 10 - AndroidJanaka PushpakumaraView Answer on Stackoverflow
Solution 11 - Androiduser3135923View Answer on Stackoverflow
Solution 12 - AndroidAmbesh TiwariView Answer on Stackoverflow