In my project I need to use Kotlin.Serialization, so by documenting myself I saw how to import the plugin.
In the build.gradle(project)
here is the plugins
block.
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
id 'com.google.dagger.hilt.android' version '2.48.1' apply false
id 'androidx.navigation.safeargs' version '2.5.3' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.20'
}
In the build.gradle(app)
here is the plugins block:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
id 'com.google.dagger.hilt.android'
id 'org.jetbrains.kotlin.plugin.serialization'
}
And there I implement the following library:
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
The problem is, annotating the following class with @Serializable
like this:
@Serializable
data class User(
val name: String = "",
val surname: String = "",
val phone: String = "",
val email: String = "",
)
Android studio leaves me with this warning:
kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed.
I poked around StackOverflow and noticed that the code in the build.gradle
is correct, so I really wouldn't know how to fix this warning.
User
? – Slattery@Serializable
orid 'org.jetbrains.kotlin.plugin.serialization'
, the code stops working. So the plugin is definitely getting applied.MySerializable.serializer()
is missing, as you report, but I can writeval serializer = serializer<MySerializable>()
and that works. This function isn't generated, it's present inSerializers.kt
. I think this is a reasonable workaround. Or you may try to downgrade the plugin, since this seems like a bug. – Slattery.serializer()
in my code (instead, I'm usingkotlinx.serialization.json.Json
encode/decode methods). I just tried downgrading the plugin to 7 different older versions, with the exact same results. Maybe I just don't know which version to downgrade it to, or maybe something else is going on. – Broz