Hi. Developing multiplatform library for Android a...
# ktor
r
Hi. Developing multiplatform library for Android and iOS. At the moment don't need anything specific for Android so targeting jvm and iOS. Getting an error on Android application when making a Ktor request call. By the way, I don't get a such error on unit test at commonMain module which runs against jvm. Any ideas what can cause this error?
Copy code
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteChannelKt$ByteChannel$1 (Kotlin reflection is not available) -> class xxx.YYY (Kotlin reflection is not available)
    with response from <https://XXX>:
    status: 200 OK
    response headers: 
    cache-control: max-age=600
    , connection: keep-alive
    , content-type: application/json;charset=utf-8
    
        at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:84)
l
I'd try to use the CIO or OkHttp engine on the JVM and Android. The default engine used on the JVM probably fails on Android for some reason.
r
Should be something else. Pulling Android engine for jvm
io.ktor:ktor-client-android
l
FYI, the Android engine is quite barbones. I'd use OkHttp or CIO over it anyday.
❤️ 1
r
Not sure how it is related but changing from
Copy code
request<R>(path) {
    this.method = methodType
    this.headers.appendAll(headersSupplier())
    this.body = body
}
to
Copy code
val response = get<String>(path) {
    this.headers.appendAll(headersSupplier())
}

Json.decodeFromString(R::class.serializer(), response)
serializes from string to type
R
Hmm... I can see that default serialization engine for Ktor is Gson. Maybe this is it 🤔
l
Ah yes, you need to explicity setup the
Json
feature.
👍🏻 1
r
Any reason I cannot access (not visible, cannot import...)
JsonFeature
on common module? Do I need to include explicit dependency for it? Already included
"org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0"
No worries. Sorted. Where Missing
io.ktor:ktor-client-json
and
io.ktor:ktor-client-serialization
. I find it quite hard to get around in Ktor docs. Found it on somebody's github.
l
Yep, the docs for the clients are not as good as the docs for the server. But the ktor team expanded, and they are working on docs improvements, among other things.