Multiplatform Project: iOS and Android cannot import ktor in SharedCode module

I’m following this https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html
Its about Multiplatform Project: iOS and Android

In side the SharedCode module, I’m not able to import java.
In the app module, I’m able to import java. The JDK location had been provided in project structure, shown in screenshot below. What am I missing?
10%20PM
17%20PM

You cannot use Java code inside the iOS source set (iosMain), the only place where you could use Java code (in your case) is in the Android source set (androidMain), everywhere else you can only use Kotlin

I’m trying test a http request.
URL provided here URL - Kotlin Programming Language
It doesn’t allow me to add dependencies in the SharedCode Build.gradle.
Any workaround so the iosMain can have more functions to use?

58%20PM

That class is only available for JavaScript targets.

If you want to use something in iOS you need to look for classes that are available either in Common or in Native (blue dot or purple dot respectively)

Now, for making HTTP requests you could use Ktor (https://ktor.io/clients/index.html)

Following this example:
https://ktor.io/clients/http-client/multiplatform.html
I have added the suggested implementation to Build.gradle for SharedCode… Only the one for Android works.
Import io.ktor in the android main is ok.
For common and iosMain does not work. Please see screenshots.

10%20PM

I found these examples GitHub - ktorio/ktor-samples: Sample projects for Ktor but there is no example showing what I’m trying to do.

:thinking: Now I don’t really know why it isn’t working.

Hello @shophk If you target is doing a http request I recomend to you don’t use a actual class on iOS, instead of this you Can make the request on a common class with ktor that can work for both platforms.
However if you can doing on iOS you import the ktor implementation on iOS target from your common gradle.

kotlin {
    sourceSets {
        iosMain {
            dependencies {
                implementation "io.ktor:ktor-client-ios:$your_ktor_version"
            }
        }
    }
}