Is your feature request related to a problem? Please describe.
I'm currently using apollo for a multiplatform project. But using it alongside Ktor bumps Ktor's coroutines version down to 1.3.9 instead of 1.3.9-native-mt, and Ktor is enforcing native-mt usage of coroutines as of version 1.4.1
Describe the solution you'd like
Add a gradle version com.apollographql.apollo:apollo-runtime-kotlin:2.4.0-native-mt so that apollo and Ktor can use the same coroutines version.
Good point. Maybe we should just use -native-mt in apollo-runtime-kotlin no matter what? native-mt is more experimental but as apollo-runtime-kotlin is experimental too, maybe it's not a big deal. Any other drawbacks of using native-mt instead of the regular artifact?
As far as I know, there are no obvious API limitations when using native-mt, except for the caution of possible memory leaks as specified here.
I'm confused, the Ktor docs recommends using the single-threaded version there: https://kotlinlang.org/docs/mobile/concurrency-and-coroutines.html#ktor-and-coroutines
Make sure that you use the single-threaded version of kotlinx.coroutines as a dependency for Ktor. Ktor for macOS and iOS requires this version
Has that changed recently?
@rantingmong another way to look at this, can you try forcing the dependency in your project?
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") {
version {
strictly("1.3.9-native-mt-2")
}
}
I'm confused, the Ktor docs recommends using the single-threaded version there: https://kotlinlang.org/docs/mobile/concurrency-and-coroutines.html#ktor-and-coroutines
Make sure that you use the single-threaded version of kotlinx.coroutines as a dependency for Ktor. Ktor for macOS and iOS requires this version
Has that changed recently?
I think this has changed recently as they are now depending on the native-mt variant of coroutines. This also confused me for a while too.
@rantingmong another way to look at this, can you try forcing the dependency in your project?
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") { version { strictly("1.3.9-native-mt-2") } }
I tried doing that as per recommendation by my friend but I got this:
Couldn't resolve metadata artifact for ModuleDependencyIdentifier(groupId=org.jetbrains.kotlinx, moduleId=kotlinx-coroutines-core) in configuration ':shared:iosArm64CompileKlibraries'
I think this has changed recently as they are now depending on the native-mt variant of coroutines. This also confused me for a while too.
Yup, this was just merged: https://github.com/JetBrains/kotlin-mobile-docs/pull/24
I tried doing that as per recommendation by my friend but I got this:
Couldn't resolve metadata artifact for ModuleDependencyIdentifier(groupId=org.jetbrains.kotlinx, moduleId=kotlinx-coroutines-core) in configuration ':shared:iosArm64CompileKlibraries'
Interesting.. Does it say anything more as to why it couldn't find the artifact? Also can you try to run ./gradlew :shared:dependencies and post the results in a gist?
Sure will do!
The best approach seems to be to force Gradle's resolution to the desired version:
configurations {
all {
resolutionStrategy {
force("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt-2")
force("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9-native-mt-2")
}
}
}
Hi @rantingmong! How did the above solution go?
Using Gradle dependency resolution is way easier than having to maintain two different artifacts so unless you've had an issue with this, I'll close this issue.
Closing this. Use the above suggestion to force the -native-mt version of couroutines if you need them.
Most helpful comment
The best approach seems to be to force Gradle's resolution to the desired version: