我是Kotlin Native的初学者,我的目标是构建一个包含我们Rest APIs的库,并在iOS和Android上使用它。
我知道ktor
并在我的项目中实现了它,但是当我用Gradle
运行build
项目时,出现了一个异常,在我使用kotr
对象的位置:
> Task :apiCore:androidProcessResources NO-SOURCE
> Task :apiCore:compileKotlinAndroid UP-TO-DATE
> Task :apiCore:androidMainClasses UP-TO-DATE
> Task :apiCore:androidJar UP-TO-DATE
> Task :apiCore:compileKotlinIOS
src/commonMain/kotlin/APICore.kt:3:8: error: unresolved reference: io
import io.ktor.client.HttpClient
^
src/commonMain/kotlin/APICore.kt:4:8: error: unresolved reference: io
import io.ktor.client.request.get
^
src/commonMain/kotlin/APICore.kt:10:17: error: unresolved reference:
HttpClient
val client = HttpClient()
^
Execution failed for task ':apiCore:compileKotlinIOS'.
> Process 'command '/Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with
non-zero exit value 1
我的多平台模块使用的是Gradle
:
sourceSets {
commonMain.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
implementation("io.ktor:ktor-client-core:1.1.1")
}
androidMain.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib'
implementation ("io.ktor:ktor-client-android:1.1.1")
}
iosMain.dependencies{
implementation "io.ktor:ktor-client-ios:1.1.1"
}
}