You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac端VS Code中Flutter应用Gradle构建报错:Java版本不符

Mac端VS Code运行Flutter应用Java版本适配问题

在Mac端使用VS Code运行Flutter应用时,抛出以下Gradle报错:

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-all.zip'.
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android'.
A problem occurred configuring root project 'android'.
A problem occurred evaluating root project 'android'.
A problem occurred configuring project ':app'.
A problem occurred evaluating project ':app'.
Failed to apply plugin 'com.android.internal.application'.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
  - changing the IDE settings.
  - changing the JAVA_HOME environment variable.
  - changing `org.gradle.java.home` in `gradle.properties`.

已执行的排查操作:

  • 下载最新Java并在Android Studio中更新配置,报错次数从重复变为单次,但问题未解决
  • 修改项目的gradle.properties文件,添加通过终端命令/usr/libexec/java_home -v 11获取的Java路径(实际配置为JDK18路径),配置内容如下:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
  • 执行flutter clean和flutter pub get命令,报错依旧存在

更新信息:

  1. 在VS Code终端执行java --version,输出显示当前Java版本为11.0.16
  2. 已定位问题仅出现在VS Code中,Android Studio可正常运行该应用

内容的提问来源于stack exchange,提问作者Ten Digit Grid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 21:06:24