Hey I have an issue when using my KMP lib on Android / Desktop I build a simple KMP with Ktor. I’m t...
l
Hey I have an issue when using my KMP lib on Android / Desktop I build a simple KMP with Ktor. I’m targeting Android and Desktops for the moment I configured the ktor engine as specified here The lib is builded as expected But when I call my service in android or on desktop (mac M1) , I got the following error (or similar error with Apache)
Copy code
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/engine/okhttp/OkHttp;
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.ktor.client.engine.okhttp.OkHttp" on path: DexPathList[[dex file "/data/data/com.louis.androidappsample/code_cache/.overlay/base.apk/classes3.dex", dex file "/data/data/com.louis.androidappsample/code_cache/.overlay/base.apk/classes.dex", zip file "/data/app/~~j1M4G7GVnLQAYjWuRlSLCA==/com.louis.androidappsample-ETUEUYx9UiPhzUHXlOvm1Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~j1M4G7GVnLQAYjWuRlSLCA==/com.louis.androidappsample-ETUEUYx9UiPhzUHXlOvm1Q==/lib/arm64, /system/lib64, /system_ext/lib64]]
I’ve tried everything. Clean and invalidate, remove all kind of caches, downgrade Ktor to 1.6.8, trying different engines..I don’t know how to solve that My targets are configured like this :
Copy code
android {
    publishAllLibraryVariants()

}

jvm {
    compilations.all {
        kotlinOptions.jvmTarget = "11"
    }
}
And sourceSet :
Copy code
val commonMain by getting {
    val commonMain by getting {
        dependencies {
            implementation(Ktor.Core)
            implementation(Ktor.ContentNegotiation)
            implementation(Ktor.Json)
            implementation(Ktor.Logging)

            implementation(Koin.Core)
        }
    }
}

val androidMain by getting {
    dependencies {
        implementation(Ktor.OkHttp)
        implementation(Android.Material)
    }
}

val jvmMain by getting {
    dependencies {
        implementation(Ktor.Apache)
    }
}
Thanks !
a
Maybe enabling multidex will help.
l
I’ll try, but my lib is empty (2 classes for the moment). It’s seems weird
a
I think all your dependencies and their dependencies counts.
l
According to that part multidex is enabled by default on API 21 or greater (i’m currently API 24)
214 Views