I'd like to create a class in a multi-platform project, and use Parcelize
to make it Parcelable
in the Android version.
So in my lib-common
project, I tried:
expect annotation class Parcelize()
expect interface Parcelable
@Parcelize
data class Foo(x: Int): Parcelable
and in my lib-android
project:
actual typealias Parcelize = kotlinx.android.parcel.Parcelize
actual typealias Parcelable = android.os.Parcelable
The first problem was that the Gradle plugin kotlin-android-extensions
didn't seem to take in lib-android
's build.gradle
, so the package kotlinx.android.parcel
was not found. I managed to work around that by just importing the library directly:
implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"
With this, the actual
definition of Parcelable
compiles.
However, I am getting an error from the definition of Foo
, as if it was not properly annotated with @Parcelize
:
Class
Foo
is not abstract and does not implement abstract memberpublic abstract fun writeToParcel(p0: Parcel!, p1: Int): Unit
defined inandroid.os.Parcelable