简体   繁体   中英

Flutter Error - FAILURE: Build failed with an exception

Yesterday, I ran my app just for check before go to bed. Suddenly, the problem appeared and I tried almost everything in stackoverflow to fix it but none of them can solve the problem. This problem appeared literally "suddenly". I'm so confused now, because I didn't do anything before I ran the app. There were not a single change in my app after I checked the app which is 5 minutes before. But now, it just can be built whatever I do. Please give me any suggestion, and I will do it. Here is Error messages.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1156

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/Documents/flutter/bin/flutter'' 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 42s
Exception: Gradle task assembleDebug failed with exit code 1


***and here is flutter doctor result***



[✓] Flutter (Channel stable, 3.0.2, on macOS 12.3.1 21E258 darwin-x64)
    • Flutter version 3.0.2 at /Users/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cd41fdd495 (6 days ago), 2022-06-08 09:52:13 -0700
    • Engine revision f15f824b57
    • Dart version 2.17.3
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.66.0)
    • VS Code at /Users/Downloads/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • macOS (desktop)   • macos       • darwin-x64     • macOS 12.3.1 21E258 darwin-x64
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

I finally success to run the app! I just deleted all files and updated android studio, and cloned my app from github and ran again. It worked! But I really don't know what caused this problem.

Try the following steps:

First run flutter clean

then open only the android project folder using android studio, android studio will start syncing your project grade. (it may take some time depending on the internet speed)

if the android studio did not start to sync you by itself or fail during this, click the sync button.

在此处输入图像描述

return back to your flutter project run flutter pub get and try to run the app.

  • First flutter clean
  • Then run flutter pub get
  • Then run flutter pub upgrade . then try and run the dart migrate. And your build gradle for no mistakes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM