I’m updating my mpp to 1.4 and get this error now ...
# ktor
j
I’m updating my mpp to 1.4 and get this error now
Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See <https://ktor.io/clients/http-client/engines.html>
I notice some changes in the doc, as far as I remember, that page had a comment regarding multiplatform saying devs could just omit to specify an engine when used in mpp context. I guess it’s not the case anymore? I plan to share an api client based on ktor client to android and ios, should I change to something like that :
Copy code
class ApiClient(
    private val engine: HttpClientEngine
) {
    private val client = HttpClient(engine)
}
then android can instantiate this by passing
CIO
and iOS passing
Ios
e
Hey, could you list the dependencies section?
j
common :
Copy code
val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
            }
        }
then I have a specific target for both android and ios :
Copy code
val clientCommon by creating {
    dependsOn(commonMain)
    kotlin.srcDir("src/clientCommon/kotlin")
    resources.srcDir("src/clientCommon/resources")

    dependencies {
        implementation("io.ktor:ktor-client-core:1.4.0")
        implementation("io.ktor:ktor-client-json:1.4.0")
        implementation("io.ktor:ktor-client-serialization:1.4.0")
        implementation("com.russhwolf:multiplatform-settings:0.6.1")
        implementation("com.russhwolf:multiplatform-settings-no-arg:0.6.1")
    }
}
android, I used to have a specific android dependency when using 1.3.72, I removed it since 1.4.0 suggest to only have a single dependency in common, is that why it fails?
Copy code
val androidMain by getting {
            dependsOn(clientCommon)
            dependencies {
            }
        }
ios, I havent implemented the app yet so it’s empty for now
Copy code
val iosMain by getting {
    dependsOn(clientCommon)
    dependencies {
    }
}
e
The engine implementations are still in platform-specific dependencies. Please consider adding them back
But
HttpClient()
call should work without explicit engine in common
j
Adding the android dependency fixed the issue 🙂 thanks for help! Should I report the bug on the ktor github or YT?
e
It’s not a bug, it’s how service loader works. You also have to add iOS dependency for iOS
j
not sure what you meant by this then
HttpClient()
  call should work without explicit engine in common
e
Without explicit argument
It will look up your dependency list, and select the engine
j
right righ, I got confused by the
But
I though you were saying that without specific dependencies in android/ios scope, it should still work. all good then, thanks 🙂
e
No problem 😉
r
I’m kinda lost in this conversation, so the correct approach is to specify ktor-client-core dependency in commonMain and in androidMain and iosMain specify engine? to be able to use HttpClient in common?
e
Yep!
r
is the CIO engine available for android and iOS? what is the artefact of these engines?
e
ktor-client-cio
👍 1
r
thx a lot
j
I might have misunderstood above....but can you put
ktor-client-cio
in common if that's engine you're going to use for all platforms (if that's possible that is)?
e
Yes, you can 🙂
👍 3
Please note that
CIO
doesn’t work on js yet
j
just fyi that there's seemingly a crash on watchOS using
CIO
.....works fine in simulator but crashes on device
got this info 2nd hand but can probably source crash info if not easy to reproduce there
e
Could you file an YT issue?
j
@Neal Sanche could you do that when you have a chance (this is crash you got (using PeopleInSpace repo) when using CIO for ktor engine when running on watchOS device)
n
@John O'Reilly Yeah, okay, I'll do that.
👍 1