2017-02-12 60 views
0

生成签名的APK时,出现以下Proguard错误。我有minifyEnabled & shrinkResources设置为真正Android Proguard在android.app.Activity中找不到方法

can't find referenced method 'void onMultiWindowModeChanged(boolean)' in library class android.app.Activity 
can't find referenced method 'boolean isInMultiWindowMode()' in library class android.app.Activity 

我想保持minifyEnabled shrinkResources进行生产。

我需要在我的proguard-rules中添加什么以保持上面的成员并摆脱错误?

这里是我的长篇Proguard的规则文件:

#-dontobfuscate 

#-optimizations !code/simplification/arithmetic 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable 
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/simplification/cast 
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/simplification/cast 


-optimizationpasses 5 

-dontpreverify 

#-allowaccessmodification 

-dontskipnonpubliclibraryclasses 
-adaptresourcefilenames 
-adaptresourcefilecontents 
-flattenpackagehierarchy 


-dontwarn org.jdom2.** 
-dontwarn org.apache.** 
-dontwarn org.google.common.collect.** 
-dontwarn com.google.common.** 


#-keep class * implements java.io.Serializable 
-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.BackupAgentHelper 
-keep public class * extends android.preference.Preference 
-keep public class com.android.vending.licensing.ILicensingService 
-keep public class android.widget.ProgressBar 
-keepclasseswithmembernames class * { 
    native <methods>; 
} 
-keepclasseswithmembernames class * { 
    public <init>(android.content.Context, android.util.AttributeSet); 
} 
-keepclasseswithmembernames class * { 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
} 
-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 
-keep class * implements android.os.Parcelable { 
    public static final android.os.Parcelable$Creator *; 
} 


# ------------------------------------------ 
# Crashlytics 
# ------------------------------------------ 
-keepattributes *Annotation* 
#-keepattributes SourceFile,LineNumberTable 
-keepattributes LineNumberTable 
-keep public class * extends java.lang.Exception 
-keep class com.crashlytics.** { *; } 
-dontwarn com.crashlytics.** 


-dontwarn com.viewpagerindicator.LinePageIndicator 


# ------------------------------------------ 
# RETROFIT config 
# ------------------------------------------ 
-dontwarn retrofit.** 
-keep class retrofit.** { *; } 
-keepattributes Signature 
-keepattributes Exceptions 
-dontwarn retrofit2.** 
-keep class retrofit2.** { *; } 


# ------------------------------------------ 
# FABRIC TWITTER config 
# ------------------------------------------ 
-dontwarn com.squareup.okhttp.** 
-dontwarn com.google.appengine.api.urlfetch.** 
-dontwarn rx.** 
-dontwarn retrofit.** 
-keepattributes Signature 
-keepattributes *Annotation* 
-keep class com.squareup.okhttp.** { *; } 
-keep interface com.squareup.okhttp.** { *; } 
-keep class retrofit.** { *; } 
#-keepclasseswithmembers class * { 
# @retrofit.http.* <methods>; 
#} 


# ------------------------------------------ 
# OKIO config 
# ------------------------------------------ 
-dontwarn okio.** 
-keep class okio.** { *; } 



# ------------------------------------------ 
# InMobi config 
# ------------------------------------------ 
-keep class android.app.Activity 
-keep class android.app.Activity.** 

-keepattributes SourceFile,LineNumberTable 
-keep class com.inmobi.** { *; } 
-keep public class com.google.android.gms.** 
-dontwarn com.google.android.gms.** 
-dontwarn com.squareup.picasso.** 
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{ 
    public *; 
} 
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{ 
    public *; 
} 
# skip the Picasso library classes 
-keep class com.squareup.picasso.** {*;} 
-dontwarn com.squareup.picasso.** 
-dontwarn com.squareup.okhttp.** 
# skip Moat classes 
-keep class com.moat.** {*;} 
-dontwarn com.moat.** 
# skip AVID classes 
-keep class com.integralads.avid.library.* {*;} 

谢谢!

+0

我们可以看到'progaurd'规则吗? – pRaNaY

+0

当然,只是添加到描述 – AlexVPerl

+1

好吧,我刚刚发现什么是错的。实际上与Proguard无关。我正在使用的一个库引用了更新版本的AppCompat库。我只是用-dontwarn标出来,因为我确信那些成员不会用在我的用例中。 – AlexVPerl

回答

0

我开发Android aar库和我们的客户有同样的问题,当他试图将proguard应用程序与连接的库。在我们的案例中,问题与AppCompat库无关。
我们的客户有compileSdkVersion和targetSdkVersion(23),这比我们的库(25)低。我们在库代码中使用的Activity.isInMultiWindowMode()方法在Android API 23中不存在,这是Proguard生成警告的原因。其结果是,我已经添加了下面一行到我的图书馆的.pro文件:

-dontwarn android.app.Activity 

@AlexVPerl做同样的事情,但我认为,这是库的作者有责任为案件做准备库,当客户端应用程序的compileSdkVersion低于库中(至少多个单元)。

相关问题