当我运行我的 flutter 应用程序时,它没有运行,这是我得到的输出消息。
Flutte Fix [!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle.
这有点奇怪,因为我检查了gradle的文档,我的gradle版本
7.5
与我拥有的java版本20.0.0
兼容
但是我的Android工作室
(Android Studio Giraffe 2022.3.1 , The latest version as of September 2023)
似乎正在考虑另一个Java版本,那就是17
。
这是我运行时的输出
java -version
Java(TM) SE Runtime Environment (build 20.0.2+9-78)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.2+9-78, mixed mode, sharing)```
And here is the output of `flutter doctor -v`
```[✓] Flutter (Channel stable, 3.13.4, on macOS 12.6.3 21G419 darwin-x64, locale en-CM)
• Flutter version 3.13.4 on channel stable at /Users/baimamboukar/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 367f9ea16b (7 days ago), 2023-09-12 23:27:53 -0500
• Engine revision 9064459a8b
• Dart version 3.1.2
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/baimamboukar/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13C100
✗ Flutter requires Xcode 14 or higher.
Download the latest version or update via the Mac App Store.
• CocoaPods version 1.11.3
[✓] 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.82.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.72.0
[✓] Connected device (3 available)
• JKM LX2 (mobile) • 192.168.43.1:5555 • android-arm64 • Android 9 (API 28)
• macOS (desktop) • macos • darwin-x64 • macOS 12.6.3 21G419 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.187
[✓] Network resources
• All expected network resources are available.```
我遇到了同样的问题,这就是我解决它的方法。
背景
flutter
将遵循以下 JDK 安装搜索条件:
1) the JDK bundled with the latest installation of Android Studio,
2) the JDK found at the directory found in the JAVA_HOME environment variable, and
3) the directory containing the java binary found in the user's path.
所以它总是首先寻找Android Studio的JDK捆绑安装。理论上,我希望能够通过以下启动配置步骤进行更新https://developer.android.com/build/jdks#jdk-android-studio或通过GUI进行更新https:// developer.android.com/build/jdks#jdk-config-in-studio.
但看起来这只会更新该特定实例的 Android Studio 的 JDK 运行配置。不是底层的“JDK 捆绑”,它保持不变。
Flutter 团队不久前在
--jdk-dir
中添加了 flutter config
选项,这会覆盖上述搜索条件。
解决方案
如果您已将首选 JDK 安装文件夹设置为
flutter config --jdk-dir=$JAVA_HOME
(或者仅指定您喜欢的任何客户文件夹),则只需运行 $JAVA_HOME