【问题标题】:Multiple Kotlin Runtimes in the same Flutter app同一个 Flutter 应用中的多个 Kotlin 运行时
【发布时间】:2021-08-25 09:16:12
【问题描述】:

我正在构建一个使用一些包的 Flutter 应用程序。其中一些包捆绑了 Kotlin 运行时。当然,不同的包使用不同的 Kotlin 运行时。此外,我的应用程序中有很多本机代码,当然也依赖于 Kotlin。因此,Kotlin 在我自己的应用程序原生代码和 Flutter 依赖项中都被声明为依赖项。

这会导致在构建发布 apk 和 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

如果它发生在应用程序的 Android 端,我可以从我的一些依赖项中排除 Kotlin,并使用应用程序的 Kotlin 版本。所以,只有一个版本的 Kotlin 会在那里。但是,由于此依赖项不在 Android 的 build.gradle 中,而是在 Flutter 的 pubspec.yaml 中,我不知道如何告诉 dart pub 排除 Kotlin 运行时并使用应用程序的运行时。

【问题讨论】:

  • 您可能需要检查 Kotlin 版本是否相同,最重要的是 JDK 版本。
  • 你好@JendorskiLabs!对什么都一样?应用的版本是1.5.10,但是不同的Flutter包使用不同的Kotlin版本。
  • @RocBoronat 嗨伙计,你解决了这个问题吗?遇到同样的问题,已经卡了好一段时间了。谢谢
  • @TryHarder 不走运:·/

标签: android flutter kotlin dependencies


【解决方案1】:

对我来说,这个问题来自audioplayers 包。

我正在运行 Flutter 2.0.0 和 audioplayers 0.20.1

我的解决方案:

  1. 运行 flutter create . 以更新 Flutter 项目的 Flutter 设置。
  2. buildscript 上更新 Kotlin 和 Gradle 版本(在文件 android/build.gradle 中)。这些较新的版本对我有用:
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. 修改android/gradle/wrapper/gradle-wrapper.properities中的Gradle版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
  1. 运行flutter clean 和/或flutter pub get。我不知道为什么这会有所帮助,它对你来说不会花费太多。 ?
  2. 运行您的应用程序 flutter runflutter --no-sound-null-safety,如果您有多个包或/和您自己的代码,但没有 null safety

(可选)清理your_user_home_path/.gradle/caches/目录中的所有文件夹和文件。


  • 您可以尝试其他 Kotlin 和 Gradle 版本。要获得灵感,请为每个不同的 Flutter SDK 版本运行不同的 Flutter 项目,并查看 android/build.gradlegradle-wrapper.properities
  • 新的 Flutter 版本(可能从 2.9.0 开始)将需要 Kotlin 1.5.31。在这里阅读https://docs.flutter.dev/release/breaking-changes/kotlin-version

【讨论】:

  • 非常感谢,吉勒姆!我会尽快回到遭受此困扰的项目:·)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多