Kotlin 如何修复';未解析的引用:HttpClient';ktor客户端核心以Linux64为目标
我正试图在第一步中构建一个以Linux64为目标的Kotlin多平台命令行应用程序。因此,我想基于在公共模块中使用的Ktor构建一个客户机 下面是我的简单设置: 版本概述Kotlin 如何修复';未解析的引用:HttpClient';ktor客户端核心以Linux64为目标,kotlin,ktor,kotlin-multiplatform,Kotlin,Ktor,Kotlin Multiplatform,我正试图在第一步中构建一个以Linux64为目标的Kotlin多平台命令行应用程序。因此,我想基于在公共模块中使用的Ktor构建一个客户机 下面是我的简单设置: 版本概述 Ktor 1.1.5 Kotlin多平台1.3.31 梯度5.3.1 build.gradle.kts plugins { kotlin("multiplatform") version "1.3.31" } repositories { mavenCentral() maven { url =
- Ktor 1.1.5
- Kotlin多平台1.3.31
- 梯度5.3.1
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()
}
import io.ktor.client.*
class MyClient {
private val client = HttpClient()
fun execute() {
//do something with Ktor client
}
}
src/commonMain/kotlin/MyClient.kt
fun main(){
val client = MyClient()
client.execute()
}
import io.ktor.client.*
class MyClient {
private val client = HttpClient()
fun execute() {
//do something with Ktor client
}
}
构建项目时,我会遇到以下构建问题:
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/Mutlipplatform和Ktor的新手。如果我的设置有误,请耐心等待。将
启用功能预览(“GRADLE\u元数据”)
添加到设置中。GRADLE.kts修复了构建问题。
我刚刚使用ktor client curl:-)使用Linux64二进制文件成功地进行了HTTP调用。将
enableFeaturePreview(“GRADLE\u元数据”)
添加到settings.GRADLE.kts修复了构建问题。我刚刚使用ktor curl客户机成功地使用Linux64二进制文件进行了HTTP调用:-)