Proguard 和错误

Posted

技术标签:

【中文标题】Proguard 和错误【英文标题】:Proguard and error 【发布时间】:2015-09-15 22:40:29 【问题描述】:

我使用这个 proguard 文件:

 -dontskipnonpubliclibraryclasses
 -dontskipnonpubliclibraryclassmembers

 !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
 -optimizationpasses 10
 -allowaccessmodification
 -mergeinterfacesaggressively
 -overloadaggressively

 -assumenosideeffects class android.util.Log 
*;
 

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v4.app.DialogFragment
-keep public class * extends com.actionbarsherlock.app.SherlockListFragment
-keep public class * extends com.actionbarsherlock.app.SherlockFragment
-keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity
-keep public class * extends android.app.Fragment
-keep public class com.android.vending.licensing.ILicensingService
-keep public class org.jsoup.** 
public *;


-keep public class * extends android.view.View 
 public <init>(android.content.Context);
 public <init>(android.content.Context, android.util.AttributeSet);
 public <init>(android.content.Context, android.util.AttributeSet, int);
 public void set*(...);


-keepclasseswithmembers class * 
 public <init>(android.content.Context, android.util.AttributeSet);


-keepclasseswithmembers class * 
 public <init>(android.content.Context, android.util.AttributeSet, int);


-keepclassmembers class * extends android.app.Activity 
 public void *(android.view.View);


-keepclassmembers enum * 
 public static **[] values();
 public static ** valueOf(java.lang.String);


-keep class * implements android.os.Parcelable 
 public static final android.os.Parcelable$Creator *;


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


-keep class android.support.v4.app.**  *; 
-keep interface android.support.v4.app.**  *; 
-keep class com.actionbarsherlock.**  *; 
-keep interface com.actionbarsherlock.**  *; 

-keep class com.google.ads.** *;
-keep class com.google.ads.internal.** *;
-keep class com.google.ads.mediation.** *;
-keep class com.google.ads.mediation.adfonic.** *;
-keep class com.google.ads.mediation.admob.** *;
-keep class com.google.ads.mediation.adfonic.util.** *;
-keep class com.google.ads.mediation.customevent.** *;
-keep class com.google.ads.searchads.** *;
-keep class com.google.ads.util.** *;

-dontwarn android.support.**
-dontwarn com.google.ads.**

但是在对代码进行一些更新后,我有以下错误:

Warning:com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.params.BasicHttpParams
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.params.BasicHttpParams
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning:com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateParseException
Warning:com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning:com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.Header
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.ClientProtocolException
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest

我试过了:

-keep class org.apache.http.**
-keep interface org.apache.http.**
-dontwarn org.apache.**

还是不行,怎么回事?我真的不明白我能做什么。 PS你有什么建议可以优化我的文件吗? 提前致谢。

【问题讨论】:

这些警告是来自 ProGuard 本身还是来自您的程序运行时的警告? 当我像往常一样尝试制作签名 APK 时,这些警告来自 Android Studio。 Can't generate APK after adding Google Analytics, but working fine in debug mode 的可能重复项 【参考方案1】:

我遇到了同样的问题。

我在这里找到了答案,它对我有用:How to add Apache HTTP API (legacy) as compile-time dependency to build.grade?

在您的*** build.gradle 文件中添加:

buildscript 
    ...
    dependencies 
        classpath 'com.android.tools.build:gradle:1.3.1'
    

...

在您的应用特定的 build.gradle 文件中添加:

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

希望它对你有用!它现在与 ProGuard 一起工作。我和你有完全相同的问题。

【讨论】:

它不适用于libGoogleAnalyticsServices.jar【参考方案2】:

看起来警告来自谷歌图书馆,你有没有尝试过这样的事情:

-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.**

我也会尝试不使用dontwarn,因为如果有需要警告的内容,我会假设您希望收到警告!

【讨论】:

会是类似的问题吗? code.google.com/p/android-developer-preview/issues/… 是的,我正在阅读,但是使用:``` -dontwarn org.apache.http.** -dontwarn android.net.http.AndroidHttpClient -dontwarn com.google.android.gms.* * -dontwarn com.android.volley.toolbox.** 仍然不起作用。 那么必须做点别的...抱歉,这没有帮助。【参考方案3】:

在 Eclipse 中找到 ..sdk/platforms/android-23/optional 中的 org.apache.http.legacy.jar。

像外部 jar 一样导入它,检查订单/导出和 proguard 类型:

-keep class org.apache.http.**  *; 
-keepclassmembers class org.apache.http.** *;
-dontwarn org.apache.**

-keep class android.net.http.**  *; 
-keepclassmembers class android.net.http.** *;
-dontwarn android.net.**

【讨论】:

【参考方案4】:

在您的 proguard 文件中添加以下行。

-keep class org.apache.http.**  *; 
-keep class org.apache.**  *; 
-dontwarn org.apache.**
-dontwarn org.apache.http.**
-dontwarn org.apache.commons.**

【讨论】:

以上是关于Proguard 和错误的主要内容,如果未能解决你的问题,请参考以下文章

Proguard 返回错误 1 ​​- 项目 bin 文件夹中没有 proguard.txt 文件?

新(空白)项目上的尴尬 Proguard 错误

proguard.ParseException:proguard.cfg 中的未知选项“-encryptstrings”

未捕获的翻译错误构建proguard

Android - proguard 和 google play 服务的应用程序导出错误

使用 Android Studio 签署 APK 时出现 Proguard 错误