任务“:app:transformClassesAndResourcesWithProguardForRelease"执行失败.>java.io.IOException: 请先更正以上警告 [英] Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. > java.io.IOException: Please correct the above warnings first

查看:29
本文介绍了任务“:app:transformClassesAndResourcesWithProguardForRelease"执行失败.>java.io.IOException: 请先更正以上警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 android studio 1.5.1 中生成签名的 Apk 并完成有关此过程的对话框时,我遇到了此消息并且构建中止:

When I tried to Generate Signed Apk in android studio 1.5.1 and completing the Dialog appeared about this process, I faced with this message and building aborted:

    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Call
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Call
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache

build.gradle:

build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        ....
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            consumerProguardFiles 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.jakewharton:butterknife:8.0.1'
    android{
        useLibrary  'org.apache.http.legacy'
    }
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.onesignal:OneSignal:2.+@aar'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-analytics:+'
    compile 'com.google.android.gms:play-services-location:+'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
}

proguard-rules.txt :

proguard-rules.txt :

    # This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags.  Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik.  The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.)  Make sure you
# test thoroughly if you go this route.
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

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

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

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

经过大量搜索,我明白我应该使用 -dontwarn com.squareup.picasso.* 但什么也没发生!我仍然有同样的问题.

After a lot of searching, I understood that I should use -dontwarn com.squareup.picasso.* but nothing happened! and I still have the same problem.

推荐答案

您的 build.gradle 中有几个错误.让我们修复它们,它应该可以为您解决问题.

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

  1. Gradle 脚本中的 ProGuard 配置文件定义

这可能是您问题的根本原因.你真的确定你的 ProGuard 配置文件 proguard-rules.txt 被使用了吗?因为从构建脚本看来并非如此.你用

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

但该配置对应用程序无效,consumerProguardFiles 仅适用于 android 库项目.它告诉库项目将指定的 ProGuard 配置文件打包到输出 aar 中.

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.

在应用中你必须使用

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

配置 proguardFiles 告诉构建应用指定的 ProGuard 配置文件.所以这意味着它不是为您的构建定义的.

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

请注意,默认的 ProGuard 文件包含所有 Android 应用程序所需的通用 Android 规则(有些规则是由 Android Gradle 插件添加的).您似乎将大部分默认规则复制到您的配置中.最佳做法是使用默认的 ProGuard 配置文件,不要将它们复制到您自己的配置中.

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. 调整 ProGuard 配置规则

你不需要这个规则

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

添加忽略那些毕加索警告的规则.您可以使用任何一个

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

-dontwarn com.squareup.okhttp.**

-dontwarn com.squareup.picasso.OkHttpDownloader

  1. useLibrary 语句放在正确的位置.
  1. Place useLibrary statement at the correct place.

这是一件小事,但你应该尽快解决它.不要将 useLibrary 放入 dependencies 闭包中.它属于 android 闭包.

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

顺便说一句:真的建议去掉 HttpClient.理想情况下使用 OkHttp.

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

这篇关于任务“:app:transformClassesAndResourcesWithProguardForRelease"执行失败.&gt;java.io.IOException: 请先更正以上警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆