"Gradle task assembleDebug failed with exit code 1" 因为 "Could not find or load main class org.gradle.wrapper.GradleWrapperMain"

"Gradle task assembleDebug failed with exit code 1" because "Could not find or load main class org.gradle.wrapper.GradleWrapperMain"

我是 flutter 的新手,我想让默认的 flutter 应用程序显示在我的 Android 模拟器上。模拟器启动正常,但进程在“gradle task assembleDebug”处失败。我重新安装了从 Android Studio 到 flutter 和 dart 的所有内容,还从 Android Studio 中删除了 AVD,然后再次创建它,但似乎没有任何效果。我尝试了一些来自 youtube 的潜在修复和 google 搜索,涉及 运行 根目录中的“gradle wrapper”命令,但这对于所有 flutter 应用程序的根目录都不起作用缺少“build.gradle”文件。 Flutter doctor 没有显示任何问题。

"flutter doctor"命令输出:

PS C:\Users\Mahmud Alam\Desktop\Programming Stuff\Flutter&Dart\newproj\firstapp> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Version 10.0.22000.675], locale en-US)
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.10)
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.67.2)
[√] Connected device (4 available)
[√] HTTP Host Availability

• No issues found!

命令行错误输出:

PS C:\Users\Mahmud Alam\Desktop\Programming Stuff\Flutter&Dart\newproj\firstapp> flutter run
Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib\main.dart on sdk gphone x86 in debug mode...
'Dart\newproj\firstapp\android\' is not recognized as an internal or external command,
operable program or batch file.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
Running Gradle task 'assembleDebug'...                             19.6s
Exception: Gradle task assembleDebug failed with exit code 1

我感觉某处丢失了某些文件,但我不知道在哪里以及如何恢复丢失的文件。另外,我是 运行 Pixel 2 API 30 (android x86) 的仿真器。但仅此一点应该不会造成任何问题。我该如何解决这个问题?

编辑:[文件夹结构截图]

在您的终端中尝试 运行 flutter clean,然后重新构建应用程序,这在过去对我有用。

  1. 删除flutter缓存(/bin/cache);
  2. 删除 android 文件夹中的 gradlew 和 gradlew.bat(在某些情况下也删除 android/gradle/wrapper/gradle-wrapper.jar);
  3. 运行再扑运行

这个步骤对我有用。

我认为这是您的 Flutter&Dart 的“&”引起的问题。