Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use kotlin-runtine with coroutines-native-mt #2619

Closed
rantingmong opened this issue Sep 30, 2020 · 10 comments
Closed

Option to use kotlin-runtine with coroutines-native-mt #2619

rantingmong opened this issue Sep 30, 2020 · 10 comments
Labels
⌛ Waiting for info More information is required ✨ Type: Feature

Comments

@rantingmong
Copy link

rantingmong commented Sep 30, 2020

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.

@martinbonnin
Copy link
Contributor

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?

@rantingmong
Copy link
Author

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.

@martinbonnin
Copy link
Contributor

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?

@martinbonnin
Copy link
Contributor

@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")
    }
  }

@rantingmong
Copy link
Author

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'

@martinbonnin
Copy link
Contributor

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: JetBrains/kotlin-mobile-docs#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?

@rantingmong
Copy link
Author

Sure will do!

@rocketraman
Copy link

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")
        }
    }
}

@martinbonnin
Copy link
Contributor

martinbonnin commented Oct 16, 2020

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.

@martinbonnin martinbonnin added the ⌛ Waiting for info More information is required label Oct 19, 2020
@martinbonnin
Copy link
Contributor

Closing this. Use the above suggestion to force the -native-mt version of couroutines if you need them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌛ Waiting for info More information is required ✨ Type: Feature
Projects
None yet
Development

No branches or pull requests

3 participants