does anyone have any luck setting up the `@Parceli...
# android
l
does anyone have any luck setting up the
@Parcelize
annotation on a class https://android.jlelse.eu/yet-another-awesome-kotlin-feature-parcelize-5439718ba220 i tried this but it doesnt recognize the import .
Copy code
import kotlinx.android.parcel.Parcelize
and i did a gradle sync after adding
Copy code
android{
  androidExtensions {
    experimental = true
  }
}
a
Yeah, use it all the time, I don't remember needing experimental but I think there is minimum kotlin version required , I am using the 1.3.60 version, try checking if you have the latest
l
im on kotlin
Copy code
1.3.61
so thats not the issue
ive spent hours trying to sort this issue out
a
Did you try building ?
l
yep
i ended up just implementing the parcelable interface the old way
a
I mean launching the app, I had this lint issue where it was highlighted and then run as expected
l
Copy code
sealed class DifficultyLevel(
        val columnCount: Int,
        val rowCount: Int,
        val flagsCount: Int,
        val minesCount: Int) : Parcelable {
    class Easy() : DifficultyLevel(10, 10, 10, 10) {
        constructor(parcel: Parcel) : this()

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            super.writeToParcel(parcel, flags)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<Easy> {
            override fun createFromParcel(parcel: Parcel): Easy {
                return Easy(parcel)
            }

            override fun newArray(size: Int): Array<Easy?> {
                return arrayOfNulls(size)
            }
        }
    }

    class Medium() : DifficultyLevel(13, 13, 23, 23) {
        constructor(parcel: Parcel) : this() {
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            super.writeToParcel(parcel, flags)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<Medium> {
            override fun createFromParcel(parcel: Parcel): Medium {
                return Medium(parcel)
            }

            override fun newArray(size: Int): Array<Medium?> {
                return arrayOfNulls(size)
            }
        }
    }

    class Hard() : DifficultyLevel(16, 16, 69, 69) {
        constructor(parcel: Parcel) : this() {
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            super.writeToParcel(parcel, flags)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<Hard> {
            override fun createFromParcel(parcel: Parcel): Hard {
                return Hard(parcel)
            }

            override fun newArray(size: Int): Array<Hard?> {
                return arrayOfNulls(size)
            }
        }
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(columnCount)
        parcel.writeInt(rowCount)
        parcel.writeInt(flagsCount)
        parcel.writeInt(minesCount)
    }
}
yes i just tried running the app
Screen Shot 2020-02-15 at 7.35.44 PM.png
i’ve add this to the top of my app
build.gradle
file
Copy code
apply plugin: 'kotlin-android-extensions'
and i added this
Copy code
androidExtensions {
    experimental = true
}
Screen Shot 2020-02-15 at 7.39.20 PM.png
see … it cannot resolve this annotation
there must be something else you need to set up to make this work
a
Did you add both of these apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android'
l
yes i did
i invalidated cache and restarted android studio, but no luck with that either
looks like someone had a similar issue here https://youtrack.jetbrains.com/issue/KT-22213
so i figured it out this is the correct order for the plugins
Copy code
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
i had it in reverse which is why it wasnt working
👍 5
a
Actually they are in reverse on the official docs how to include kotlin into existing Android project
l
thats a bummer that the docs have it all wrong. i hope they update that.