电线+改造NoSuchMethodException的Proguard

时间:2016-07-16 03:21:16

标签: android proguard retrofit2 android-proguard square-wire

我的大脑被炸了。我搜索了S.O.寻求帮助但看起来这个例外的Proguard问题是针对相关应用程序的。我一直在尝试使用Proguard来篡改/缩小我的应用程序,当我在生成的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.**

如果我能得到一些帮助,那将是惊人的,请告诉我是否有更多我应该提供的信息。

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

1 个答案:

答案 0 :(得分:1)

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

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

当您使用wire时,建议使用these indications proguard形式:

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

如果问题来自retrofit here is a proguard example

-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