6

I have read a fair bit on the libraries but find that how they work still remains a mystery.

I want to use the Kotlin serialization libraries but having looked at what I need to do still end up with errors when I compile. Json.encodeToString and Json.decodeToString are showing red.

https://medium.com/better-programming/why-and-how-to-use-kotlins-native-serialization-library-c88c0f14f93d

  • Can anyone point out what I am doing wrong. Thanks. (There is so much to know.)

The following is what I have in the gradles

In the app level gradle I have

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlinx-serialization'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_version"
}

In the project Gradle I have

dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

This is the error

Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find org.jetbrains.kotlinx:kotlinx-serialization-json:extension 'kotlin'-version.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json/extension 'kotlin'-version/kotlinx-serialization-json-extension 'kotlin'-version.pom
       - https://jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-serialization-json/extension 'kotlin'-version/kotlinx-serialization-json-extension 'kotlin'-version.pom
     Required by:
         project :app

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

1 Answer 1

4

It seems there's an issue with the replacement of kotlin_version. The line:

Could not find org.jetbrains.kotlinx:kotlinx-serialization-json:extension 'kotlin'-version.

The artifact should be org.jetbrains.kotlinx:kotlinx-serialization-json:<version>. Make sure that property is defined properly, either in your gradle.properties file or somewhere else (or don't use a property). Also note that the serialization module doesn't track the Kotlin version number, it uses a different one. The latest version number is: Download

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent, I did have problems on route but, courtesy of your answer, I have a better understanding of how the libraries work and where to find the files. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.