升级Android Studio至Meerkat 2024.3.1后Flutter安卓应用无法构建求助
问题描述
Windows 10环境下将Android Studio升级至Meerkat | 2024.3.1版本后,Flutter应用无法构建安卓版本,IntelliJ IDE编译时出现以下错误:
FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':assets_audio_player:compileDebugKotlin'. > Unknown Kotlin JVM target: 21 * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 4m 17s Error: Gradle task assembleDebug failed with exit code 1 Build #AI-243.22562.218.2431.13114758, built on February 25, 2025 Runtime version: 21.0.5+-12932927-b750.29 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.awt.windows.WToolkit Windows 10.0 GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation Memory: 4084M Cores: 12 Registry: ide.experimental.ui=true i18n.locale=
flutter doctor -v输出:
[√] Flutter (Channel stable, 3.24.0, on Microsoft Windows [Version 10.0.19045.5487], locale en-GB) • Flutter version 3.24.0 on channel stable at d:\Ian\Documents\sdk\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 80c2e84975 (7 months ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at C:\Users\Ian\AppData\Local\Android\sdk • Platform android-34, build-tools 32.1.0-rc1 • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.8) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools • Visual Studio Build Tools 2019 version 16.11.32002.261 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 2024.3) • Android Studio at C:\Program Files\Android\Android Studio1 • Flutter插件可在JetBrains插件市场安装 • Dart插件可在JetBrains插件市场安装 • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29) [√] IntelliJ IDEA Ultimate Edition (version 2024.3) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.3.1 • Flutter plugin version 83.0.4 • Dart plugin version 243.23654.44 [√] Connected device (4 available) • SM S906B (mobile) • R3CTA09TLMK • android-arm64 • Android 14 (API 34) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.5487] • Chrome (web) • chrome • web-javascript • Google Chrome 134.0.6998.89 • Edge (web) • edge • web-javascript • Microsoft Edge 133.0.3065.92 [√] Network resources • All expected network resources are available.
解决方案
核心原因
Android Studio 2024.3默认使用JDK 21,但当前项目依赖的Gradle插件和Kotlin版本不支持JVM target 21,导致编译失败。
方案1:升级Gradle插件与Kotlin版本
- 打开项目根目录的
android/build.gradle文件 - 更新Gradle插件到8.4.0及以上,Kotlin版本到1.9.20及以上:
buildscript { ext.kotlin_version = '1.9.20' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.4.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
- 同步项目后重新构建
方案2:指定兼容的JVM目标版本
如果暂时不想升级Gradle/Kotlin,可在android/app/build.gradle中强制设置JVM目标为17(或更低兼容版本):
android { // 其他配置... kotlinOptions { jvmTarget = '17' } }
方案3:清理构建缓存
执行以下步骤彻底清理缓存:
- 运行命令:
flutter clean - 删除项目根目录下的
.gradle文件夹和android/.gradle文件夹 - 执行
flutter pub get后重新运行flutter run
方案4:升级Flutter版本
当前Flutter版本3.24.0发布于7个月前,建议升级到最新稳定版以获得更好的Gradle 8.x兼容性:
flutter upgrade
内容的提问来源于stack exchange,提问作者Davout
相关产品推荐
相关产品推荐

