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命令,报错依旧存在
更新信息:
- 在VS Code终端执行
java --version,输出显示当前Java版本为11.0.16 - 已定位问题仅出现在VS Code中,Android Studio可正常运行该应用
内容的提问来源于stack exchange,提问作者Ten Digit Grid
相关产品推荐
相关产品推荐

