如何在Kotlin Native中使用Http Request库

时间:2019-01-08 08:13:00

标签: kotlin kotlin-native kotlin-multiplatform

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

1 个答案:

答案 0 :(得分:1)

我知道,如果您将class Validator { public: Validator(const std::string& name = "BaseValidator") : m_name(name) {}; // ... }; class RequiredValidator : public Validator { public: RequiredValidator() : Validator("RequiredValidator") {} // ... }; 降级到4.7,我确实在其他论坛上也读过有关该问题的文章,请解决。 我降级了gradle项目并解决了。