Hi guys, I'm converting my android project to kotl...
# ktor
r
Hi guys, I'm converting my android project to kotlin multiplatform and I'm running into a simulator crash when running my app. The logcat error is
Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency
. My client looks like this:
Copy code
private val client = HttpClient() {
        install(Logging)
        install(ContentNegotiation) {
            json(Json {
                prettyPrint = true
                isLenient = true
                ignoreUnknownKeys = true
            })
        }
    }
And my
shared
module (where my ktor code lives) looks like this (I'm using kotlin 1.9.20)
Copy code
commonMain {
            dependencies {
                implementation(libs.ktor.client.core) // 2.3.5
                implementation(libs.kotlinx.serialization.json) // 1.6.0
                implementation(libs.kotlinx.coroutines.core) // 1.7.3
                implementation(libs.ktor.client.content.negotiation) // 2.3.5
                implementation(libs.ktor.serialization) // 2.3.5
                implementation(libs.ktor.logging) // 2.3.5
            }
        }
I didn't have an
androidMain
sourceSet defined so, one of the things I tried was to add one with the same dependencies as commonMain (based on a thread from 3 years ago) but that didn't help the issue go away. Is there a different place I should be adding the engine? The reason I'm not specifying an engine in my
HttpClient()
declaration is because I just wanted to use the default engine, should I be using a different engine? I had a thread about a month ago where I was using CIO but that led to issues with my ios app not running
h
HttpClient without a specific engine tries to fetch an engine from the classpath, specified by your dependencies. You could either use CIO or use the platform specific engine by adding the dependency.
core does not contain any engine
r
So I need to add an engine in my
app
dependencies? or still in my
shared
module?
h
It does not matter, both modules are merged in your classpath but from the module structure you only need it in your app, so app dependencies.
r
Got it. Thank you!