如何使用针对LinuxX64的ktor-client-core修复'Unresolved reference:HttpClient' [英] How to fix 'Unresolved reference: HttpClient' with ktor-client-core targeting linuxX64
问题描述
第一步,我试图构建针对linuxX64的Kotlin Multiplatform命令行应用程序.因此,我想基于通用模块中使用的Ktor构建客户端.
I'm trying to build a Kotlin Multiplatform command line application targeting linuxX64 in a first step. Therefore I wanted to build a client based on Ktor which is used in the common module.
版本概述
- Ktor 1.1.5
- 科特林多平台1.3.31
- 5.3.1级
build.gradle.kts
plugins {
kotlin("multiplatform") version "1.3.31"
}
repositories {
mavenCentral()
maven { url = uri("https://kotlin.bintray.com/ktor") }
}
kotlin {
linuxX64("linux") {
binaries {
executable()
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
api("io.ktor:ktor-client-core:1.1.5")
}
}
val linuxMain by getting {
dependsOn(commonMain)
dependencies {
api("io.ktor:ktor-client-curl:1.1.5")
}
}
}
}
src/linuxMain/kotlin/Main.kt
fun main(){
val client = MyClient()
client.execute()
}
src/commonMain/kotlin/MyClient.kt
import io.ktor.client.*
class MyClient {
private val client = HttpClient()
fun execute() {
//do something with Ktor client
}
}
构建项目时,出现以下构建问题:
When I build the project I get the following build issue:
11:15:21: Executing task 'build'...
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :wrapper
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :compileKotlinLinux FAILED
e: .../src/commonMain/kotlin/MyClient.kt: (1, 8): Unresolved reference: io
e: .../src/commonMain/kotlin/MyClient.kt: (5, 26): Unresolved reference: HttpClient
我是Kotlin Native/Mutliplatform和Ktor的新手.所以,如果这是我的设置错误,请忍受...
I'm new to Kotlin Native/Mutliplatform and Ktor. So bear with me if this my setup is wrong...
推荐答案
在 settings.gradle.kts 中添加 enableFeaturePreview("GRADLE_METADATA")
可以解决构建问题.我刚刚使用ktor-client-curl用linuxX64二进制文件成功进行了HTTP调用:-)
Adding enableFeaturePreview("GRADLE_METADATA")
to settings.gradle.kts fixed the build issue.
I just made a successful HTTP call with a linuxX64 binary using ktor-client-curl :-)
这篇关于如何使用针对LinuxX64的ktor-client-core修复'Unresolved reference:HttpClient'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!