I am building an app using type safe navigation.
Destinations
@Serializable
data object OwnerGraph {
@Serializable
data object HistoryGraph {
@Serializable
data object HistoryScreen
}
}
The Navigation graph:
fun NavGraphBuilder.historyScreenOwnerNavGraph() {
navigation<OwnerGraph.HistoryGraph>(
startDestination = OwnerGraph.HistoryGraph.HistoryScreen
) {
composable<OwnerGraph.HistoryGraph.HistoryScreen> { navBackStackEntry ->
val navHostController = LocalNavHostContoller.current
Text("History Screen")
}
}
}
The Navhost
NavHost(
navController = navController,
startDestination = startingNavigationGraph,
modifier = Modifier
.padding(paddingValues)
.consumeWindowInsets(paddingValues)
) {
historyScreenOwnerNavGraph()
}
And when I run the app I get this error:
kotlinx.serialization.SerializationException: Serializer for class 'OwnerGraph$HistoryGraph' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
But I applied the plugin and added the corresponding library.
And what is wierd is this is just a cut out of my whole codebase.
I use this structuring elswhere as well and there is not a crash like this.
But all of a sudden it has problem with this particularly one.
I would like to imagine this structure for the Type safe graph of mine which makes it more understandable.
Note: The crash only happens when I run the app with R8 enabled and in release build
Update: I am decompiling the classes and I found that the declaredFields
is empty and INSTANCE
is missing : No such static field 'INSTANCE'
While other cases the INSTANCE
is there and I did the same thing
Missing fields:
Update: If I add the @Keep annotation it start working again
Make sure you imported from @kotlinx.serialization.Serializable and properly setup plugin in build.gradle,
Module:
id(“org.jetbrains.kotlin.plugin.serialization”) version “1.7.10” apply false
App:
id(“org.jetbrains.kotlin.plugin.serialization”)
Then try the start destination as, startDestination = OwnerGraph.HistoryGraph
1