Android studio - Proguard 似乎忽略了规则,导致构建错误
Posted
技术标签:
【中文标题】Android studio - Proguard 似乎忽略了规则,导致构建错误【英文标题】:Android studio - Proguard seems to ignore rules, resulting in build error 【发布时间】:2017-03-04 21:29:27 【问题描述】:我在尝试使用 proguard 制作签名的 apk 时不断收到以下错误:
Warning:com.dropbox.client2.DropboxAPI: can't find referenced class org.json.simple.JSONArray
Warning:com.dropbox.client2.DropboxAPI$DropboxFileInfo: can't find referenced class org.json.simple.JSONValue
Warning:com.dropbox.client2.DropboxAPI$Entry: can't find referenced class org.json.simple.JSONArray
Warning:com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.JSONParser
Warning:com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.ParseException
Warning:com.dropbox.client2.jsonextract.JsonExtractionException: can't find referenced class org.json.simple.JSONValue
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.Picasso
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.Picasso$Builder
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.RequestCreator
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.Picasso
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.Picasso$Builder
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.RequestCreator
Warning:com.inmobi.ads.aj: can't find referenced class com.squareup.picasso.Picasso
尽管我的 proguard 规则工作室中有 -keep public class com.dropbox.** *;
,但我在 dropbox 的问题上总是碰壁。inmobi 课程也会发生同样的事情。有什么建议?
这是我的 proguard-rules 文件。
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Program Files (x86)\android\android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the javascript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview
# public *;
#
-keep public class com.dropbox.** *;
# Appodeal
-keep class com.appodeal.** *;
-keep class org.nexage.** *;
-keepattributes EnclosingMethod, InnerClasses, Signature, JavascriptInterface
# Amazon
-keep class com.amazon.** *;
-dontwarn com.amazon.**
# Mopub
-keep public class com.mopub.**
-keepclassmembers class com.mopub.** public *;
-keep class * extends com.mopub.mobileads.CustomEventBanner
-keep class * extends com.mopub.mobileads.CustomEventInterstitial
-keep class * extends com.mopub.nativeads.CustomEventNative
-keep class * extends com.mopub.mobileads.CustomEventRewardedVideo
-dontwarn com.mopub.volley.toolbox.**
# Applovin
-keep class com.applovin.** *;
-dontwarn com.applovin.**
# Facebook
-keep class com.facebook.ads.** *;
-dontwarn com.avocarrot.**
-keep class com.avocarrot.** *;
-keepclassmembers class com.avocarrot.** *;
-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*(...);
-dontwarn android.support.v7.**
-keep class android.support.v7.** *;
-keep interface android.support.v7.** *;
-keep public class com.google.android.gms.**
-dontwarn com.google.android.gms.**
-keep class butterknife.** *;
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder *;
-keepclasseswithmembernames class *
@butterknife.* <fields>;
-keepclasseswithmembernames class *
@butterknife.* <methods>;
# Appodeal
-keep class com.appodeal.** *;
-keep class org.nexage.** *;
-keepattributes EnclosingMethod, InnerClasses, Signature, JavascriptInterface
# Amazon
-keep class com.amazon.** *;
-dontwarn com.amazon.**
# Mopub
-keep public class com.mopub.**
-keepclassmembers class com.mopub.** public *;
-keep class * extends com.mopub.mobileads.CustomEventBanner
-keep class * extends com.mopub.mobileads.CustomEventInterstitial
-keep class * extends com.mopub.nativeads.CustomEventNative
-keep class * extends com.mopub.mobileads.CustomEventRewardedVideo
-dontwarn com.mopub.volley.toolbox.**
# Applovin
-keep class com.applovin.** *;
-dontwarn com.applovin.**
# Facebook
-keep class com.facebook.ads.** *;
-dontwarn com.facebook.ads.**
# Chartboost
-keep class com.chartboost.** *;
-dontwarn com.chartboost.**
# Unity Ads
-keepattributes JavascriptInterface
-keepattributes SourceFile,LineNumberTable
-keep class com.unity3d.** *;
# Yandex
-keep class com.yandex.metrica.** *;
-dontwarn com.yandex.metrica.**
-keep class com.yandex.mobile.ads.** *;
-dontwarn com.yandex.mobile.ads.**
-keepattributes *Annotation*
# StartApp
-keep class com.startapp.** *;
-dontwarn com.startapp.**
-keepattributes Exceptions, InnerClasses, Signature, Deprecated, SourceFile, LineNumberTable, *Annotation*, EnclosingMethod
# Flurry
-keep class com.flurry.** *;
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class *
public <init>(android.content.Context, android.util.AttributeSet, int);
# Avocarrot
-keep class com.avocarrot.** *;
-keepclassmembers class com.avocarrot.** *;
-dontwarn com.avocarrot.**
-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*(...);
# Adcolony
-keep class com.jirbo.adcolony.** *;
-keep class com.immersion.** *;
-dontnote com.immersion.**
-dontwarn android.webkit.**
-dontwarn com.jirbo.adcolony.**
# Vungle
-keep class com.vungle.** public *;
-keep class javax.inject.*
-keepattributes *Annotation*, Signature
-keep class dagger.*
-dontwarn com.vungle.**
# MyTarget
-keep class com.my.target.** *;
-dontwarn com.my.target.**
-keep class ru.mail.android.mytarget.** *;
-dontwarn ru.mail.android.mytarget.**
#Cheetah Mobile
-keep class com.cmcm.** *;
-dontwarn com.cmcm.**
# Tapjoy
-keep class com.tapjoy.** *;
-dontwarn com.tapjoy.**
# Revmob
-keep class com.revmob.** *;
-dontwarn com.revmob.**
# Admob
-keep class com.google.android.gms.ads.** *;
# Google
-keep class com.google.android.gms.common.GooglePlayServicesUtil *;
-keep class com.google.android.gms.ads.identifier.** *;
-dontwarn com.google.android.gms.**
# Legacy
-keep class org.apache.http.** *;
-dontwarn org.apache.http.**
-dontwarn android.net.http.**
# Google Play Services library
-keep class * extends java.util.ListResourceBundle
protected Object[][] getContents();
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable
public static final *** NULL;
-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable
public static final *** CREATOR;
-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class *
@android.support.annotation.Keep <fields>;
-keepclasseswithmembers class *
@android.support.annotation.Keep <methods>;
-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class *
@com.google.android.gms.common.annotation.KeepName *;
-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep public @com.google.android.gms.common.util.DynamiteApi class *
public <fields>;
public <methods>;
-keep class com.google.android.gms.common.GooglePlayServicesNotAvailableException *;
-keep class com.google.android.gms.common.GooglePlayServicesRepairableException *;
# Google Play Services library 9.0.0 only
-dontwarn android.security.NetworkSecurityPolicy
-keep public @com.google.android.gms.common.util.DynamiteApi class * *;
# support-v4
-keep class android.support.v4.app.Fragment *;
-keep class android.support.v4.app.FragmentActivity *;
-keep class android.support.v4.app.FragmentManager *;
-keep class android.support.v4.app.FragmentTransaction *;
-keep class android.support.v4.content.LocalBroadcastManager *;
-keep class android.support.v4.util.LruCache *;
-keep class android.support.v4.view.PagerAdapter *;
-keep class android.support.v4.view.ViewPager *;
-keep class android.support.v4.content.ContextCompat *;
# support-v7-recyclerview
-keep class android.support.v7.widget.RecyclerView *;
-keep class android.support.v7.widget.LinearLayoutManager *;
-dontwarn okio.**
-dontwarn okhttp3.**
-dontwarn com.google.appengine.**
-dontwarn javax.servlet.**
# Support classes for compatibility with older API versions
-dontwarn android.support.**
-dontnote android.support.**
-keep class org.** *;
-keep class com.inmobi.ads.** *;
-keep public class com.google.ads.** public protected *;
-keep public class com.inmobi.androidsdk.** public protected *;
-keep public class com.millenialmedia.android.** public protected *;
-keep public class com.mobclix.android.sdk.** public protected *;
-keep public class com.jumptap.adtag.** public protected *;
【问题讨论】:
投反对票的人愿意说出他们投反对票的原因吗? 【参考方案1】:在下方添加以忽略警告
-dontwarn com.dropbox.**
-dontwarn com.inmobi.**
【讨论】:
如果我这样做了,我只是没有收到错误警告......它不会让错误消失。以上是关于Android studio - Proguard 似乎忽略了规则,导致构建错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在android studio中启用proguard? [复制]
Android Studio & ProGuard:无法解析符号 getDefaultProguardFile?
Proguard 在 android Studio 中开箱即用?这是啥意思?
使用 Android Studio 签署 APK 时出现 Proguard 错误