https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Joaquim Ley

10/18/2020, 6:15 PM
Hello everyone, has anyone had any issues related to coroutines/ktor/multiplatform? So when using the
1.3.9-native-mt-2
it works on iOS but not for Android • const val kotlinCoroutines = “1.3.9-native-mt-2” With
1.4.0-M1
works for android but not iOS • const val kotlinCoroutines = “1.4.0-M1"
c

cy

10/18/2020, 6:16 PM
How exactly it is not working? Could you please briefly describe?
j

Joaquim Ley

10/18/2020, 6:19 PM
Sorry I’ll give more context, give me a minute to write it out
Versions.kotlinCoroutines =
1.3.9-native-mt-2
Copy code
val commonMain by getting {
 dependencies {
                // Coroutines
                implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}") {
                    version {
                        strictly(Versions.kotlinCoroutines)
                    }
                }
(...)
}
• This works fine I can make http requests on iOS, I only have the kto-client-ios dependency on the iosMain But if I try to build on Android with the same versions it won’t compile:
Copy code
Execution failed for task ':android:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':android:debugRuntimeClasspath'.
   > Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:{strictly 1.3.9-native-mt-2}.
     Required by:
         project :android > project :shared
      > Cannot find a version of 'org.jetbrains.kotlinx:kotlinx-coroutines-core' that satisfies the version constraints:
           Dependency path 'com.<--->:android:unspecified' --> 'com.'<--->:shared:1.0-SNAPSHOT' --> 'org.jetbrains.kotlinx:kotlinx-coroutines-core:{strictly 1.3.9-native-mt-2}'
• Cannot find a version of ‘org.jetbrains.kotlinx:kotlinx-coroutines-core’ that satisfies the version constraints:  ☝️
And if I switch the
kotlinCourtines
version to
1.4.0-M1
compiles just fine for both android and iOS, but when making a http request on the later, I get the freeze error:
Copy code
Error(message=mutation attempt of frozen kotlinx.coroutines.ChildHandleNode@3516608)
PS: Sorry it took so long I had to clean and rebuild, for a moment it worked on both but that’s because iOS was cached on 1.3.9-mt-2 and android was on 1.4.0-m1
Some more info on other versions:
Copy code
const val androidGradlePlugin = "4.2.0-alpha13"
    const val kotlin = "1.4.10"
    const val kotlinCompiler= "1.4.0"
    const val kotlinCoroutines = "1.4.0-M1" // OR "1.3.9-native-mt-2"
    const val ktor = "1.4.0"
    const val kotlinxSerialization = "1.0.0-RC"
@cy let me know if I can provide any more info
Thanks to @John O'Reilly’s People in Space repo I noticed he commited a cleaup but stil kept isForce instead of strictely, so the workaround for now is:
Copy code
val commonMain by getting {
            dependencies {
                // Coroutines
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}") {
                    isForce = true
                }
(...)
I spent a good 6hours to get this to finally working but now I only have swift on actual SwiftUI and I’m able to write ViewModels in kotlin for ios and android
👍 1
j

John O'Reilly

10/18/2020, 8:15 PM
@Joaquim Ley I actually had meant to commit the update to use
strictly
instead of
isForce
....wasn't clear on this issue but are you saying that using that causes a problem?
j

Joaquim Ley

10/18/2020, 8:16 PM
Yes, it took my whole sunday to get this.. As I mentioned on Twitter, I’ve based a lot of my project on your PiS project but I wanted to write my viewmodels in Kotlin. I had some issues setting up ktor with iOS and eventually came to this. It should however work fine if you use Swift to call the repository
j

John O'Reilly

10/18/2020, 8:46 PM
but
strictly
and
isForce
should do the same thing as I understand it.....I had meant to update to the former as that seemed to be the recommended approach now
I'm still using v
1.3.9-native-mt
of kotlinx coroutines btw primarily because of https://youtrack.jetbrains.com/issue/KTOR-1087
j

Joaquim Ley

10/18/2020, 9:15 PM
It should be the same but I got it working finally, android is on 1.4-m2 and common on native-mt-2 and it is working finally 🙏
7 Views