Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.37k stars 620 forks source link

Compilation error with R8 8.5.xx and compose type safe navigation #2825

Open Beb3r opened 22 hours ago

Beb3r commented 22 hours ago

When using compose navigation type safe and switching to R8 tool version 8.5.xx (8.5.10/8.5.27/8.5.35) compilation fails

Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied. at kotlinx.serialization.SerializationException.(SerializationException.java:49) at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform_common.kt:91) at kotlinx.serialization.SerializersKtSerializersKt.serializer(SerializersKtSerializers.kt:278) at kotlinx.serialization.SerializersKt.serializer(Serializers.kt:1) at androidx.navigation.NavDestinationBuilder.(NavDestinationBuilder.kt:91) at androidx.navigation.compose.ComposeNavigatorDestinationBuilder.(ComposeNavigatorDestinationBuilder.kt:95)

When falling back to R8 8.3.xx (8.3.37/8.3.36), compilation doesn't fail.

Environment

Is there some new proguard rules to add ?

sandwwraith commented 19 hours ago

This looks like R8 issue. Have you tried reporting this to Google's issue tracker?

Beb3r commented 18 hours ago

Good point! Just did https://issuetracker.google.com/issues/371227633

Beb3r commented 12 hours ago

Adding the @Keep annotation on routes fixed the issue (Navigation safe type relies on serialization, but since they're not referenced at runtime, R8 strips them away)