Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transformClassesAndResourcesWithProguardForRelease FAILED

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'.
like image 396
Mo Mirmousavi Avatar asked Jan 03 '17 23:01

Mo Mirmousavi


6 Answers

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

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

The answer was posted here: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease

like image 141
John Spax Avatar answered Nov 20 '22 01:11

John Spax


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...

like image 40
ultra.deep Avatar answered Nov 20 '22 01:11

ultra.deep


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 *;
}
like image 8
Haris Durrani Avatar answered Nov 20 '22 02:11

Haris Durrani


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

like image 7
Brijesh Tanwar Avatar answered Nov 20 '22 01:11

Brijesh Tanwar


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.

like image 3
Ayaz Muhammad Avatar answered Nov 20 '22 00:11

Ayaz Muhammad


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.**

like image 1
ken Avatar answered Nov 20 '22 01:11

ken