There has been a lot of changes recently with the release of the stable version. As stated in the release notes:
Jsonconstructor is replaced withJson {}builder function,JsonConfigurationis deprecated in favor ofJson {}builder
Your tutorial is outdated. I suggest you read the official docs instead.
As for dependencies, runtime was renamed to json in 1.0.0. You should have all of these:
// build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion"
}
}
// app/build.gradle
plugins {
id "org.jetbrains.kotlin.plugin.serialization"
}
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion"
}
Answer from Nicolas on Stack OverflowThere has been a lot of changes recently with the release of the stable version. As stated in the release notes:
Jsonconstructor is replaced withJson {}builder function,JsonConfigurationis deprecated in favor ofJson {}builder
Your tutorial is outdated. I suggest you read the official docs instead.
As for dependencies, runtime was renamed to json in 1.0.0. You should have all of these:
// build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion"
}
}
// app/build.gradle
plugins {
id "org.jetbrains.kotlin.plugin.serialization"
}
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion"
}
Go to your project-level build.gradle, under plugins add
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...........
...........
id "org.jetbrains.kotlin.plugin.serialization" version "1.7.10"
}
Go to your app level build-gradle, and add
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
.......
.......
id 'org.jetbrains.kotlin.plugin.serialization'
}
in the sane app-level build-Gradle then add,
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0"
I was able to resolve the warning "kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project." by adding the serialization plugin in the project-level build.gradle.kts, and then applying it in the module-level build.gradle.kts.
Project build.gradle.kts:
plugins {
...
kotlin("plugin.serialization") version "1.9.0" apply false
}
Module build.gradle.kts:
plugins {
...
kotlin("plugin.serialization")
}
...
dependencies {
...
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
}
After commenting out
id 'org.jetbrains.kotlin.jvm' version '1.9.22' apply false
from project.gradle, its worked for me and can also able to call
SomeClassName.serializer()
build.gradle (project)
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.8.20' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'}
build.gradle (app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlinx-serialization'
id 'org.jetbrains.kotlin.plugin.serialization'}
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1'}