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.
- 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