我正在构建一个使用一些包的 Flutter 应用程序。其中一些包 bundle 了 Kotlin 运行时。当然,不同的包使用不同的 Kotlin 运行时。此外,我的应用程序中有很多 native 代码,当然也依赖于 Kotlin。因此,Kotlin 在我自己的应用程序 native 代码和 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 运行时并使用应用程序的运行时。
最佳答案
对我来说,这个问题来自 audioplayers
包裹。
我正在运行 Flutter 2.0.0 和 audioplayers
0.20.1
我的解决方案:
flutter create .
更新 Flutter 项目的 Flutter 设置。 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"
}
}
android/gradle/wrapper/gradle-wrapper.properities
中的 Gradle 版本: distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
flutter clean
和/或 flutter pub get
.我不知道为什么这会有所帮助,它对你来说不会花费太多。 😉 flutter run
或 flutter --no-sound-null-safety
如果您有多个软件包或/和您自己的代码,但没有 null safety
. (可选)清理
your_user_home_path/.gradle/caches/
中的所有文件夹和文件目录。android/build.gradle
和 gradle-wrapper.properities
. Kotlin 1.5.31
.在这里阅读 https://docs.flutter.dev/release/breaking-changes/kotlin-version 关于android - 同一个 Flutter 应用中的多个 Kotlin 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67885993/