1

我的大脑被炸了。我搜索了 SO 寻求帮助,但似乎带有此异常的 Proguard 问题特定于相关应用程序。我一直在尝试使用 Proguard 来混淆/缩小我的应用程序,当我在 Generated APK 表单中运行它时,我的应用程序要么崩溃,要么让我遇到:

com.company.project E/a: java.lang.NoSuchMethodException: fromValue [int]

堆栈跟踪:

java.lang.AssertionError: java.lang.NoSuchMethodException: fromValue [int]
     at com.squareup.wire.RuntimeEnumAdapter.decode(Unknown Source)
     at com.squareup.wire.RuntimeEnumAdapter.getFromValueMethod(Unknown Source)
     at com.squareup.wire.RuntimeEnumAdapter.decode(Unknown Source)
     at com.company.project.utils.wiremodels.d.a(Unknown Source)
     at com.company.project.utils.wiremodels.d.decode(Unknown Source)
     at com.company.project.utils.wiremodels.g.a(Unknown Source)
     at com.company.project.utils.wiremodels.g.decode(Unknown Source)
     at com.squareup.wire.ProtoAdapter.decode(Unknown Source)
     at retrofit2.converter.wire.WireResponseBodyConverter.convert(Unknown Source)
     at retrofit2.converter.wire.WireResponseBodyConverter.convert(Unknown Source)
     at retrofit2.ServiceMethod.toResponse(Unknown Source)
     at retrofit2.OkHttpCall.parseResponse(Unknown Source)
     at retrofit2.OkHttpCall$1.onResponse(Unknown Source)
     at a.az.b(Unknown Source)
     at a.a.l.run(Unknown Source)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
     at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.NoSuchMethodException: fromValue [int]
     at java.lang.Class.getMethod(Class.java:624)
     at java.lang.Class.getMethod(Class.java:603)
    ... 18 more

我的应用使用了来自 Square 的 Retrofit (2.1.0) 和 Wire。然后,当我的应用程序崩溃时,我正在检查mapping.txt文件以查看导致问题的类(我相信是com.company.project.a,对吗?)

无论如何,这是我的 proguard 文件(带有模糊的类名 fyi):

-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keep class com.squareup.wire.** { *; }
-keep class com.company.project.utils.wiremodels.ProtoFile1 { *; }
-keep class com.company.project.utils.wiremodels.ProtoFile2 { *; }
-keep class com.company.project.utils.wiremodels.ProtoFile3 { *; }
-keep class com.company.project.utils.wiremodels.ProtoFile4 { *; }
-keep class com.company.project.utils.wiremodels.ProtoFile5 { *; }
-dontwarn com.google.**
-keepattributes Signature
-keepattributes *Annotation*
-keepattributes Exceptions
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn org.simpleframework.xml.stream.**

如果我能得到一些帮助,那就太棒了,如果我应该提供更多信息,请告诉我。

编辑:在标记答案的评论中回答的问题(供将来参考)

4

1 回答 1

1

您可以将方法保留在某些类中:

-keepclassmembers,allowobfuscation class com.company.project.yourClass.** {
    <methods>;
}

当您使用wire时,建议使用这些迹象proguard 是:

-keep class com.squareup.wire.** { *; }
-keep class com.yourcompany.yourgeneratedcode.** { *; }

如果问题来自retrofit 这里是一个proguard示例

-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**

-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions

# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
于 2016-07-16T03:38:46.637 回答