https://kotlinlang.org logo
Title
r

rsetkus

10/24/2020, 7:36 PM
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?
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

louiscad

10/24/2020, 7:50 PM
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

rsetkus

10/24/2020, 7:57 PM
Should be something else. Pulling Android engine for jvm
io.ktor:ktor-client-android
l

louiscad

10/24/2020, 7:58 PM
FYI, the Android engine is quite barbones. I'd use OkHttp or CIO over it anyday.
❤️ 1
r

rsetkus

10/24/2020, 8:23 PM
Not sure how it is related but changing from
request<R>(path) {
    this.method = methodType
    this.headers.appendAll(headersSupplier())
    this.body = body
}
to
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

louiscad

10/24/2020, 8:50 PM
Ah yes, you need to explicity setup the
Json
feature.
👍🏻 1
r

rsetkus

10/24/2020, 9:10 PM
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

louiscad

10/24/2020, 11:40 PM
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.