5

I'm building a Flutter app that uses some packages. Some of those packages bundle a Kotlin runtime. And of course, different packages use different Kotlin runtimes. And, in addition, there's a lot of native code in my app that, of course, also depends on Kotlin. So, Kotlin is declared as a dependency in both my own app native code and the Flutter dependencies.

That leads to this message when building the release apk and appbundle:

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/roc/.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/roc/.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/roc/.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/roc/.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)
    C:/Users/roc/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.71/898273189ad22779da6bed88ded39b14cb5fd432/kotlin-stdlib-1.3.71.jar (version 1.3)
    C:/Users/roc/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.61/70dffc5f8ac5ea7c34f30deac5b9d8b1d48af066/kotlin-stdlib-jdk7-1.3.61.jar (version 1.3)
    C:/Users/roc/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.71/e71c3fef58e26affeb03d675e91fd8abdd44aa7b/kotlin-stdlib-common-1.3.71.jar (version 1.3)
    C:/Users/roc/.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/roc/.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)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

If it happened in the Android side of the app, I could just exclude Kotlin from some of my dependencies, and use the app's Kotlin version. So, only one version of Kotlin would be there. But, as this dependencies are not in Android's build.gradle but in Flutter's pubspec.yaml, I don't know how to tell dart pub to exclude the Kotlin runtime and use the app's one.

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59

1 Answers1

0

For me, this issue came from audioplayers package.

I'm running Flutter 2.0.0 and audioplayers 0.20.1

My solution:

  1. Run flutter create . to update Flutter settings on the Flutter project.
  2. Update version of Kotlin and Gradle on buildscript (in file android/build.gradle). These newer versions are working for me:
buildscript {
    ext.kotlin_version = '1.4.32'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
  1. Modify a version of Gradle in android/gradle/wrapper/gradle-wrapper.properities:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
  1. Run flutter clean and/or flutter pub get. I don't know exactly why this could help, what it doesn't cost to you too much.
  2. Run your app flutter run or flutter --no-sound-null-safety if you have a mix of packages or/and your own code without null safety.

(Optional) Clean all folders and files inside your_user_home_path/.gradle/caches/ directory.


  • You can try other Kotlin and Gradle versions. To get inspiration, run different a Flutter project for each different Flutter SDK version and look at android/build.gradle and gradle-wrapper.properities.
  • New Flutter versions (probably from 2.9.0) will require Kotlin 1.5.31. Read it here https://docs.flutter.dev/release/breaking-changes/kotlin-version
Guillem Puche
  • 1,199
  • 13
  • 16