KMM - How to add Retrofit into :shared module (commonMain)

Viewed 1085

I want to add Retrofit into :shared module (commonMain).

sourceSets["commonMain"].dependencies {
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
}

But in commonMain I can't see Retrofit class. In androidMain I can see it. That is a magic. I don't add Retrofit into androidMain.

Please help me. Thanks in advance.

1 Answers

Retrofit is a Java & Android library, this means you can share it only between JVM targets in KMP.

You can't use Retrofit in your shared code, if you're building a KMM app (iOS and Android targets) unless you create an abstraction over it, and provide the native/iOS implementation (which is a tedious amount of work).

You could use Ktor instead.

Related