gpt4 book ai didi

android - 编译 Kotlin 序列化时出错

转载 作者:行者123 更新时间:2023-12-04 15:06:42 27 4
gpt4 key购买 nike

我已经阅读了一些关于库的文章,但发现它们的工作原理仍然是个谜。

我想使用 Kotlin 序列化库,但在查看了我需要做什么之后,在编译时仍然出现错误。 Json.encodeToStringJson.decodeToString 显示红色。

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

  • 谁能指出我做错了什么。谢谢。 (要知道的太多了。)

下面是我在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

最佳答案

kotlin_version 的替换似乎有问题.线路:

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

神器应该是org.jetbrains.kotlinx:kotlinx-serialization-json:<version> .确保在您的 gradle.properties 中正确定义属性文件或其他地方(或不使用属性)。另请注意,序列化模块不跟踪 Kotlin 版本号,它使用不同的版本号。最新版本号为:Download

关于android - 编译 Kotlin 序列化时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65982688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com