android - 编译 Kotlin 序列化时的错误
问题描述
我已经阅读了一些关于图书馆的文章,但发现它们的工作方式仍然是一个谜。
我想使用 Kotlin 序列化库,但是在查看了我需要做的事情后,编译时仍然会出现错误。 Json.encodeToString
并Json.decodeToString
显示为红色。
- 谁能指出我做错了什么。谢谢。(有很多东西要知道。)
以下是我在 gradles 中的内容
在应用程序级别的gradle中我有
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"
}
在我的项目 Gradle 中
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
}
这是错误
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
解决方案
推荐阅读
- scala - 如何使用我在 Spark Join 中创建的列?- 模棱两可的错误
- android - 如何使用 ContentResolver 为运行低于 API 29/AndroidQ 的设备保存图像?
- flutter - 只改变一个项目样式而不是每个人。正在更改所有 ListTile 而不是一个
- php - 包含php文件后,找不到它的js-script src
- sql - MS Access:匹配 Xrate 到日期
- python - Tesseract 搞乱数字和字符
- python - Python3无法建立连接socket.gaierror:名称或服务未知
- c# - 如何拆分包含许多属性的大型请求对象,其中一个是巨大的值列表
- typescript - Typescript - 从接口实现匿名对象
- node.js - 如何以及何时使用 http2