任务“:app:transformClassesAndResourcesWithProguardForRelease”执行失败 Android

Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease' Android

我正在 Android 中构建应用程序,这是 build.gradle 文件:

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'
}

当我尝试构建我的应用程序时,我收到以下导致构建失败的警告:

http://pastebin.com/EhMr66Yg

我应该为这些警告添加-dontwarn 规则吗?是什么原因造成的?

构建失败是因为 67 条警告还是最后一条警告:

“有 1 个未解决的对库 class 成员的引用。 您可能需要更新库版本。"

谢谢。

这不是 gradle 问题。这些问题是由 ProGuard 引起的。您需要修复 ProGuard 配置文件。

查看这些链接以获得更多帮助:

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

Using ProGuard with Android

你必须使用以下内容。

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

和其他导致 warning.These classes 的 class 可能会自我混淆,因此您无需在 them.Hope 上应用 pro-guard 这将起作用给你。

问题出在 Proguard 的链接问题上。 ProGuard 优化了字节码,删除了未使用的代码指令,并使用短名称混淆了剩余的 类、字段和方法。混淆代码使您的 APK 难以进行逆向工程,这在您的应用使用安全敏感功能时尤为重要

有关混淆器的更多信息,请查看此处: https://developer.android.com/studio/build/shrink-code.html

您 build.gradle 中使用的每个库的混淆器特定规则应放置在 "proguard-rules.pro" 文件中,如屏幕截图所示。

注意:proguard 文件可以更改。

来到要写的规则。

-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*();
}

注意:有关进一步的库混淆规则,请使用 https://github.com/krschultz/android-proguard-snippets