似乎从 Android studio 中升级 Android SDK 会安装不兼容的东西,我无法构建。有人知道如何解决这个废话吗?
Java SDK 似乎是 Android studio 附带的。到底如何选择新版本呢? Android studio 设置中似乎没有提供 JDK 更新/降级版本选项。
$ flutter create --platforms android
...
Your application code is in ./lib/main.dart.
The configured version of Java detected may conflict with the Gradle version in your new Flutter app.
To keep the default AGP version Gradle version 8.3, download a compatible Java version
(Java 17 <= (Java 17 <= compatible Java version < Java 21) Java version < Java 21). Configure this Java version
globally for Flutter by running:
flutter config --jdk-dir=<JDK_DIRECTORY>
Alternatively, to continue using your configured Java version, update the Gradle
version specified in the following file to a compatible Gradle version (compatible Gradle version range: 8.4 - 8.7):
/home/sir/software/.../android/gradle/wrapper/gradle-wrapper.properties
You may also update the Gradle version used by running
`./gradlew wrapper --gradle-version=<COMPATIBLE_GRADLE_VERSION>`.
See
https://docs.gradle.org/current/userguide/compatibility.html#java for details
on compatible Java/Gradle versions, and see
https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:upgrading_wrapper
for more details on using the Gradle Wrapper command to update the Gradle version
used.
似乎某些版本的intellij与某些版本的Java不兼容(我有Android Studio Ladybug | 2024.2.1 Patch 2)。 Gradle 从哪个版本开始支持 Java 21?
您可能认为集成安装程序会提供指导。但无论如何。
~/my_app$ flutter doctor -v
[✓] Flutter (Channel master, 3.27.0-1.0.pre.25, on Ubuntu 22.04.3 LTS 6.8.0-48-generic, locale en_US.UTF-8)
• Flutter version 3.27.0-1.0.pre.25 on channel master at /home/sir/software/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c667c97c3f (5 weeks ago), 2024-10-11 17:55:42 -0400
• Engine revision b39fec6d97
• Dart version 3.6.0 (build 3.6.0-334.2.beta)
• DevTools version 2.40.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /home/sir/Android/Sdk
• Platform android-35, build-tools 34.0.0
• ANDROID_HOME = /home/sir/Android/Sdk
• Java binary at: /home/sir/software/android-studio/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 14.0.0-1ubuntu1.1
• cmake version 3.25.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2024.2)
• Android Studio at /home/sir/software/android-studio
• Flutter plugin version 82.1.3
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /home/sir/software/android-studio
• Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
[✓] VS Code (version 1.85.1)
• VS Code at /usr/share/code
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] VS Code (version 1.86.0-insider)
• VS Code at /usr/share/code-insiders
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.3 LTS 6.8.0-48-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.149
[✓] Network resources
• All expected network resources are available.
互联网建议按如下方式升级 gradle(对于 Java 21 至 8.11)...但随后就消失并使用了不正确的 Java。
android$ ./gradlew wrapper --gradle-version=8.11
Welcome to Gradle 8.3!
Here are the highlights of this release:
- Faster Java compilation
- Reduced memory usage
- Support for running on Java 20
For more details see https://docs.gradle.org/8.3/release-notes.html
Starting a Gradle Daemon, 1 busy and 1 incompatible Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Build file '/home/sir/software/..../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 /usr/lib/jvm/java-11-openjdk-amd64
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.
BUILD FAILED in 22s
4 actionable tasks: 2 executed, 2 up-to-date
还有:
$ ./gradlew wrapper --gradle-version=8.7
Welcome to Gradle 8.11!
Here are the highlights of this release:
- Parallel load and store for Configuration Cache
- Java compilation errors at the end of the build output
- Consolidated report for warnings and deprecations
For more details see https://docs.gradle.org/8.11/release-notes.html
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
[Incubating] Problems report is available at: file:///home/sir/software/....app/android/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* Where:
Build file '/home/sir/software/...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 /usr/lib/jvm/java-11-openjdk-amd64
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.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.11/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 23s
4 actionable tasks: 2 executed, 2 up-to-date
您是否尝试过从
Java SE 17 Archive Downloads安装
Java 17
?
然后将当前
PATH
和JAVA_HOME
的目录替换为Java 17 directory
自从遇见你,
Android Gradle 插件需要 Java 17 才能运行。
所以你必须确保你正在使用
Java 17 SDK
。
它对我有用,方法是在安装
Java 17
并替换 system variable
PATH
和 JAVA_HOME
后重新启动计算机,并且确保我的 Flutter 项目已针对更新的环境配置进行配置。
我通过创建一个新的 Flutter 应用程序来查看更新的构建配置文件来验证它。执行上述方法后,它可以正常运行。
还可以通过执行此命令检查当前安装的 Java,
Java --版本
顺便说一句,我安装的 Java 有 LTS。
查看您的 java 安装位置,
java在哪里
如果您正在处理多个 Flutter 项目,您可以阅读此 answer
因为我通过测试特定于平台的运行时来验证 Flutter 项目中文件的正确配置。所以我可以将它用作我的实际项目的参考,特别是通过检查插件/包来查看哪些可能会导致异常。