300

I have an Android studio project in which I have added a Java library module, which I call core. My three Gradle build files look like this.

project/build.gradle

buildscript {
    ext.kotlin_version = '1.2.40'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

core/build.gradle

apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies { 
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
    ...
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android { ... }

dependencies {
    implementation project(':core')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    testImplementation 'junit:junit:4.12'
}

The problem I have is that, in core/build.gradle, the kotlin-stdlib-jdk7 line is giving me the warning Plugin version (1.2.40) is not the same as library version (jdk7-1.2.40). I have tried changing it to:

implementation "org.jetbrains.kotlin:kotlin-stdlib"

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.40"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

But the warning is still there. The build still runs successfully, and I know I can surpress the warning without any problems and ignore it, but I really want to know why this is happening and how I can get rid of it. I am using Android Studio 3.0.1. Does anyone know of a solution to this?

Leo Aso
  • 11,898
  • 3
  • 25
  • 46

9 Answers9

479

Starting from Kotlin 1.4 dependency on the standard library added by default:

You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.

The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.

For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script.

Link to Kotlin Gradle plugin documentation.

Spatz
  • 18,640
  • 7
  • 62
  • 66
  • 174
    this is the correct answer, e.g. you don't need `implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"` any longer – SqAR.org Jan 11 '21 at 23:48
  • 11
    So the bug is on the android studio template for a new lib or project, it brings this dependency as default. – Helton Isac Feb 17 '21 at 11:37
  • @Spatz: Could you please provide any official statements / links from Jetbrains for above change. – SVK Mar 17 '21 at 03:24
  • @SVK [Kotlin 1.4.0-RC Released](https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-released/) – Spatz Mar 17 '21 at 04:18
  • 2
    @HeltonIsac it even says to do that in official Android Studio docs: https://developer.android.com/kotlin/add-kotlin – Adam Burley Sep 26 '22 at 14:57
143

This is a bug in the Kotlin plugin. I've filed an issue in the Kotlin issue tracker. You can simply ignore the message.

EDIT: JetBrains marked the issue as a duplicate of KT-23744 "Kotlin library and Gradle plugin versions are different" inspection false positive for non-JVM dependencies".

Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
yole
  • 92,896
  • 20
  • 260
  • 197
  • 3
    KT-23744 has been marked as fixed and should be fixed in `1.3.20`. However i am still facing this issue on android studio for kotlin plugin version `1.3.20-release-Studio3.3-1`. On IntelliJ for kotlin plugin version `1.3.20-release-IJ2018.3-1`, i am not having this issue. – Weizhi Feb 03 '19 at 03:19
  • 6
    Just remove this line from your build.gradle and the warning will be gone: implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" – Mario Huizinga Dec 02 '20 at 13:38
  • 3
    Seems like we could just remove the stdlib line starting from kotlin 1.4 according to answer below. – hoso.ch Dec 29 '20 at 03:21
  • 3
    y'all need to see the below answer by @Spatz https://stackoverflow.com/a/64988522/9316730 `implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"` is no longer required – Praveen G Feb 15 '21 at 06:51
14

Solution, in my case, I got rid of the line implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" in the app level Gradle and the warning disappear As the Kotlin page says : " You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.

The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.

For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script."
cigien
  • 57,834
  • 11
  • 73
  • 112
Lucas
  • 458
  • 4
  • 6
5

You might be facing this after upgrading kotlin version, Actually, older versions are still in your caches, In this case, you need to do the following steps

  1. Invalidate cache
  2. Clean project
  3. Sync project with gradle files

Now your warning will be gone.

Amit Gupta
  • 95
  • 1
  • 5
3

[build.gradle(Module)]

dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.10'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10'
    ...
}

My project automatically added

(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.10') 

to the project build file. After moving the implementation to the module file, and removing

(implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.10')

the warning went away. The 'stdlib' needs to match the 'stdlib-jdk' in the module file.

David
  • 31
  • 1
0

I faced the same issue while using Firebase with Kotlin. I had to upgrade all the dependencies with their latest version available.

Note: have your kotlin-reflect and kotlin-stdlib versions same.

0

after many days i have solve the issue Update the kotlin_version to '1.4.32'

0

In my case, I set the version number for all modules the same as gradle of app as latest version, and problem resolved.

Sayed Abolfazl Fatemi
  • 3,678
  • 3
  • 36
  • 48
0

This is because kotlin-stdlib, you can override how the jdk versions are resolved in your app/build.gradle

Check this answer for more details.

Osama Remlawi
  • 2,356
  • 20
  • 21