Search code examples
javaandroidflutterkotlinintellij-idea

flutter - ERROR: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath


When running flutter build apk I get the following:

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.50/50ad05ea1c2595fb31b800e76db464d08d599af3/kotlin-stdlib-jdk7-1.3.50.jar (version 1.3)
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.50/b529d1738c7e98bbfa36a4134039528f2ce78ebf/kotlin-stdlib-1.3.50.jar (version 1.3)
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.50/3d9cd3e1bc7b92e95f43d45be3bfbcf38e36ab87/kotlin-stdlib-common-1.3.50.jar (version 1.3)
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.5.10/da6a904b132f0402fa4d79169a3c1770598d4702/kotlin-stdlib-1.5.10.jar (version 1.5)
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.5.10/c49d0703d16c6cb1526cc07b9b46486da1dd8a60/kotlin-stdlib-jdk7-1.5.10.jar (version 1.5)
    C:/Users/username/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.5.10/6b84d926e28493be69daf673e40076f89492ef7/kotlin-stdlib-common-1.5.10.jar (version 1.5)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

I have already done some of the suggestions I've found online and in this group but so far nothing have worked. In android\build.gradle:

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath "org.jetbrains.kotlin:kotlin-stdlib:1.5.10"
        classpath "org.jetbrains.kotlin:kotlin-stdlib-common:1.5.10"
        classpath "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.10"

    }
}

And in app\build.gradle:

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

I've also ran flutter pub upgrade --major-versions

I've been able to build my apk no problem before, I added workmanager to my pubsec.yaml and this issue started coming up, however I removed the package and the issue still persists. Any help appreciated I've been stuck on this for awhile!

Output of flutter doctor -v

[√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19041.1288], locale en-BZ)
    • Flutter version 2.2.2 at C:\flutter
    • Framework revision d79295af24 (4 months ago), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\username\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.2
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7665

[√] VS Code (version 1.59.1)
    • VS Code at C:\Users\kvernon\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (2 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 94.0.4606.81
    • Edge (web)   • edge   • web-javascript • Microsoft Edge 94.0.992.47

• No issues found!

Solution

  • Came back to this after having the same problem and couldn't figure out what I did the first time but basically I needed to figure out how to upgrade the gradle version in android/app/build.gradle: classpath 'com.android.tools.build:gradle:7.3.1' (I had this on 4.2.2)

    Then I had to make the same update in android/gradle/wrapper/gradle-wrapper.properties like so distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

    Then built with no errors.