pavlos163
pavlos163

Reputation: 2890

Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease' Android

I am building an app in Android, this is the build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "myApp"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile project(':geth')
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'org.web3j:core-android:1.1.0'
    testCompile 'junit:junit:4.12'
}

When I try to build my app, I get the following warnings which result to a failed build:

http://pastebin.com/EhMr66Yg

Should I add -dontwarn rules for these warnings? What causes them?

Does the build fail because of the 67 warnings or because of the last one:

"there were 1 unresolved references to library class members. You probably need to update the library versions."

Thanks.

Upvotes: 1

Views: 2095

Answers (3)

Chaitanya Atkuri
Chaitanya Atkuri

Reputation: 1672

The issue is with the linking problem of the Proguard. ProGuard optimizes the bytecode, removes unused code instructions, and obfuscates the remaining classes, fields, and methods with short names. The obfuscated code makes your APK difficult to reverse engineer, which is especially valuable when your app uses security-sensitive features

For more info of proguard look here : https://developer.android.com/studio/build/shrink-code.html

The proguard specific rules for each library used in your build.gradle should be placed in "proguard-rules.pro" file as shown in the screenshot.

enter image description here

Note : The proguard file can be changed.

Coming to the rules to be written.

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.android.volley.** { *; }
-keep interface com.android.volley.** { *; }
-keep class org.apache.commons.logging.**
-keepattributes *Annotation*

-dontwarn org.apache.**

-keepattributes Annotation,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.* { ; }
-dontwarn com.fasterxml.jackson.databind.
-keep class org.codehaus.* { ; }
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
-keep public class your.class.* {
public void set_(_);
public ** get*();
}

NOTE: For further library proguard rules, use https://github.com/krschultz/android-proguard-snippets

Upvotes: 1

Kuldeep Saini
Kuldeep Saini

Reputation: 70

You have to use following.

-dontwarn com.squareup.**
-dontwarn com.fasterxml.**

and else class which are causing the warning.These classes may be self-obfuscated so you needn't apply pro-guard over them.Hope this will work for you.

Upvotes: 0

Hod
Hod

Reputation: 2276

This isn't a gradle issue. The problems are caused by ProGuard. You need to fix your ProGuard config file.

See these links for more help:

http://proguard.sourceforge.net/manual/troubleshooting.html

Using ProGuard with Android

Upvotes: 0

Related Questions