1

I've been using Kotlinx Serialization perfectly happily in my Android project.

The main project build.gradle file has the following dependency:

dependencies {
  classpath "org.jetbrains.kotlin:kotlin-serialization:${versions.project.kotlin}"
}

And in each of the modules using serialization I have:

plugins {
  id 'com.android.library'
  id 'org.jetbrains.kotlin.plugin.serialization'
}

This works fine for Kotlin 1.6.21 but as soon as I try to upgrade to 1.7.0 I get the following convoluted message and I can't build the project.

Could not resolve org.jetbrains.kotlin:kotlin-serialization:1.7.0.
Required by:
    project :config
 > The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.3', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of org.jetbrains.kotlin:kotlin-serialization:1.7.0:
     - apiElements
     - gradle70ApiElements
     - gradle70JavadocElements
     - gradle70RuntimeElements
     - gradle70SourcesElements
     - javadocElements
     - runtimeElements
     - samplessources
     - sourcesElements
   All of them match the consumer attributes:
     - Variant 'apiElements' capability org.jetbrains.kotlin:kotlin-serialization:1.7.0 declares an API of a component, preferably optimized for standard JVMs, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
         - Unmatched attributes:
             - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '7.1.3')
             - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
             - Provides a library but the consumer didn't ask for it
             - Provides its dependencies declared externally but the consumer didn't ask for it
             - Provides compatibility with Java 8 but the consumer didn't ask for it
             - Provides its elements packaged as a jar but the consumer didn't ask for it
             - Provides release status but the consumer didn't ask for it

Has anyone else run into this problem and/or knows the solution?

aSemy
  • 5,485
  • 2
  • 25
  • 51
Barry Irvine
  • 13,858
  • 3
  • 25
  • 36
  • 1
    I migrated a [project](https://github.com/tminet/API-Request) that uses _kotlin serialization_ to version 1.7.0 days ago and had no problems, the difference in my case is that I was using the new _gradle_ structure. I also opened a project with the old _gradle_ structure here, added _kotlin serialization_ and migrated to version 1.7.0, but no errors happened... – Thales Isidoro Jul 04 '22 at 13:11
  • @ThalesIsidoro Thank you so much for sharing your project. It wasn't the new vs old gradle structure that was the problem but the fact that in addition to `implementation org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3` I was also doing the completely unnecessary `implementation org.jetbrains.kotlin:kotlin-serialization:1.7.0` – Barry Irvine Jul 05 '22 at 08:01

0 Answers0