Warning "Kotlin plugin version is not the same as library version" (but it is!)

AndroidAndroid StudioGradleKotlin

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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".

Solution 3 - Android

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."

Solution 4 - Android

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.

Solution 5 - Android

[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.

Solution 6 - Android

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.

Solution 7 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeo AsoView Question on Stackoverflow
Solution 1 - AndroidSpatzView Answer on Stackoverflow
Solution 2 - AndroidyoleView Answer on Stackoverflow
Solution 3 - AndroidLucasView Answer on Stackoverflow
Solution 4 - AndroidAmit GuptaView Answer on Stackoverflow
Solution 5 - AndroidDavidView Answer on Stackoverflow
Solution 6 - AndroidAbhijeet PrasadView Answer on Stackoverflow
Solution 7 - AndroidGURPREET SINGHView Answer on Stackoverflow