Hi. For everyone using KMM with Ktor and Coroutin...
# multiplatform
a
Hi. For everyone using KMM with Ktor and Coroutines dependency, which versions of these two are you using? 🙏 So far, I was only able make it work with
Ktor 1.6.7
and
Coroutines 1.5.1-new-mm-dev2
but
./gradlew <module>:compileKotlinMetadata
gradle tasks are failing.
m
Coroutines
1.6.0
comes with support for the new mm, so no need for
1.5.1-new-mm-dev2
h
Ktor
1.6.7
and coroutines
1.6.0-native-mt
with
Copy code
kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled
p
@Mitchell Syer I was having very weird problems with Ktor and the standard
1.6.0
coroutines. I’m using
1.5.2-native-mt
still. Otherwise same as @hfhbd
m
This should help, it suggests using a build of Ktor made for the new MM https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md
a
@Mitchell Syer Thanks, but using Ktor 1.6.2-native-mm-eap-196 and Coroutines 1.6.0 results in:
Could not find io.ktor:ktor-client-android:1.6.2-native-mm-eap-196.
m
Its in a seperate maven repo, it should be listed in the guide
a
I think, it should work with latest Ktor 1.6.7 and Coroutines 1.6.0. But having this two set up,
./gradlew umbrellaModule:assembleXCFramework
fails with:
Copy code
e: Module "io.ktor:ktor-network" has a reference to symbol kotlinx.coroutines/SingleThreadDispatcher|null[0]. Neither the module itself nor its dependencies contain such declaration.

This could happen if the required dependency is missing in the project. Or if there is a dependency of "io.ktor:ktor-network" that has a different version in the project than the version that "io.ktor:ktor-network" was initially compiled with. Please check that the project configuration is correct and has consistent versions of all required dependencies.
Any idea? 😕
m
Hmm, then your best bet may be to use the Ktor 2.0.0 beta, which looks to have support for the new MM
🙌 1
h
coroutines
1.6.0
is not yet supported with ktor, only
1.6.0-native-mt
. a) use ktor
1.6.2-native-mm-eap-196
and coroutines
1.5.1-new-mm-dev2
b) wait for the next beta of ktor
2.0.0-beta2
and use coroutines
1.6.0
c) use ktor
1.6.7
and coroutines
1.6.0-native-mt
🙌 1
a
Thank you both for your help! 🙏 However, neither of this solutions seem to work for my case, so I’ll have to dig a bit deeper to find out what is going on with ktor stuff. Still getting
Module "io.ktor:ktor-network" has a reference to symbol kotlinx.coroutines/SingleThreadDispatcher|null[0]
error using (C) versions above 🤷‍♂️
h
Thats strange. Do you have a sample/reproducer? For my simple playground demo, this combination works: https://github.com/hfhbd/ComposeTodo
a
Hm. Could be somehow related to ktor-cio. So we are using:
Copy code
"ktor-cio" to "io.ktor:ktor-client-cio:$ktorVersion",
"ktor-core" to "io.ktor:ktor-client-core:$ktorVersion",
and coroutines. Tried
1.6.0-native-mt
but no luck. Only
1.5.1-new-mm-dev2
seem to be working with Ktor
1.6.7
but in this case,
compileKotlinMetadata
gradle task fails 😕 In case of
1.6.7
and
1.6.0-native-mt
, there is
Module "io.ktor:ktor-network" has a reference to symbol kotlinx.coroutines/SingleThreadDispatcher|null[0]
error and
linkDebugFrameworkIosArm64
gradle task fails 🤷‍♂️ 😞
h
do you try to use cio on iOS?
a
ktor-cio is then used as
implementation
inside
commonMain
dependencies yes, and this module is then exported inside iOS umbrella framework
In case of
Ktor 1.6.7
and
Coroutines 1.5.1-new-mm-dev2
, gradle task
moduleB:compileKotlinMetadata
fails with error:
Copy code
Execution failed for task ':moduleB:compileKotlinMetadata'.
> Error while evaluating property 'filteredArgumentsMap' of task ':moduleB:compileKotlinMetadata'
   > Could not resolve all files for configuration ':moduleB:metadataCompileClasspath'.
      > Could not find org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-new-mm-dev2.
        Required by:
            project :moduleB > project :moduleA
So we have Umbrella module, which exports moduleA and moduleB. Also moduleB has dependency on moduleA.
s
I recall cio not being supported on iOS targets (this may have changed at some point). Normal ktor client on iOS delegates to using NSURLSession which is better for mobile apps. The last I looked it didn't support web sockets which may be a problem for you. Otherwise, it is great.
a
@Sam Thanks for the info, will keep it in mind. Will update you guys once we find a solution, thanks!
Hi all! Just an update in case anybody faces this issue 😄 We’ve managed to get it work using
Ktor 2.0.0-eap-317
and
Coroutines 1.6.0-native-mt
. Reference: https://youtrack.jetbrains.com/issue/KT-51145 Thank you all!