Flutter Android SDK Build Tools Error Fix
In this tutorial, you'll learn about Flutter Android SDK Build Tools Error Fix. We cover key concepts, practical examples, and best practices.
Your Flutter build fails with Android SDK build tools not found, Failed to find Build Tools revision, or Could not locate aapt — the Android SDK is missing required components or the Gradle configuration references an incorrect build tools version.
Step-by-Step Fix
1. Check installed Android SDK components
# Wrong: assuming SDK is complete
flutter doctor
# Right: list installed SDK components
$ANDROID_HOME/tools/bin/sdkmanager --list --verbose | grep "build-tools"
Expected <a href="/mobile/flutter/">flutter</a> doctor output showing the issue:
[!] Android toolchain - develop for Android devices
X Unable to locate Android SDK.
X Android SDK file not found: build-tools/34.0.0/aapt
2. Install the correct build tools version
# Check what version your project needs (from android/app/build.gradle)
grep "buildToolsVersion" android/app/build.gradle
# Install the required build tools
$ANDROID_HOME/tools/bin/sdkmanager "build-tools;34.0.0" "platforms;android-34"
# Also install the latest platform and tools
$ANDROID_HOME/tools/bin/sdkmanager "platform-tools" "platforms;android-34"
3. Fix Gradle configuration
// android/app/build.gradle
// Wrong: hardcoded build tools version that's not installed
android {
compileSdkVersion 34
buildToolsVersion "34.0.0" // May not be installed
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
}
}
// Right: let Gradle use the latest installed version
android {
compileSdk 34
// Remove buildToolsVersion — Gradle uses the latest installed
defaultConfig {
minSdk 21
targetSdk 34
}
}
4. Update Gradle wrapper version
# Check current Gradle version
cd android && ./gradlew --version
# Update Gradle wrapper if needed
cd android && ./gradlew wrapper --gradle-version 8.4
# In android/gradle/wrapper/gradle-wrapper.properties
# distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
5. Fix Kotlin plugin version
// android/build.gradle (project-level)
buildscript {
ext.kotlin_version = '1.9.22' // Match Flutter's Kotlin requirement
// Wrong: mismatched Kotlin version
// ext.kotlin_version = '1.7.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
6. Clean and rebuild
# Clean Flutter build artifacts
flutter clean
# Clean Android build artifacts
cd android && ./gradlew clean && cd ..
# Get packages and rebuild
flutter pub get
flutter run
Prevention
- Run
<a href="/mobile/flutter/">flutter</a> doctorto verify the Android SDK setup before starting a project. - Keep the Android SDK up to date with
sdkmanager --update. - Set
compileSdkwithoutbuildToolsVersionto use the latest installed tools. - Use the Flutter-recommended Kotlin and Gradle versions.
- Run
<a href="/mobile/flutter/">flutter</a> cleanafter SDK component updates.
Common Mistakes with android build error
- Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
These mistakes appear frequently in real-world FLUTTER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro