Flutter says Gradle failed to produce an .apk file, but the build finished
Gradle build failed to produce an .apk file.Short answer
Gradle did build; the Flutter tool just could not find the file under the name it expects, which is app-<flavor>-<buildType>.apk in the flutter-apk folder. The usual reasons are a flavored app built without the matching --flavor option, or a Gradle script that renames the APK. List the real files first, then compare.
Fix it fast
1Find out which cause you have
List every APK Gradle really wrote, and compare each name with app-release.apk (or app-<flavor>-<buildType>.apk when the app has flavors). The difference is the cause.
find build/app/outputs -name "*.apk" grep -n -A10 "productFlavors" android/app/build.gradle*2Match what you see, then jump to its fix
What does the error look like?
Gradle build failed to produce an .apk file.but the tool couldn't find it.
Cause 1 of 2
The app has flavors, but the build did not name one
1Check
The tool builds the expected file name from the build type and the flavor, lower-cased, and fails when that exact file is missing. With flavors defined and no --flavor, the name it expects has no flavor in it.
grep -n -A10 "productFlavors" android/app/build.gradle*
find build/app/outputs -name "*.apk"2Fix
Pass the name of the product flavor on every run and build command. The name must be the one in productFlavors.
flutter run --flavor staging
flutter build apk --flavor staging3Verify
The build finishes and the APK is listed under the flutter-apk folder with the flavor in its name.
ls build/app/outputs/flutter-apk/Confirmed by docs.flutter.dev
Cause 2 of 2
A Gradle script renamed the APK
1Check
The Flutter tool checks for the exact expected path after Gradle finishes and gives up if the file does not exist. Search the Android build files for any code that sets the output file name.
grep -n "outputFileName\|applicationVariants" android/app/build.gradle*2Fix
Remove the renaming from android/app/build.gradle(.kts) and rename after the build instead.
flutter build apk
mkdir -p dist
cp build/app/outputs/flutter-apk/app-release.apk dist/my-app-1.0.0.apk3Verify
flutter build apk completes and prints the path of the APK it built.
flutter build apkConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Treat the flavor name as part of the build command in scripts, CI jobs and IDE run configurations, so every one of them passes --flavor.
- Do not set custom APK names inside the Gradle files; rename the file in the release script after flutter build.
- After changing android/app/build.gradle, run flutter clean once, as Flutter's release guide advises after editing Gradle files.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
flutter run hangs for minutes on Running Gradle task 'assembleDebug'
Downloading https://services.gradle.org/distributions/gradle-8.14-all.zip
That line only says Gradle started; the wait is inside Gradle.
3 causes, each with a fixMobile apps
Google Play says the app does not support 16 KB memory pages
check_elf_alignment.sh reports UNALIGNED for a library under lib/arm64-v8a
Google Play requires apps that target Android 15 or higher and ship native .so libraries to run on devices with 16 KB memory pages; from 1 February 2027 it will block updates that do not.
5 causes, each with a fixMobile apps
Gradle cannot find com.google.firebase:firebase-analytics-ktx
Required by: project :app
Firebase moved the Kotlin extensions into the main modules and stopped releasing the -ktx modules in July 2025.
2 causes, each with a fixMobile apps
Gradle cannot create LibraryVariantBuilderImpl in a Flutter Android build
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl
This error appears when the Android Gradle plugin (AGP) cannot run in the Gradle or IDE you use.
3 causes, each with a fixMobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fix