Mitch Ware
06/08/2022, 8:00 PMkotlin-parcelize
plugin and how best to use it in a modularized project setup:
In an effort to modularize a monolithic Android app module, step 1 (ideally) is to extract common model classes into standalone modules for re-use.
Based on the project setup, we want these new modules to be plain JVM modules (no com.android.library
plugin).
This becomes problematic if any of the model classes are Parcelable
and utilize the parcelize plugin - kotlin-parcelize
can't run in a module without applying the com.android.library
plugin.
Any recommendations on how to work around this? I can come up with two options myself, but neither one is necessarily ideal; I'm curious if anyone has other ideas or recommendations?
1. Make the common model not Parcelable, create a new Parcelize-specific model class local to the app module, and convert back and forth between the two.
2. Persist the data a different way, or use a different serialization strategy, and remove the @Parcelize
annotation on those common models.ephemient
06/08/2022, 8:23 PM// commonMain
@OptionalExpectation
annotation class AndroidParcelable
@AndroidParcelable
data class Data(...)
// androidMain
actual typealias AndroidParcelable = Parcelable
I haven't tried this and it might not work, but it may be worth a shotMitch Ware
06/08/2022, 8:54 PMephemient
06/08/2022, 9:00 PM@Serializable
to `@TypeParceler`/`@WriteWith`, but never ended up using it in the project it was built for, so it's also untested.
https://gist.github.com/ephemient/65a3ee700f020661858c89b5648a2772Mitch Ware
06/08/2022, 9:55 PMkenkyee
06/08/2022, 10:20 PMkenkyee
06/08/2022, 10:20 PMRobert Williams
06/09/2022, 8:40 AMmodularize a monolithic Android app
, just making a separate Android module using the com.android.library plugin may be the best optionRobert Williams
06/09/2022, 8:41 AMRobert Williams
06/09/2022, 8:41 AM