185

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?

Any ideas how to fix it or at least how can I follow the suggestion to make kotlin-reflect explicit (1.1) ?

enter image description here

ycomp
  • 8,316
  • 19
  • 57
  • 95
  • FOR ANDROID DEVELOPERS WITH ERROR OCCURING AT XML UNRECOGNIZED FILE It if it in Android and thew error appears by not recognizing a xml file, you could search for some error in the xml folder files(in my case, one of the files had tag duplicated) – Aury0n Sep 13 '22 at 17:56

15 Answers15

141

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.

jpthesolver2
  • 1,107
  • 1
  • 12
  • 22
Alexander Udalov
  • 31,429
  • 6
  • 80
  • 66
57

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.

jeonghyeon kim
  • 833
  • 7
  • 9
34

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

Vlad
  • 7,997
  • 3
  • 56
  • 43
  • 1
    I added that but still gets the same error. It is driving me nut man... – Joseph Wambura Sep 07 '19 at 07:45
  • 3
    @GithithuWambura put it directly in app build.gradle without bracing in `android {}` e.g. – Vlad Sep 07 '19 at 08:18
  • 2
    /*Alternatively*/ configurations.all { resolutionStrategy { eachDependency { if ((requested.group == "org.jetbrains.kotlin") && (!requested.name.startsWith("kotlin-gradle"))) { useVersion(kotlin_version) } } } } – Photon Point Jun 06 '21 at 00:23
  • For the Gradle Kotlin DSL variant of this answer: https://stackoverflow.com/a/73257394/430128 – Raman Aug 06 '22 at 05:28
12

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"
  • I have tryed this but only changes the error message. No luck. Trying to recompile an old project turns into a nightmare! – jap1968 Jun 05 '21 at 11:15
7

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
Mubashir Murtaza
  • 327
  • 2
  • 14
6

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

}

Niral Dhameliya
  • 199
  • 3
  • 4
3

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:
3

For me in our react-native project, I just needed to add kotlinVersion = "1.6.10" to buildscript.ext in android/build.gradle file.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
        kotlinVersion = "1.6.10"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath 'com.google.gms:google-services:4.3.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        maven { url 'https://www.jitpack.io' }
    }
}
aprilmintacpineda
  • 1,114
  • 13
  • 21
  • 1
    This is what worked for me. At first i was resistant to update kotlin version, and after wasting an hour or so I decided to do so after reading this comment. – sud007 Oct 03 '22 at 19:37
2

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.

rohegde7
  • 633
  • 9
  • 15
1

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

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
1

To use the resolutionStrategy approach (see @vlad's answer https://stackoverflow.com/a/53081554/430128) with Gradle Kotlin DSL:

// this one defines it via rootProject e.g. `gradle.properties`
// change as needed
val kotlinVersion: String by rootProject

configurations.all {
  resolutionStrategy {
    force(
      "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
      "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlinVersion}",
      "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}",
    )
  }
}
Raman
  • 17,606
  • 5
  • 95
  • 112
0

@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!

mangu23
  • 884
  • 9
  • 13
0

Upgrading your own version of Kotlin in your project does the work according to the version of your dependencies used.

Worked me by upgrading kotlin from 1.5.21 to 1.6.0 after upgrading Room from 2.3.0 to 2.4.x

Itoun
  • 3,713
  • 5
  • 27
  • 47
0

Adding the code below into build.gradle inside of android{ //paste code here} worked;

lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
    }
ysnsyhn
  • 457
  • 1
  • 6
  • 12
0

I upgraded to gradle Latest Version . that's when i faced this error

So you only have to delete the old gradle folder and this will fix the issue /android/.gradle