I'm trying out for the first time to build a Kotlin MPP using a Kotlin DSL gradle file. The issue is quite simple but I've been trying everything I could think of to fix it : the android shared code can't resolve Stetho interceptor
My build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("kotlinx-serialization")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.14.0")
// HTTP
implementation("io.ktor:ktor-client-core:1.3.0-rc")
implementation("io.ktor:ktor-client-json:1.3.0-rc")
implementation("io.ktor:ktor-client-serialization:1.3.0-rc")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3")
implementation("io.ktor:ktor-client-android:1.3.0-rc")
implementation("io.ktor:ktor-client-json-jvm:1.3.0-rc")
implementation("io.ktor:ktor-client-serialization-jvm:1.3.0-rc")
implementation("io.ktor:ktor-client-okhttp:1.3.0-rc")
implementation("com.squareup.okhttp3:logging-interceptor:4.0.1")
implementation( "com.facebook.stetho:stetho-okhttp3:1.5.1")
}
Thanks a lot for your help !
EDIT :
So I found out that when I replace
jvm("android")
with
android()
Stetho-interceptor can be imported, but the "expected" and "actual" keyword are not correctly linked by Android studio for iOS :
"Actual property ... has no corresponding expected declaration" when I hover an actual declaration for iOS
When I use both
jvm("android") android()
I get a gradle error :
"The target 'android' already exists, but it was not created with the 'jvm' preset. To configure it, access it by name in kotlin.targets
or use the preset function 'android'."
you do not need to have jvm("android") if you already are using the android() target. if you want a separate jvm target then you should name it something different (ex. jvm("something") ).
Once you add your android target and manifest + android definitions, the libraries should resolve. the facebook library likely depends on an android target which is why it is not resolving.