gpt4 book ai didi

java - 任务 ':app:transformClassesAndResourcesWithProguardForRelease' 执行失败。 > java.io.IOException : Please correct the above warnings first

转载 作者:行者123 更新时间:2023-12-01 21:22:04 25 4
gpt4 key购买 nike

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

    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

构建.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:

    # 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.* 但什么也没发生!我仍然遇到同样的问题。

最佳答案

您的 build.gradle 中存在一些错误。让我们修复它们,它应该可以解决您的问题。

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

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

android {

buildTypes {
release {
minifyEnabled true
consumerProguardFiles 'proguard-rules.txt'
}
}
}

但该配置对应用程序无效,consumerProguardFiles 仅为 Android 库项目设计。它告诉库项目将指定的 ProGuard 配置文件打包到输出 aar 中。

在应用程序中你必须使用

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

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

请注意,默认的 ProGuard 文件包含所有 Android 应用程序所需的一般 Android 规则(某些规则是由 Android Gradle 插件添加的)。看来您已将大部分默认规则复制到您的配置中。最佳实践是使用默认的 ProGuard 配置文件,不要将它们复制到您自己的配置中。

  • 调整 ProGuard 配置规则
  • 你不需要这条规则

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

    添加忽略这些毕加索警告的规则。您可以使用其中之一

    -dontwarn com.squareup.okhttp.**

    -dontwarn com.squareup.picasso.OkHttpDownloader
  • useLibrary 语句放在正确的位置。
  • 这是一件小事,但你应该解决它。不要将 useLibrary 放入 dependency 闭包中。它属于android闭包。

    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    }

    顺便说一句:确实建议摆脱HttpClient。理想情况下使用 OkHttp

    关于java - 任务 ':app:transformClassesAndResourcesWithProguardForRelease' 执行失败。 > java.io.IOException : Please correct the above warnings first,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38984045/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com