Can't find ScalaSig for class - json4s with sc

2019-08-06 09:52发布

I have a very simple case class (Baz) that I want to serialise to JSON using json4s-native. I cannot seem to get this to work at all, when using Proguard to make an android apk.

When serialising, the following exception occurs:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: org.json4s.package$MappingException: Can't find ScalaSig for class foo.bar.Baz
    at org.json4s.reflect.ScalaSigReader$.findClass(ScalaSigReader.scala:42)
    at org.json4s.reflect.ScalaSigReader$.org$json4s$reflect$ScalaSigReader$$read$1(ScalaSigReader.scala:36)
    at org.json4s.reflect.ScalaSigReader$.readField(ScalaSigReader.scala:38)

My proguard config contains:

-keepclassmembers class * { ** MODULE$; }
-dontoptimize
-dontobfuscate
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

Things work as expected when running test cases against actual code, but after the proguard step, this problem always occurs.

Any help?

Cheers.

1条回答
相关推荐>>
2楼-- · 2019-08-06 10:10

maybe this helps:

"Only top level objects or objects defined directly in an object are supported" by json4s. For example classes defined inside a def don't work. I assume Proguard changes the code structure.

(sorry I can't comment)

查看更多
登录 后发表回答