1

我正在尝试在 Kotlin Multiplatform 项目的 commonMain 模块中设置 ktor http 客户端(如此处所述https://ktor.io/clients/http-client/features/json-feature.html),但无法解析对它的依赖:

    val client = HttpClient {
        install(JsonFeature) {
            serializer = JacksonSerializer()
        }
    }

摇篮版本:4.7。

这是通用模块的 build.gradle:

apply plugin: 'kotlin-multiplatform'
apply plugin: 'kotlinx-serialization'

    kotlin {
        targets {
            // Change to `presets.iosArm64` to deploy the app to iPhone
            fromPreset(presets.iosX64, 'ios') {
                compilations.main.outputKinds('FRAMEWORK')
            }
        }
        sourceSets {
            commonMain.dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"

                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-json:$ktor_version"
                implementation "io.ktor:ktor-client-jackson:$ktor_version"
            }
            commonTest {
                dependencies {
                    implementation "org.jetbrains.kotlin:kotlin-test-common"
                    implementation "org.jetbrains.kotlin:kotlin-test-annotations-common"
                }
            }
            iosMain {
                dependencies {
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"

                    implementation "io.ktor:ktor-client-ios:$ktor_version"
                    implementation "io.ktor:ktor-client-core-ios:$ktor_version"
                    implementation "io.ktor:ktor-client-json-ios:$ktor_version"
                }
            }
        }
    }
4

1 回答 1

4

您不能在 ios 上使用 jackson,因为它是 JVM 特定的。在 ios 上只有 Kotlinx.serialization 有效。

于 2018-11-29T11:01:47.717 回答