I'm trying to add `kotlinx-serialization` to a KMP...
# serialization
a
I'm trying to add
kotlinx-serialization
to a KMP module, but I'm getting the following error (details in the thread). What could be an issue?
Copy code
Could not resolve org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0
1
Copy code
Execution failed for task ':state-keeper:compileKotlinMetadata'.
> Could not resolve all files for configuration ':state-keeper:metadataCompileClasspath'.
   > Could not resolve org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0.
     Required by:
         project :state-keeper
      > The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0:
          - androidNativeArm32ApiElements-published
          - androidNativeArm64ApiElements-published
          - androidNativeX64ApiElements-published
          - androidNativeX86ApiElements-published
          - iosArm32ApiElements-published
          - iosArm64ApiElements-published
          - iosSimulatorArm64ApiElements-published
          - iosX64ApiElements-published
          - jsApiElements-published
          - jvmApiElements-published
          - jvmRuntimeElements-published
          - linuxArm32HfpApiElements-published
          - linuxArm64ApiElements-published
          - linuxX64ApiElements-published
          - macosArm64ApiElements-published
          - macosX64ApiElements-published
          - mingwX64ApiElements-published
          - mingwX86ApiElements-published
          - tvosArm64ApiElements-published
          - tvosSimulatorArm64ApiElements-published
          - tvosX64ApiElements-published
          - watchosArm32ApiElements-published
          - watchosArm64ApiElements-published
          - watchosDeviceArm64ApiElements-published
          - watchosSimulatorArm64ApiElements-published
          - watchosX64ApiElements-published
          - watchosX86ApiElements-published
build.gradle
is pretty simple:
Copy code
plugins {
    id("kotlin-multiplatform")
    kotlin("plugin.serialization") version "1.9.0"
}

kotlin {
    jvm()
    js { browser() }

    sourceSets {
        commonMain {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
            }
        }
    }
}
Kotlin 1.9.0
j
hmm, strange....I was using 1.5.1 on a few KMP projects here but just tried 1.6.0 and seems ok....also added explicit dependency to
kotlinx-serialization-json
and seemed to find it (projects also included those targets)
a
Did you try building? For me Gradle sync works, but build fails.
j
yeah, built/ran as well
a
Weird
Somehow it doesn't list the common variant, which it tries to find.
Must be a silly mistake somewhere 🙂
Oh. Turned out this was due to the presence of:
kotlin.mpp.enableCompatibilityMetadataVariant=true
in
gradle.plroperties
👍 1