2020年2月26日水曜日

moshi-kotlin (1.9.2) の proguard 設定ではまった

moshi の proguard 設定は https://github.com/square/moshi#r8--proguard にあります。 この設定だけだと

java.lang.IllegalArgumentException: Cannot serialize Kotlin type XX. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapter from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.

というエラーが出て parse に失敗しました。

ちゃんと以下のように KotlinJsonAdapterFactory をセットしているので、関係ないエラー文言であり紛らわしいです。 val moshi = Moshi.Builder() .add(KotlinJsonAdapterFactory()) .build()

問題は moshi-kotlin を使うときに追加する proguard 設定にあります。
https://github.com/square/moshi/blob/master/kotlin/reflect/src/main/resources/META-INF/proguard/moshi-kotlin.pro
は 1.9.2 の時点で -keep class kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoaderImpl -keepclassmembers class kotlin.Metadata { public <methods>; } になっていますが、これを -keep class kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoaderImpl -keep class kotlin.Metadata { public <methods>; } にすれば正しく parse されるようになりました。


1 件のコメント:

  1. As reported by Stanford Medical, It's really the ONLY reason this country's women live 10 years more and weigh 42 pounds lighter than us.

    (And by the way, it has NOTHING to do with genetics or some secret-exercise and EVERYTHING to do with "how" they eat.)

    BTW, I said "HOW", and not "what"...

    Tap on this link to uncover if this easy test can help you decipher your true weight loss possibility

    返信削除