当我创建新的 flutter 应用程序时,出现错误:
> FAILURE: Build failed with an exception.
* Where:
Build file '/Users/cansukaluc/flutter-projects/fortune_validator_app/android/app/build.gradle' line: 2
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Your current JDK is located in /Applications/Android Studio.app/Contents/jbr/Contents/Home
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.
* 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.
然后我用Brew安装了相关的Java版本。
brew 安装 openjdk@17
还更新了 .zshrc bash 文件中的路径变量。
导出JAVA_HOME=/opt/homebrew/opt/openjdk@17/
然后我用以下内容确认了当前版本:
java-版本
Flutter 项目仍未启动并给出相同的错误。
最后,我用这一行更新了我的 android/gradle.properties 文件:
org.gradle.java.home=/opt/homebrew/opt/openjdk@17
这有效。