Francis Mariano

    Francis Mariano

    11 months ago
    Hello everyone: I have problem with coroutine when I try use
    native-mt
    on iosMain module. Code in thread
    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")
                        }
                    }
                }
            }
        }
    }
    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???
    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

    11 months ago
    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.
    Anton Afanasev

    Anton Afanasev

    11 months ago
    was about to write the same
    Francis Mariano

    Francis Mariano

    11 months ago
    I see. Thank you very much