warning: Kotlin runtime JAR files in the classpath should have the same version

后端 未结 6 4306
花落未央
花落未央 2020-12-05 03:59

I get the following warning, but I\'m not sure where v1.0.6 resides.

Is it possible this error comes from a Kotlin library somehow including an old Kotlin version?

相关标签:
6条回答
  • 2020-12-05 04:11

    I was facing same issue but it was due to Dagger wrong injection

    0 讨论(0)
  • 2020-12-05 04:14

    It seems that your project is configured in such a way that you depend on kotlin-stdlib 1.1 and kotlin-reflect 1.0. The most likely case is that you already have an explicit dependency on kotlin-stdlib 1.1 but have no dependency on kotlin-reflect, and some other library (which you depend on) depends on kotlin-reflect 1.0.

    If that indeed is the case, the solution is to provide an explicit dependency on kotlin-reflect 1.1.

    In Maven, add this to pom.xml:

        <dependencies>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-reflect</artifactId>
                <version>1.1.0</version>
            </dependency>
        </dependencies>
    

    In Gradle, add this to build.gradle:

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-reflect:1.1.0"
    }
    

    See some info about this and related warnings in the official docs.

    0 讨论(0)
  • 2020-12-05 04:17

    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.

    1. upgrade the dependency's version(the dependency's latest version may refer to latest issue dependency's version)
    2. or exclude the issue dependency from the dependency
    3. or follow other answers.

    I'm not sure what is the best way. kindly just refer to it.

    0 讨论(0)
  • 2020-12-05 04:18

    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"
    
    0 讨论(0)
  • 2020-12-05 04:19

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

    }

    0 讨论(0)
  • 2020-12-05 04:21

    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

    0 讨论(0)
提交回复
热议问题