Hi All,
I am very new to Kotlin Native and I’m trying to build a very simple HTTP client as a PoC. The idea is that I create a native executable with the same source that can be run on the Mac and Linux, and maybe in the future JVM / Node or other platforms.
I was able to make it work as a simple “hello world” and built targets successfully.
Then I tried adding Ktor as an HTTP client and there the fun began.
import io.ktor.client.HttpClient
fun main() {
val c = HttpClient()
println( "HTTP client created" )
}
Idea marks the import as correct (no squiggly red line), but when I build I get;
.../Main.kt: (3, 8): Unresolved reference: io
.../Main.kt: (11, 13): Unresolved reference: HttpClient
Like the library does not exist.
I guess my issues come from build.gradle, where the “kotlin” stanza is:
kotlin {
macosX64("mac") {
binaries {
executable {
entryPoint = 'knativedemo.main'
runTask?.args('')
}
}
}
linuxX64("linux") {
binaries {
executable {
entryPoint = 'knativedemo.main'
runTask?.args('')
}
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
macMain {
dependencies {
implementation "io.ktor:ktor-client-core-macosx64:$ktor_version"
implementation "io.ktor:ktor-client-curl:$ktor_version"
}
}
linuxMain {
dependencies {
implementation "io.ktor:ktor-client-core-linuxx64:$ktor_version"
implementation "io.ktor:ktor-client-curl:$ktor_version"
}
}
}
But what is wrong with it?
Any help appreciated.
Full project sources at: GitHub - l3nz/kotlin-native-example: A small example of a Kotlin Native project