Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Http Request lib in Kotlin Native

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"
    }
}
like image 573
ImanX Avatar asked Oct 17 '22 08:10

ImanX


1 Answers

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.

like image 62
ImanX Avatar answered Dec 04 '22 14:12

ImanX