使用android模拟器运行flutter项目时出现问题

问题描述 投票:0回答:1

在调试模式下在 IA 模拟器上的 AOSP 上启动 lib\main.dart...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open cp_settings generic class cache for settings file 'C:\Users\Faishana\Flutter_projects\healthcare_app\android\settings.gradle' (C:\Users\Faishana\.gradle\caches\8.0\scripts\a1w3xsedh8nmfinmqjxhisyir).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65

* 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 1s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using    │
│ for Gradle.                                                                                      │
│                                                                                                  │
│ If you recently upgraded Android Studio, consult the migration guide at                          │
│ https://flutter.dev/to/to/java-gradle-incompatibility.                                           │
│                                                                                                  │
│ Otherwise, to fix this issue, first, check the Java version used by Flutter by running `flutter  │
│ doctor --verbose`.                                                                               │
│                                                                                                  │
│ Then, update the Gradle version specified in                                                     │
│ C:\Users\Faishana\Flutter_projects\healthcare_app\android\gradle\wrapper\gradle-wrapper.properti │
│ es to be compatible with that Java version. See the link below for more information on           │
│ compatible Java/Gradle versions:                                                                 │
│ https://docs.gradle.org/current/userguide/compatibility.html#java                                │
│                                                                                                  │
│                                                                                                  │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

Exited (1).

这是什么问题? 怎么解决?

我尝试使用 chatgpt 但它不起作用

flutter performance compiler-errors android-emulator runtime-error
1个回答
0
投票

如果您可以生成一个最小示例(MCVE)并通过 github 或其他公共代码共享网站共享它,这将会有所帮助。我注意到的主要事情是给出了这个链接,建议您阅读:

https://docs.flutter.dev/release/writing-changes/android-java-gradle-migration-guide

错误提到“类文件主要版本 65”,即 Java 21,请参阅 https://javaalmanac.io/bytecode/versions/ .

确保您使用的是最新版本的 Android Studio,并且使用的是最新的 gradle 版本和最新的 AGP 版本。请参阅 https://developer.android.com/build/releases/gradle-plugin#updating-plugin 。另请检查 https://developer.android.com/build/jdks 了解 Java 版本相关问题。

我对 flutter 了解不多,但 Android 本身可能会遇到 Java 21 类文件的问题,具体取决于现代 API 的使用,因为大多数 Android 设备几乎不支持 Java 11。

© www.soinside.com 2019 - 2024. All rights reserved.