`kotlin.NoSuchElementException: List is empty` whe...
# ktor
d
kotlin.NoSuchElementException: List is empty
when initialising
HttpClient
with
JsonFeature
on iOS 🤔 Not sure what's going wrong here but I suspect I have the wrong dependencies for target
iosMain
, being:
Copy code
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-iosx64:$kotlin_coroutines_version")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$kotlin_serialization_version")
                implementation("io.ktor:ktor-client-ios:$ktor_version")
                implementation("io.ktor:ktor-client-json-iosx64:$ktor_version")
..it's hard to follow what the dependencies should be from Ktor documentation and examples. These don't seem to have kept pace with recent changes in meta-data driven identifiers and other refactoring.
👀 1
r
Here are the dependencies I have on the iOS side, note that I use the multiplatform plugin
Copy code
implementation("io.ktor:ktor-client-ios:${Versions.ktor}")
implementation("io.ktor:ktor-client-json-native:${Versions.ktor}")
implementation("io.ktor:ktor-client-serialization-native:${Versions.ktor}")
From what I understand the MPP plugin then selects the correct actual dependency from the target type, (arm64 or x86 for me)
d
Thanks, you are right - I was missing
ktor-client-json-native
and unnecessarily fully specifying
-iosx64
. That solved my issue 😄
Next problem is how to handle making simple Ktor client requests from iOS since
runBlocking
will block the only available thread... 🤔
I'm guessing somewhere in Kotlin's MVP there might be a way to adapt the main
NSRunLoop
as a co-routine run-loop & scope...
r
Just search for “ios kotlin coroutines” and you’ll find a bunch of articles
d
👍