https://kotlinlang.org logo
f

Francis Mariano

10/01/2021, 7:41 PM
Hello everyone: I have problem with coroutine when I try use
native-mt
on iosMain module. Code in thread
Copy code
kotlin {
    android()

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget = when {
        System.getenv("SDK_NAME")?.startsWith("iphoneos") == true -> ::iosArm64
        else -> ::iosX64
    }

    iosTarget("ios") {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }



    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt") {
                    version {
                        strictly("1.5.2-native-mt")
                    }
                }
            }
        }
    }
}
Copy code
Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2.
Required by:
    project :shared
But when I replace the iosTarget with ios {} the gradle syncs with success. Can anyone tell me the reason???
Copy code
kotlin {
    android()

    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
            }
        }

        val iosX64Main by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-iosx64:1.5.2-native-mt") {
                    version {
                        strictly("1.5.2-native-mt")
                    }
                }
            }
        }

        val iosArm64Main by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-iosarm64:1.5.2-native-mt") {
                    version {
                        strictly("1.5.2-native-mt")
                    }
                }
            }
        }
    }
}
m

mkrussel

10/01/2021, 8:24 PM
You need the
native-mt
on all the dependencies. With that in the
commonMain
, you don't need the ios specific dependencies. Android is still needed to get the correct Main dispatcher on Android.
a

Anton Afanasev

10/01/2021, 10:40 PM
was about to write the same
f

Francis Mariano

10/04/2021, 11:19 AM
I see. Thank you very much
4 Views