5

我是 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"
    }
}
4

1 回答 1

3

我明白了,我确实在其他论坛上阅读过有关问题,如果您降级gradle到 4.7,此问题将得到解决。我降级了项目的等级并解决了。

于 2019-01-15T08:10:22.583 回答