Home > database >  "Gradle task assembleDebug failed with exit code 1" because "Could not find or load m
"Gradle task assembleDebug failed with exit code 1" because "Could not find or load m

Time:05-24

I'm new to flutter and I want to make the default flutter app to show up on my Android emulator. The emulator starts up fine but the process fails at "gradle task assembleDebug". I reinstalled everything ranging from Android Studio to flutter and dart and also deleting the AVD from Android Studio then creating it again but nothing seems to work. I tried a few potential fixes from youtube and google searches involving running a "gradle wrapper" command at the root directory but that doesn't work too as the root directories of all flutter apps lacks the "build.gradle" file. Flutter doctor does not show any problems.

"flutter doctor" command output:

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!

Error output in command line:

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

I get the feeling that something is missing from somewhere but I cant figure out where and how to restore the files that are missing. Also, I'm running an emulation of Pixel 2 API 30 (android x86). But that alone should not cause any problems. How do I fix this?

Edits: [Folder Structure Screenshots]

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

CodePudding user response:

Try running flutter clean in your terminal and then rebuilding the app, that's worked for me in the past.

CodePudding user response:

  1. Delete the flutter cache (/bin/cache);
  2. Delete gradlew and gradlew.bat in android folder (and in some cases android/gradle/wrapper/gradle-wrapper.jar too);
  3. Run flutter run again.

This steps worked for me.

CodePudding user response:

Could you share screenshots of your folders until we see folders like "android", "ios", "lib", "web", "windows", "build". Each time you double click a folder take a screen shot and share with us. It could be a problem of path.

  • Related