How to use Http Request lib in Kotlin Native
Asked Answered
E

1

6

I'm beginner in Kotlin native and my objective is build a lib that our Rest APIs include it and I use it on iOS and Android. I knew ktor and implemented this in my project but when I run build project by Gradle get exception where I use objects of 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

and my Gradle for multiplatform module:

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"
    }
}
Ezraezri answered 8/1, 2019 at 8:12 Comment(0)
E
3

I see, I did read about issue in other forums, if you downgrade gradle to 4.7 this issue be solve. I downgraded gradle of project and solved.

Ezraezri answered 15/1, 2019 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.