Using kotlinx-coroutines-core-native with kotlin-multiplatform plugin


#1

Hi folks,

I have tried to use the native coroutine with multiplatform plugin, but with no success to build the project.
My build.gradle to SharedCode is the following:

apply plugin: 'kotlin-multiplatform'

    kotlin {
        targets {
            final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
                              ? presets.iosArm64 : presets.iosX64

            fromPreset(iOSTarget, 'iOS') {
                compilations.main.outputKinds('FRAMEWORK')
        }

         fromPreset(presets.jvm, 'android')
    }

        sourceSets {
            commonMain.dependencies {
                api 'org.jetbrains.kotlin:kotlin-stdlib-common'
                // coroutine
                implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.1.0'
        }

        androidMain.dependencies {
            api 'org.jetbrains.kotlin:kotlin-stdlib'
            // Timber
            implementation 'com.jakewharton.timber:timber:4.7.1'
        }
    }
}

// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
    compileClasspath
}

The project sync with no error, but the coroutine code is not accessible inside commonMain module. I also tried to add enableFeaturePreview('GRADLE_METADATA') in settings.gradle file, but the sync fails.

 FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':android:debugRuntimeClasspath'.
> Could not resolve org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.1.0.
  Required by:
      project :android > project :Shared
   > Unable to find a matching configuration of org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.1.0:
       - Configuration 'debugIos_arm32Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'ios_arm32' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'debugIos_arm64Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'ios_arm64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'debugIos_x64Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'ios_x64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'debugLinux_x64Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'linux_x64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'debugMacos_x64Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'macos_x64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'debugMingw_x64Link':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.native.debuggable 'true' but wasn't required.
           - Found org.gradle.native.optimized 'false' but wasn't required.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'mingw_x64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'metadata-api':
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-runtime' and found incompatible value 'kotlin-api'.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'common'.

Can anyone help me?
Thanks in advanced.


#2

i hawe same problem:


#3

Yep, same happening here with kotlin-platform-native