Your Flutter app was working fine. You added a package, changed a setting, or just opened the project on a new machine — and now the build is broken with a wall of red text that means nothing to you yet.
Build errors are the single biggest reason beginners give up on Flutter in the first week. Not because the errors are hard to fix — most of them have a three-command solution — but because the actual error is buried under layers of Gradle output, and beginners do not know where to look or what to search.
This guide is built around the exact error strings that appear in your terminal. Each section shows the full error message exactly as you would see it, explains what actually went wrong in plain English, and gives you copy-paste terminal commands to fix it.
Before diving into any specific error, run this sequence. It fixes a surprising number of vague build failures on its own:
flutter doctor -v
flutter clean
flutter pub get
flutter run -v
flutter doctor -v shows you exactly what is misconfigured. flutter clean deletes stale build caches. flutter pub get re-fetches all dependencies. flutter run -v gives verbose output so you can see the real error instead of the generic banner.
1. FAILURE: Build failed with an exception.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:someTask'.
> ...
* Try:
Run with --stacktrace option to get the stack trace.
What it means: This is Gradle’s generic failure banner — it is never the real error. It is always a wrapper sitting on top of a more specific failure higher in the log. Beginners waste time googling this exact string when the actual problem is 20–50 lines above it.
Flutter build logs print the generic failure at the bottom. The specific, actionable error is always higher up. When you see this banner, immediately scroll up 30–50 lines and look for the first line that says something specific — a file name, a version number, a missing class, or a permission error. That is where your fix lives.
Fix:
# Step 1: Clean stale build artifacts
flutter clean
# Step 2: Re-fetch dependencies
flutter pub get
# Step 3: Run with verbose output so the real error is visible
flutter run -v
# Step 4: Full Gradle stacktrace for the deepest detail
cd android
./gradlew assembleDebug --stacktrace
2. Finished with error: Gradle task 'assembleDebug' failed with exit code 1
Finished with error: Gradle task assembleDebug failed with exit code 1
What it means: The Android build step ran and failed. Exit code 1 is Gradle’s way of saying “something went wrong” — still a generic wrapper. Root cause is almost always a Gradle version mismatch, a plugin requiring a higher Android SDK compile version, a broken dependency, or a syntax error in your Android config files.
# Step 1: Clean and re-fetch
flutter clean
flutter pub get
# Step 2: Run verbose to find the real underlying error
flutter run -v
If verbose output reveals a Gradle version mismatch, open android/gradle/wrapper/gradle-wrapper.properties:
# android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-8.0-all.zip
If the error mentions compileSdkVersion being too low for a plugin, open android/app/build.gradle:
// android/app/build.gradle
android {
compileSdkVersion 34 // raise this if a plugin demands a higher version
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
}
}
Always check what version the failing plugin’s documentation recommends before changing
compileSdkVersion. Raising it without understanding why can introduce new compatibility problems with other plugins.
3. Running Gradle task 'assembleDebug'... (This is taking an unexpectedly long time.)
Running Gradle task 'assembleDebug'...
(This is taking an unexpectedly long time.)
What it means: Not a crash — a warning that Gradle is taking longer than Flutter expects. On a first build this is completely normal: Gradle downloads dependencies, compiles the Android toolchain, and caches everything. Subsequent builds are much faster. If you see this every time, it usually means a stuck Gradle daemon or mismatched versions causing repeated re-downloads.
# Stop all running Gradle daemons
cd android
./gradlew --stop
# Clean Flutter build cache
cd ..
flutter clean
flutter pub get
flutter run
The very first time you run a Flutter project — or the first time after a
flutter clean — Gradle downloads several hundred megabytes of tooling. This can take 5–15 minutes on a slow connection. This is expected. Once cached, subsequent builds are fast.
4. Execution failed for task ':app:compileFlutterBuildDebug'.
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command flutter' finished with non-zero exit value 1
What it means: This task compiles your Flutter/Dart code for the Android build. When it fails, the cause is almost always a dependency conflict — a package in your pubspec.yaml requires a different version of another package than what is currently installed, or a package no longer supports your current Dart/Flutter SDK version.
# Step 1: Delete the lock file so Flutter resolves fresh
rm pubspec.lock
# Step 2: Re-fetch all dependencies
flutter pub get
# Step 3: Upgrade all packages to their latest compatible versions
flutter pub upgrade
# Step 4: Check exactly what is conflicting
flutter pub deps
If a conflict is found, pin the package to a compatible version in pubspec.yaml:
# pubspec.yaml
dependencies:
flutter:
sdk: flutter
package_a: ^1.9.0 # pin to last compatible version instead of latest
5. Execution failed for task ':app:mergeDebugResources'.
Execution failed for task ':app:mergeDebugResources'.
> [path/to/resource.xml] Error: ...
AAPT: error: ...
What it means: Android’s resource merging step failed. This happens when a drawable, layout, or XML resource file is malformed — either in your own code or inside a plugin. Common causes: an XML file has invalid syntax for your minSdkVersion, a resource file name contains capital letters (Android resource names must be lowercase with underscores only), or antivirus software is blocking AAPT from accessing files.
# Step 1: Clean everything
flutter clean
flutter pub get
# Step 2: Verbose run to get the exact file and line from AAPT
flutter run -v
# Step 3: If it points to a plugin resource, update that plugin
flutter pub upgrade package_name
On Windows, antivirus software (including Windows Defender) sometimes locks files that AAPT needs to read or write. If you keep seeing this error after cleaning and the verbose log shows a permissions-related failure, try adding your Flutter project folder and the Android SDK folder to your antivirus exclusion list.
6. Unable to locate Android SDK.
Unable to locate Android SDK.
Please run the Android Studio SDK Manager and install the required SDK,
or set the ANDROID_HOME environment variable to the path of the Android SDK.
What it means: Flutter cannot find the Android SDK on your machine. We have a dedicated guide for this: How to Fix “Unable to Locate Android SDK” in Flutter. Below is the quick version.
Step 1 — Find your SDK path in Android Studio: Settings → Appearance & Behavior → System Settings → Android SDK. Copy the path shown at the top.
# Point Flutter directly to your SDK path
flutter config --android-sdk /path/to/your/android/sdk
# Verify
flutter doctor -v
Set the environment variable permanently (macOS / Linux):
# Add to ~/.zshrc or ~/.bashrc
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
# Reload your shell
source ~/.zshrc
7. Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
Some Android licenses not accepted.
To resolve this, run: flutter doctor --android-licenses
What it means: The Android SDK is installed but the license agreements have not been accepted. The Android SDK toolchain checks for accepted licenses before it starts — every single build attempt will fail until you run the acceptance command.
# Accept all Android licenses
flutter doctor --android-licenses
# Type y and Enter for each prompt, then verify
flutter doctor -v
If the command fails with a permissions error (common when Android Studio was installed as admin):
# macOS / Linux
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
# Windows (run in an elevated Administrator terminal)
%ANDROID_HOME%cmdline-toolslatestbinsdkmanager --licenses
This is not a warning you can ignore and build anyway. Every single build attempt will fail with the same error until you complete the acceptance process.
8. Error: No pubspec.yaml file found.
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
What it means: You ran a Flutter command from a folder that is not the root of a Flutter project. This is almost always a folder navigation mistake — you opened a terminal in your home directory, cd-ed into android/ or lib/ instead of the project root, or cloned a repo where the Flutter project is inside a subdirectory.
# Check where you currently are
pwd
# List files — you should see pubspec.yaml here
ls
# If you don't see pubspec.yaml, navigate to your project root
cd /path/to/your/flutter/project
# Confirm it is there
ls pubspec.yaml
# Then run your command
flutter pub get
flutter run
The project root is the folder that directly contains
pubspec.yaml, lib/, and android/. Not inside lib/. Not inside android/. Exactly the folder where pubspec.yaml lives. When in doubt, run ls first.
9. This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered.
Warning: This version only understands SDK XML versions up to 2 but an
SDK XML file of version 3 was encountered. This can occur if you use a
more recent SDK than the one bundled with your IDE.
What it means: Your Android SDK tools are older than the XML schema version the newer SDK components use. This is a version skew problem — most often caused by updating SDK packages through the command line while leaving Android Studio’s bundled command-line tools at an older version.
# Step 1: Update Android Studio via Help > Check for Updates
# Step 2: In SDK Manager, update:
# - Android SDK Command-line Tools (latest)
# - Android SDK Build-Tools (latest)
# - Android SDK Platform-Tools (latest)
# Step 3: Clean and rebuild
flutter clean
flutter pub get
flutter run
# Or update via command line
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --update
flutter doctor -v
Android SDK build tools, platform tools, and command-line tools are designed to work together at matching versions. When you update Android Studio, let it update all SDK components at the same time rather than picking individual packages.
10. Exception: Build process failed.
Exception: Build process failed.
at throwToolExit (lib/src/base/common.dart)
at ...
What it means: Another broad wrapper error. The most common underlying causes are: corrupted pub cache, mismatched Dart/Flutter SDK versions, a broken plugin, or an incompatible Kotlin version.
# Full clean and cache repair sequence
flutter clean
flutter pub cache repair
flutter pub get
flutter run -v
If verbose output points to a Kotlin version problem, open android/build.gradle:
// android/build.gradle
buildscript {
ext.kotlin_version = '1.9.0' // update this if a plugin requires newer Kotlin
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
11. General Debug Strategy for Any Flutter Build Error
When you hit a build error that is not in this list — or the fixes above did not resolve it — use this decision tree every time:
| Step | Command | What it does |
|---|---|---|
| 1. Diagnose | flutter doctor -v | Shows every misconfiguration in your environment |
| 2. Clean | flutter clean | Deletes all build artifacts — fixes most stale-cache errors |
| 3. Re-fetch | flutter pub get | Re-downloads and links all dependencies from scratch |
| 4. Verbose run | flutter run -v | Exposes the real sub-error hidden under generic banners |
| 5. Repair cache | flutter pub cache repair | Fixes corrupted packages in the global pub cache |
| 6. Gradle stacktrace | cd android && ./gradlew assembleDebug --stacktrace | Full Java stacktrace — deepest level of build error detail |
| 7. Check Flutter version | flutter --version | Confirm you are on stable channel; try flutter upgrade if outdated |
When you hit an unfamiliar error, copy the most specific line from the log (not the generic “Build failed” banner) and paste it into Google with the word “Flutter” in front. The exact error string almost always has a Stack Overflow thread with a working answer.
Quick Reference: All 10 Errors and Their First Fix
| # | Error (shortened) | First Command to Try |
|---|---|---|
| 1 | FAILURE: Build failed with an exception | flutter run -v |
| 2 | assembleDebug failed with exit code 1 | flutter clean && flutter pub get |
| 3 | assembleDebug taking unexpectedly long | cd android && ./gradlew --stop |
| 4 | compileFlutterBuildDebug failed | rm pubspec.lock && flutter pub get |
| 5 | mergeDebugResources failed | flutter clean then check XML files |
| 6 | Unable to locate Android SDK | flutter config --android-sdk <path> |
| 7 | Android licenses not accepted | flutter doctor --android-licenses |
| 8 | No pubspec.yaml file found | cd to the project root folder |
| 9 | SDK XML version mismatch | Update Android Studio + SDK tools together |
| 10 | Exception: Build process failed | flutter pub cache repair |
12. Related Posts
| Post | Why it’s relevant |
|---|---|
| How to Fix “Unable to Locate Android SDK” in Flutter | The full deep-dive on Error #6 — step-by-step SDK path setup, environment variables, and flutter doctor fixes. |
| Flutter Tutorial for Beginners: From Install to First App | If your build errors are coming from a fresh install, start here — correct setup from scratch avoids most of the errors in this guide. |
| Flutter for Beginners in 2026: Everything You Need to Know | The big picture guide — covers what Flutter is, how the toolchain fits together, and why Android SDK setup matters. |
| Building a Notes App in Flutter – Part 1 | A real project to build once your environment is working — the best way to confirm your build setup is fully fixed. |
| Hot Reload vs Hot Restart in Flutter | Once your build is fixed and your app is running, understand the development tools that let you iterate fast without rebuilding every time. |

Pingback: Flutter FutureBuilder Explained: Loading Data from an API (Beginner Tutorial)
Pingback: Flutter 3.41 Release Notes (2026): What's New for Beginners - Flutter for beginners