'warning: Kotlin runtime JAR files in the classpath should have the same version
Solution 1:[1]
firstly, figure out the reason by the gradle script below
./gradlew app:dependencies
(change app to your gradle module name)
+--- project :common
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| | \--- org.jetbrains:annotations:13.0
| +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61
| +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.12.0 -> 0.14.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.60 -> 1.3.61
Then, the dependency tree will be shown. check which dependency use the issue dependency.
If you found the dependency, decide how to solve it.
- upgrade the dependency's version(the dependency's latest version may refer to latest issue dependency's version)
- or exclude the issue dependency from the dependency
- or follow other answers.
I'm not sure what is the best way. kindly just refer to it.
Solution 2:[2]
I fixed warning by overwriting kotlin version used in my app
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'org.jetbrains.kotlin' && requested.name == 'kotlin-reflect') {
details.useVersion kotlin_version
}
}
}
e.g. kotlin_version = 1.3.0
Solution 3:[3]
it happens when you are using the dagger in a kotlin project(android) and you have the kotlin version to be 1.7 i.e
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
all you have to do is add the dependency below to your app build gradle level
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
Solution 4:[4]
replace this
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.30'
with
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30'
the version of library should be same as plugin in project level
classpath org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30
Solution 5:[5]
Make sure you use the same version of stdlib-jdk7 & kotlin-gradle-plugin dependencies to avoid warnings.
You can refere below example where stdlib-jdk7 & kotlin-gradle-plugin both have the same version
app-level build.gradle file
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0"
...
}
project-level build.gradle file
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0"
...
}
}
Solution 6:[6]
The Kotlin version in build.gradle and the one bundled with your IDE are of different versions. Check the kotlin version in build.gradle (app) and in Tools -> Kotlin -> Configure Kotlin Plugin Updates.
Solution 7:[7]
When this happens for the Lint task, one can list the dependencies with:
./gradlew -q dependencies app:dependencies --configuration lintClassPath
Which shows that eg. kotlin-stdlib-jdk8:1.4.32 is being used:
+--- org.jetbrains.kotlin:kotlin-reflect:1.4.32 (*)
\--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32 (*)
I've wrote a Gradle script, which equalizes all the Kotlin library versions:
// Runtime JAR files in the classpath should have the same version.
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def kotlinVersion = "1.6.0"
def requested = details.requested
if (requested.group == 'org.jetbrains.kotlin') {
List<String> list = ['kotlin-stdlib', 'kotlin-stdlib-jdk7', 'kotlin-stdlib-jdk8', 'kotlin-stdlib-common']
if (list.contains(requested.name)) { details.useVersion kotlinVersion }
}
}
}
There is no other way, because some older versions are being pulled in by build tools.
One likely could also add kotlin-reflect into the List<String> list (not tested).
Solution 8:[8]
For flutter initialized project, I commented this line to refer the already available lib
dependencies {
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
and this was gone:
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
Solution 9:[9]
@Photo Point's comment from this answer is what worked for me
configurations.all {
resolutionStrategy {
eachDependency {
if ((requested.group == "org.jetbrains.kotlin") && (!requested.name.startsWith("kotlin-gradle"))) { useVersion(kotlin_version) }
}
}
}
And added app-level build.gradle file:
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Hope this helps as this drove me nuts for some time!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Vlad |
| Solution 3 | Musa Abdul Wadud |
| Solution 4 | Mubashir Murtaza |
| Solution 5 | Niral Dhameliya |
| Solution 6 | rohegde7 |
| Solution 7 | |
| Solution 8 | |
| Solution 9 | mangu23 |

