https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

AG

08/30/2020, 4:30 PM
Hi everyone I’m trying to create kmp with ktor 1.4.0 similar to this sample https://github.com/ktorio/ktor-samples/tree/master/client-mpp and having issues with ktor, ios app keep crashing with kotlin
InvalidMutabilityException
Copy code
class Api {

    private val client = HttpClient()

    var address = Url("<https://tools.ietf.org/rfc/rfc1866.txt>")

    fun request(callback: (String) -> Unit) {
        GlobalScope.apply {
            launch(ApplicationDispatcher) {
                val result: String = client.get {
                    url(address.toString())
                }
                callback(result)
            }
        }
    }
}
j

John O'Reilly

08/30/2020, 5:02 PM
There's a couple of known issues with Ktor 1.4.0 running in Kotlin/Native env e.g https://youtrack.jetbrains.com/issue/KTOR-915 https://youtrack.jetbrains.com/issue/KTOR-924 Firstly Ktor 1.4 now uses
native-mt
branch of Kotlinx Coroutines but this is only fully supported in Kotlin/Native using
CIO
engine I believe (and only for http endpoints). (EDIT: my previous statement about only being supported in CIO is not correct, see below!).....but that crash still occurs with that setup if logging is enabled ( @russhwolf identified that and created that 2nd issue).
👍 1
fwiw I'm using it in following small project if you want to compare setup https://github.com/joreilly/PeopleInSpace
a

AG

08/30/2020, 6:31 PM
Thanks 👍
r

russhwolf

08/30/2020, 7:18 PM
CIO isn’t actually necessary. You can get the default engine working as well.
j

John O'Reilly

08/30/2020, 7:19 PM
I thought I had issues with default engine on iOS and/or macOS but will double check
r

russhwolf

08/30/2020, 7:19 PM
You still have to be careful about all the usual K/N threading, but we have it working in KaMPKit
And I was using the default engine in the sample for KTOR-924
Haven’t looked at macOS so it’s also possible the situation is different there but I think that would surprise me
j

John O'Reilly

08/30/2020, 7:21 PM
at least prior to 1.4 I was seeing different behaviour on iOS and macOS
I'll check again now I'm rebased on 1.4 and see what works/doesn't work now
I may have misinterpreted "Partial support for CIO (native-mt) which includes Sockets and HTTP* from https://blog.jetbrains.com/ktor/2020/08/18/ktor-1-4-0-now-available/
r

russhwolf

08/30/2020, 7:25 PM
Yeah I initially misinterpreted that to mean that was the only place where
native-mt
was.
j

John O'Reilly

08/30/2020, 7:51 PM
yeah, confirmed default engine is fine....which also means there isn't same restriction on only using http endpoint that current CIO imlementation has
thanks @russhwolf for heads up on that
2 Views