https://kotlinlang.org logo
#ktor
Title
# ktor
j

jean

08/19/2020, 12:21 PM
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

e5l

08/19/2020, 12:22 PM
Hey, could you list the dependencies section?
j

jean

08/19/2020, 12:26 PM
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

e5l

08/19/2020, 12:27 PM
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

jean

08/19/2020, 12:43 PM
Adding the android dependency fixed the issue 🙂 thanks for help! Should I report the bug on the ktor github or YT?
e

e5l

08/19/2020, 12:44 PM
It’s not a bug, it’s how service loader works. You also have to add iOS dependency for iOS
j

jean

08/19/2020, 12:46 PM
not sure what you meant by this then
HttpClient()
  call should work without explicit engine in common
e

e5l

08/19/2020, 12:46 PM
Without explicit argument
It will look up your dependency list, and select the engine
j

jean

08/19/2020, 12:48 PM
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

e5l

08/19/2020, 12:49 PM
No problem 😉
r

rudolf.hladik

08/19/2020, 1:19 PM
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

e5l

08/19/2020, 1:20 PM
Yep!
r

rudolf.hladik

08/19/2020, 1:21 PM
is the CIO engine available for android and iOS? what is the artefact of these engines?
e

e5l

08/19/2020, 1:22 PM
ktor-client-cio
👍 1
r

rudolf.hladik

08/19/2020, 1:22 PM
thx a lot
j

John O'Reilly

08/19/2020, 1:57 PM
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

e5l

08/19/2020, 1:57 PM
Yes, you can 🙂
👍 3
Please note that
CIO
doesn’t work on js yet
j

John O'Reilly

09/01/2020, 3:20 PM
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

e5l

09/02/2020, 10:09 AM
Could you file an YT issue?
j

John O'Reilly

09/02/2020, 10:10 AM
@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

Neal Sanche

09/02/2020, 2:48 PM
@John O'Reilly Yeah, okay, I'll do that.
👍 1
14 Views