17

I'm trying to run the application in the android emulator but this error keeps popping.

    FAILURE: Build failed with an exception.

* Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 3m 33s
Exception: Gradle task assembleDebug failed with exit code 1

I have tried the following with no help.

flutter channel stable
flutter upgrade --force
flutter pub cache repair
flutter clean

in case anyone can help.

Community
  • 1
  • 1
sserunjogi
  • 171
  • 1
  • 1
  • 3

11 Answers11

10

Try this:

  1. Close project.
  2. Go to project repository folder.
  3. Delete all generated files, for example:
    • .dart_tool
    • .idea
    • .build
    • .flutter-plugins
    • .flutter-plugins-dependencies
    • .metadata
    • .packages

Nothing should changed in your git changes due to .gitignore file

  1. Open Android Studio again

  2. Go to File->Invalidate Caches/Restart, then invalidate caches and restart

    if your project structure is corrupted go to: File -> Close Project, close project and reopen it, it should be back to normal.

  3. Run all the necessary scripts starting with:

    flutter pub get

    dart pub get

flashrow
  • 164
  • 7
  • 2
    miracle cure here. I had an issue where my plugged in device was no longer showing in the Android Studio toolbar, but it is in flutter doctor and flutter run connects to the device but crashes. This was caused by modifying Android/build.gradle, or app/build.gradle. "Sync Now" does not register and makes device disappear from the toolbar and nothing really works. These steps restored everything - many thanks! – statHacker Feb 25 '22 at 12:28
  • 1
    i try many things but nothing will work for me, but its work like magic. so please try this when this kind of issues any one facing – DAVE chintan Nov 09 '22 at 05:37
4

For me the thing was to delete android/app/build folder and run flutter clean.

Georgii
  • 442
  • 4
  • 11
3

I had this problem in (line 1156) when I wanted to build an APK file, after almost executing solutions to solve it, finally found this command build release apk:

flutter build apk --release --no-tree-shake-icons

build apk with the lowest size:

flutter build apk --split-per-abi --no-tree-shake-icons

I could build my APK very well

2

2022 Working Solution
I got the same error after running my app on a physical device. This may happen if the compile SDK version is lower than that of the physical device. This error message is not limited just to running on physical devices however, here is the solution.

Go to android/app/build.grade
Find

android {
    compileSdkVersion 30 //Or whatever version it currently is

The change the compileSdkVersion to 31

android {
    compileSdkVersion 31

In the future, the maximum compileSdkVersion might increase, so try 32, or 33 if it doesn't work

1

upgrade your dependencies in your pubspec.yaml

0

Working solution:

Just uninstall/remove the entire flutter SDK folder and reinstall the same version of a flutter you have currently from the below link.

Flutter SDK as per version: https://flutter.dev/docs/development/tools/sdk/releases?tab=macos

After the new flutter is installed. Just do flutter clean and run the app.

Patel Pinkal
  • 8,984
  • 4
  • 28
  • 50
0

For my case, I found my code incompatible with my flutter version as I used flutter upgrade once. So I had to downgrade (delete the flutter folder manually in your src folder and extract the version that supports my code) my flutter sdk in C:\src\flutter to the version that my app supports. After running flutter clean (which just deletes the files that flashrow has mentioned) it got solved for me.

0

Try to run with the -v parameter to see a better logging console. In my case, some plugins are generating the following error:

Cannot run with sound null safety, because the following dependencies

When I saw it, I run with the option --no-sound-null-safety and I could start my app in the emulator.

Néstor
  • 570
  • 2
  • 8
  • 22
0

Apperently this seems like a null safety related issue. lowering down the Dart sdk's version from pubspec.yaml could solve this issue.

flutter channel stable
flutter upgrade
## pubspec.yaml
environment:<br>
sdk: '>=2.0.0 <3.0.0'
Lou
  • 73
  • 1
  • 8
0

I have updated version of gradle to latest.

Path : android/build.gradle(project level gradle file)

classpath 'com.android.tools.build:gradle:7.2.0'
Paras Arora
  • 605
  • 6
  • 12
0

2023 working solution

This is a problem related to dependencies that are not null safety according to pub.dev, so we got two options:

  • you discard the dependency
  • upgrade your flutter project dependencies

If you choose the second one, let's do it

  1. First close your IDE that you're working on.
  2. run this on your terminal inside your project:
flutter clean && flutter pub cache repair && flutter upgrade --force && flutter pub get && dart pub get && code .

this will remove all .dart_tool .idea .build .flutter-plugins .flutter-plugins-dependencies .metadata .packages. Then, repair cache errors and get all dependencies back to your project

After that, will open VSCode, select the device you want and run your app. Everything should be working :)