Skip to content

Flutter Android build errorFlutter: “Gradle build failed to produce an .apk file. It’s likely that this file was generated under …/build, but the tool couldn’t find it.”

flutter run or flutter build apk ends with Gradle build failed to produce an .apk file. It’s likely that this file was generated under <app_root>/build, but the tool couldn’t find it. Gradle usually succeeded. The flutter tool then looks for a file named app-<flavor>-<mode>.apk under build/app/outputs/flutter-apk, and the APK has a different name or sits in a different folder.

Short answer

If the app has Android product flavors, run with --flavor (flutter run --flavor staging). If android/app/build.gradle renames APKs (outputFileName), remove the rename or rename a copy after the build. If android/build.gradle no longer points the build folder at the project’s build directory, restore the lines from a fresh flutter create project. Then flutter clean and build again.

Why flutter can’t find the APK, and the fix

  1. 01

    Product flavors, but no --flavor

    “Replace this with the name of your Android product flavor” Flutter, Set up flavors for Android

    With flavors defined, Gradle names the files app-staging-debug.apk and so on, while flutter without --flavor looks for app-debug.apk. Pass the flavor every time, also in your IDE run configuration.

    flutter run --flavor staging
    flutter build apk --flavor production --release
  2. 02

    A custom APK file name

    On current stable Flutter, a block in android/app/build.gradle that sets outputFileName (for example to add the version) changes the name flutter expects. Remove it, or copy and rename the APK in a script after flutter build apk. Newer Flutter builds copy the APK under the expected name, so this cause fades after upgrading.

    // Groovy: remove blocks like this from android/app/build.gradle
    applicationVariants.all { variant ->
        variant.outputs.all { outputFileName = "myapp-${variant.versionName}.apk" }
    }
  3. 03

    The build folder was moved

    Flutter’s Android template sends Gradle output to the project’s top-level build folder. If those lines were removed or changed in android/build.gradle.kts (or android/build.gradle in older Groovy projects), the APK lands somewhere the tool doesn’t look. Restore them from a fresh flutter create project.

    // android/build.gradle.kts (from the Flutter template)
    val newBuildDir: Directory =
        rootProject.layout.buildDirectory
            .dir("../../build")
            .get()
    rootProject.layout.buildDirectory.value(newBuildDir)
    
    subprojects {
        val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
        project.layout.buildDirectory.value(newSubprojectBuildDir)
    }
    
    // android/build.gradle (older Groovy projects)
    rootProject.buildDir = "../build"
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }

Checked against the vendor’s docs on : Flutter: Set up flavors for Android; Flutter tool source: where flutter looks for the APK (gradle.dart); Flutter template: android/build.gradle.kts.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Android “Execution failed for task” · Flutter “:app:compileFlutterBuildDebug” failed · Gradle “Could not resolve all files” · Flutter Gradle assembleDebug failed

Questions

More on this error

Where is the APK if Gradle did build it?

With the standard template, Gradle writes it under build/app/outputs/apk/<flavor>/<mode>/ and flutter looks in build/app/outputs/flutter-apk. If it is under android/app/build instead, the build folder lines were changed. A flavor or a custom name in the file name points to the other causes.

Does the same happen with app bundles?

Yes, flutter build appbundle shows the same message for an .aab file, with mostly the same causes: a missing --flavor or a moved build folder.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.