Your Flutter app looks beautiful on the simulator. You've spent weeks perfecting the UI and logic. It's time to test on a real device or submit the project. You type `flutter build apk` into the terminal.
Instead of a success message, you get a massive wall of red text ending with `Execution failed for task ':app:assembleRelease'` or `Exit code 1`.
Building for release triggers code minification, strict type checking, and Gradle compilation steps that are skipped during debug mode. In this guide, I'll show you how to identify the exact cause and generate your APK successfully.
TL;DR - Most Common Fixes
- 1Run `flutter clean` and `flutter pub get`.
- 2Check for AndroidX incompatibilities in your `pubspec.yaml` plugins.
- 3Ensure your `compileSdkVersion` and `targetSdkVersion` in `android/app/build.gradle` are up to date (usually 33 or 34).
Root Causes
Outdated Gradle or Kotlin Versions
Flutter plugins update frequently and require newer versions of Android build tools. If your project was created months ago, your `android/build.gradle` files might be too old to compile modern plugins.
compileSdkVersion Mismatch
A plugin in your `pubspec.yaml` might require Android API level 34, but your app is configured to compile against API level 31.
Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in libraryNull Safety Conflicts
You are using a package that does not support sound null safety, and you are trying to build the app without the proper flags.
Step-by-Step Fix Guide
Read the Real Error
The command `flutter build apk` often hides the actual Android error. Run the build with verbose logging to see exactly which Gradle task is failing.
flutter build apk -vUpdate compileSdkVersion
Open `android/app/build.gradle` and ensure your versions match Google Play requirements.
android {
compileSdkVersion 34 // Update this
defaultConfig {
minSdkVersion 21 // Some plugins require at least 21
targetSdkVersion 34 // Update this
}
}Clean and Rebuild
Corrupted build caches cause 50% of all APK failures. Always clear them.
flutter clean
flutter pub get
cd android && ./gradlew clean
cd ..
flutter build apkIs your Flutter app refusing to build?
If your submission deadline is imminent and you can't generate the APK, I can remotely debug your Gradle setup and fix your build errors.
Get Urgent Build FixRelated Errors
Cannot fit requested classes in a single dex file
Your app has too many methods. Enable multidex in `android/app/build.gradle` by adding `multiDexEnabled true` to defaultConfig.
Prevention Strategy
- Always run `flutter pub outdated` to check for major version jumps in your dependencies.
- If you upgrade Flutter, occasionally recreate the android folder (`flutter create .` in your project root) to get the latest boilerplate.
Still Stuck With This Issue?
Send your exact error message or deployment issue. I'll respond with a targeted fix.
Need a Deeper Fix?
Describe your full project issue below and I'll get back to you with a targeted fix.