skip to Main Content

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:flutterpackagesflutter_toolsgradleflutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:flutterbinflutter.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.

10

Answers


  1. 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

    Login or Signup to reply.
  2. For me the thing was to delete android/app/build folder and run flutter clean.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. 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:srcflutter 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.

    Login or Signup to reply.
  5. 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

    Login or Signup to reply.
  6. 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.

    Login or Signup to reply.
  7. 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'
    
    Login or Signup to reply.
  8. upgrade your dependencies in your pubspec.yaml

    Login or Signup to reply.
  9. 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

    Login or Signup to reply.
  10. 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'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search