First, we need to know where the conflict comes from.
The binary version 1.5.1 isn't the version of kotlin-stdlib used which can be known by examining the dependency tree. In my case, I was using androidx.core:core-ktx:1.6.0 which depends on org.jetbrains.kotlin:kotlin-stdlib:1.5.10
The expected version depends on the version of kotlin-gradle-plugin
used in build.gradle
project file.
So in my case, there was incompatibility between androidx.core:core-ktx
and kotlin-gradle-plugin
version. To resolve the conflict, I had two options. Either upgrade KGP or downgrade ktx.
In build.gradle (Project)
ext.kotlin_version = '1.3.40' // not compatible with ktx:1.6.0
// ext.kotlin_version = '1.4.31' // upgrading KGP fixes the issue
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
In build.gradle (Module)
// implementation "androidx.core:core-ktx:1.2.0" // downgrading ktx fixes the issue
implementation "androidx.core:core-ktx:1.6.0" // not compatible with kotlin_version = '1.3.40'
In gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
The rule here is to choose a ktx version whose release date is close to the release date of KGP. Links of both can be found below.
https://developer.android.com/jetpack/androidx/releases/core
https://developer.android.com/studio/releases
https://developer.android.com/studio/releases/past-releases
https://developer.android.com/studio/releases/gradle-plugin