Genson with Android - Proguard config

限于喜欢 提交于 2019-12-11 07:39:37

问题


I have a problem with proguard config in Android Project. I'm using Genson to parse incoming JSON data. It is fast and there is no need for extra configuration or deserializers, because on the Server-side there is also Genson.

Everything works fine in debug mode, but in release, with proguard it doesn't.

Unfortunately I have some error during runtime:

FATAL EXCEPTION: main
Process: com.es.mobile.meedy, PID: 16650
java.lang.UnsupportedOperationException: Couldn't find parameter at 0 from type interface com.owlike.genson.Converter , you should first locate the parameterized type, expand it and then use typeOf.
    at com.owlike.genson.reflect.TypeUtil.typeOf(Unknown Source)
    at com.owlike.genson.GensonBuilder.withConverters(Unknown Source)
    at com.mypackage.f.k.a(Unknown Source)
    at com.a.a.b.n.a(Unknown Source)
    at com.a.a.i.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5086)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)

It happens even if datamodel is in keep class. I tried all configrations with keep class, classmembers, etc. What else can i do?

EDIT

What else do I know:

  • I tried keep class with all classes in my project.
  • I have keep class with genson (-keep class com.owlike.genson.** { *; })
  • Instanceof with my class shows that it is instance of com.owlike.genson.Converter

回答1:


The solution to the problem was to add -keepattributes Signature

If annotations are being used then this option should be enabled too -keepattributes *Annotation*

Also the application class being ser/de by Genson must also be provided: -keep class com.mypackage.model.** { *; }




回答2:


-keep class com.owlike.genson.*{ *; }  

Add that line to your ProGuard configuration.

-keep [,modifier,...] class_specification
Specifies classes and class members (fields and methods) to be preserved as entry points to your code. For example, in order to keep an application, you can specify the main class along with its main method. In order to process a library, you should specify all publicly accessible elements.



来源:https://stackoverflow.com/questions/27362851/genson-with-android-proguard-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!