我正在运行一个 flutter 项目,最近更新了一堆依赖项。 我收到此错误:
* What went wrong:
Execution failed for task ':flutter_google_places_sdk_android:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).
Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation
我已经通过 build.gradle 文件更新了以下内容,已经看到了这些问题
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
但是,我仍然收到上述错误。 这是我的扑动医生:
[✓] Flutter (Channel stable, 3.13.6, on macOS 13.2.1 22D68 darwin-x64, locale en-AU)
• Flutter version 3.13.6 on channel stable at /Users/sophiahuynh/Documents/_gitLabProjects/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ead455963c (8 weeks ago), 2023-09-26 18:28:17 -0700
• Engine revision a794cf2681
• Dart version 3.1.3
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/sophiahuynh/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Users/sophiahuynh/Library/Java/JavaVirtualMachines/jbrsdk-17.0.9/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment JBR-17.0.9+7-1087.3-nomod (build 17.0.9+7-b1087.3)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E300c
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• 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 17.0.6+0-17.0.6b829.9-10027231)
[✓] VS Code (version 1.84.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.76.0
[✓] Connected device (3 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)
• macOS (desktop) • macos • darwin-x64 • macOS 13.2.1 22D68 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159
[✓] Network resources
• All expected network resources are available.
我完全不知道自己还能做什么。任何帮助表示赞赏。谢谢!!
升级 Gradle 8.2 和 Kotlin 1.9.22 时,我遇到了同样的错误。
确保您在这里有相同的版本:
compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 }
kotlinOptions { jvmTarget = "17" }
添加您的 gralde.properties:
kotlin.jvm.target.validation.mode = IGNORE
此解决方案可能无法解决问题,但可以绕过它,直到有人修复它。
仅使用步骤1不起作用。
希望有帮助。
对我来说,通过将其添加到常规build.gradle.kts中解决了问题。
allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
kotlinOptions {
jvmTarget = "17"
}
}
...
}