Arkadii Ivanov
09/04/2023, 11:57 PMAdam Brown
09/05/2023, 6:47 PMJan
09/12/2023, 2:45 PMcom.arkivanov.essenty:parcelable be deprecated at some time & Decompose/Essenty will provide a new way to preserve state based on kotlinx.serialization?Arkadii Ivanov
09/12/2023, 3:09 PMcommonMain annotated with expect annotation class (like Parcelize). Then on androidMain we can have actual typealias Parcelize = kotlinx.parcelize.Parcelable, and apply kotlin-parcelize compiler plugin (which is partially frontend). The plugin is executed when android target is being compiled, and the plugin sees all the classes, including the ones in commonMain.
The new K2 compiler breaks this feature. The frontend compiles each source set only once, and uses the results as a dependency for other source sets. This means that commonMain is compiled only once, and since kotlin-parcelize is Android only, the Parcelable implementations are not generated. And so the compilation fails eventually.
This could be fixed in theory by moving all the code generation in kotlin-parcelize to the backend. But this would be a pretty big change that the responsible team from Google would have to do, and it would take time, and so on. E.g. my plugin parcelize-darwin is backend-only, and it works fine with K2.
This means that we have to migrate to something else, and kotlinx-serialization looks like a good option. It would also allow actual state preservation on all targets out of the box. The current plan is to deliver Essenty v1.3.0 and Decompose v2.2.0 with some Parcelable APIs deprecated and new serialization-based replacements. This would allow some time for migration. Then deliver Essenty v2.0.0 with parcelable module removed and state-keeper module fully based on kotlinx-serialization, plus Decompose v3.0.0 also fully-based on kotlinx-serialization.
This is a very unfortunate change, but I tried all my best to push the support in K2 and/or kotlin-parcelize. But to be honest, I chose Parcelize ~3 years ago mostly because kotlinx-serialization was not that good at that point of time. But it evolved nicely since then, and now looks pretty suitable for Decompose.