Unresolved reference: Parcelable Kotlin

Viewed 606

I want to use safeArgs to send an object from a fragment to another one but Parcelable is not working even with me adding the necessary plugin. Can somebody please help me? the model class


import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class GazModel(
    val id: String,
    val name: String,
    val description: String?,
    val price : Double,
    val priority: Int,
    val weight : Double,
    val imageUrl : String?,
    var quantity : Int = 0,
    var selected: Boolean = false,
    val gazType: String, // TRADEX, TOTAL, CAMGAZ
) :  Parcelable{}

build.gradle.kts (Project)

 dependencies {
        //...
        val nav_version = "2.3.5"
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
    }

build.gradle.kts (Module)

plugins {
 //...
    id("androidx.navigation.safeargs.kotlin")
    id ("kotlin-parcelize")
}

the problem that appear in the problem box

Unresolved reference: os
No 'Parcelable' supertype
Unresolved reference: Parcelable
2 Answers

In the build.gradle (Module), add an id('kotlin-android-extensions') instead of the id ("kotlin-parcelize"), just it !

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

Try this

@Parcelize
data class GazModel(
    val id: String,
    val name: String,
    val description: String?,
    val price : Double,
    val priority: Int,
    val weight : Double,
    val imageUrl : String?,
    var quantity : Int = 0,
    var selected: Boolean = false,
    val gazType: String, // TRADEX, TOTAL, CAMGAZ
) :  Parcelable

I mean extend with Parcelable not Parcelable{} Hope this fixes the issue

Related