【问题标题】:Android Proguard Can't Find Methods in android.app.ActivityAndroid Proguard 在 android.app.Activity 中找不到方法
【发布时间】:2017-02-12 07:08:50
【问题描述】:

生成签名的 APK 时出现以下 Proguard 错误。我已将 minifyEnabledshrinkResources 设置为 true

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.* {*;}

谢谢!

【问题讨论】:

  • 我们能看到progaurd规则吗?
  • 好的,刚刚添加到描述中
  • 好的,我刚刚发现出了什么问题。实际上与Proguard无关。我正在使用的库之一是引用更新版本的 AppCompat 库。我只是用 -dontwarn 标记了它,因为我确信这些成员不会在我的用例中使用。

标签: android proguard


【解决方案1】:

我开发了 Android aar 库,我们的客户在尝试将 proguard 应用到他的带有连接库的应用时遇到了同样的问题。在我们的案例中,问题与 AppCompat 库无关。
我们的客户有 compileSdkVersion 和 targetSdkVersion (23),比我们的库 (25) 还低。我们在库代码中使用的 Activity.isInMultiWindowMode() 方法在 Android API 23 中不存在,这是 Proguard 生成警告的原因。因此,我在库的 .pro 文件中添加了以下行:

-dontwarn android.app.Activity

@AlexVPerl 做了同样的事情,但我认为,当客户端应用程序的 compileSdkVersion 低于库中(至少几个单位)时,库作者有责任为这种情况准备库。

【讨论】:

    猜你喜欢
    • 2014-06-02
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多