Which dependencies for serialization should I use?

Viewed 715

I want to do this manual. There's a link to install dependencies, but gradle's mad because of these dependencies. It doesn't want version numbers there. When I remove them It can't find plugins in sources. Then I find another manual. For this I should add some classpath to "project-level" gradle. When I do that my gradle syncs, but there are conflicts with implementations. For one manual I should add this

implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0"

For another this one

implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"

Whem I use one of them my projects can't use Json keyword, but when I use different one I can't use JsonConfiguration. Together it doesn't compile.

There are many words I wrote, sorry for that. Just give me normal dependencies for groovy gradle.

2 Answers

There has been a lot of changes recently with the release of the stable version. As stated in the release notes:

Json constructor is replaced with Json {} builder function, JsonConfiguration is deprecated in favor of Json {} 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"
Related