kotlinx.coroutines: 0.30.0 kotlinx.coroutines does not seem to compile with iOS

I followed the Intellij IDEA File->New Project-> (Kotlin Tab) -> Kotlin (Mobile Android/iOS) generator tool to setup a project for testing a shared codebase between iOS and Android.

The coroutine setup works well for android but for some reason I can’t get a clean build for iOS with the following setup:

kotlin {
    targets {
        // For ARM, preset should be changed to presets.android_arm32 or presets.android_arm64
        fromPreset(presets.android, 'android')
        // For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64
        fromPreset(presets.iosX64, 'ios')
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
            }
        }
        commonTest {
            dependencies {
        		implementation 'org.jetbrains.kotlin:kotlin-test-common'
        		implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
            }
        }
        androidTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
            }
        }
        iosMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
            }
        }
        iosTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
            }
        }
    }
}

I get the following exception:

> Task :proj
proj/src/commonMain/kotlin/com/proj/sdk/Sample.kt:3:16: error: unresolved reference: coroutines
import kotlinx.coroutines.*
               ^
proj/src/commonMain/kotlin/com/proj/sdk/Sample.kt:17:5: error: unresolved reference: GlobalScope
    GlobalScope.launch { delay(1000)
    ^
proj/src/commonMain/kotlin/com/proj/sdk/Sample.kt:17:26: error: unresolved reference: delay
    GlobalScope.launch { delay(1000)
                         ^

> Task :proj:compileKotlinIos FAILED

FAILURE: Build failed with an exception.

I do assume I did something wrong, but I i’ve tried using both native+common as dependency for iOS but it does not accept it. Can someone point me towards the right direction?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 25 (3 by maintainers)

Most upvoted comments

@Syrou try to add enableFeaturePreview('GRADLE_METADATA') in settings.gradle

Thanks for the reply @wild-lynx As stated below my code snippet I did try with “kotlinx-coroutines-core-native” as dependency as well without any success.

The KotlinConf app uses an older setup than the one specified in https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html, and from my tests only work if you use the -conf2 on the two more important dependencies, and I do not want to go back to something that is not gonna work with the 1.3.0RC/1.3.0

Try cloning the KotlinConf app and bump the versions up to the latest releases and you will notice it does not work anymore.

@Syrou, source set names are case sensitive. Please use iOSMain.dependencies instead of iosMain.dependencies to get the required dependencies for the corresponding target.

Did it help?

oh well… same here, thanks a lot! nevertheless my code does not compile, but thats another topic/problem with coroutines and “Job”… https://github.com/JetBrains/kotlin-native/issues/2167 =(

@Syrou, doesn’t kotlinx-coroutines-core-native work even having Gradle version 4.7 and Gradle metadata enabled? Can you share a sample project, please, so I’d be able to take a look at the whole configuration and try to figure out what went wrong?

Also, the following versions should be compatible with each other:

* kotlin: 1.3.0-rc-146
* kotlinx.coroutines: 0.30.2-eap13 
* ktor: 1.0.0-alpha-3
* kotlinx.atomifcu: 0.11.10-eap13
* kotlinx.io (http://kotlinx.io/): 0.1.0-alpha-17-rc13
* kotlinx.serialization: 0.8.2-rc-13
* Gradle: 4.7

Please, try with Gradle 4.7