我是 Kotlin 本机的初学者,我的目标是构建一个我们的 Rest API 包含它的库,并在 iOS 和 Android 上使用它。我知道ktor
并在我的项目中实现了这一点,但是当我build
通过Gradle
获取异常运行项目时,我使用以下对象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"
}
}