R8 and Moshi-sealed crash #686
-
Hello,
As you can see, moshi-sealed is used inside normal moshi json adapters. When running the app version with r8 I get this error: Caused by: java.lang.ClassCastException: $Proxy7 cannot be cast to kotlin.metadata.jvm.b
at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactoryKt.b(MetadataMoshiSealedJsonAdapterFactory.kt:13)
at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactoryKt.access$header(MetadataMoshiSealedJsonAdapterFactory.kt)
at dev.zacsweers.moshix.sealed.reflect.MetadataMoshiSealedJsonAdapterFactory.create(MetadataMoshiSealedJsonAdapterFactory.java)
at com.squareup.moshi.Moshi.adapter(Moshi.java) We use the MetadataMoshiSealedJsonAdapterFactory. In build.gradle we have:
In proguard, I have added:
And we still have the error happening. I was wondering what am I missing in the proguard configuration. Any help is appreciated, thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 2 replies
-
Reproducible sample app https://drive.google.com/file/d/1diXfz14LWNIR7F_DbEFqHb3fm9M94_Dx/view?usp=sharing I managed to fix the issue by manually adding the PolymorphicJsonAdapter to the moshi instance:
|
Beta Was this translation helpful? Give feedback.
-
Got it working by using the following pro-guard configuration:
|
Beta Was this translation helpful? Give feedback.
-
Those rules are bundled with kotlin-reflect's jar. Please file an issue with the kotlin issue tracker if those are not being properly bundled? |
Beta Was this translation helpful? Give feedback.
-
Will do that, thank you 👍 |
Beta Was this translation helpful? Give feedback.
-
I am still struggling to understand where the issue lies exactly. The guys from R8 are telling me that I have practically disabled R8 optimisation for all kotlin files by using the above 😄 I have raised a YouTrack issue and one in the IssueTracker but just wanted to confirm, why is MetadataJsonFactory executed if I have already annotated my sealed class (as per the example from the project above) with the generator property and have added type labels. Doesn't that mean that they are not recognized and MetadataJsonFactory now uses reflection to recognize the classes while I shouldn't reach reflection at all? |
Beta Was this translation helpful? Give feedback.
-
Sorry are you saying you are trying to use code gen? All of your information up to this point seemed to imply you were intentionally trying to configure reflective use. Converting this to a discussion now as this appears to be more of a usage question than anything |
Beta Was this translation helpful? Give feedback.
-
After looking further, this looks like an R8 issue. It is tracked here: https://issuetracker.google.com/378473616. |
Beta Was this translation helpful? Give feedback.
-
R8 fix is in, see https://issuetracker.google.com/378473616#comment17 for which versions to use. |
Beta Was this translation helpful? Give feedback.
After looking further, this looks like an R8 issue. It is tracked here: https://issuetracker.google.com/378473616.