How to solve the error FAILURE: Build failed with an exception. * Where: Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

6,013

Solution 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

Solution 2

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

Share:
6,013
Admin
Author by

Admin

Updated on January 01, 2023

Comments

  • Admin
    Admin over 1 year

    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.

  • statHacker
    statHacker about 2 years
    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!