Flutter: 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

in my case I have a multi flavor app like this:

 android {

    ...

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "flavor-type"

    productFlavors{
        development{
            dimension "flavor-type"
        }
        staging{
            dimension "flavor-type"
        }
        production{
            dimension "flavor-type"
        }
    }
}

So if you want to run app you have to write the flavor name and then the class name that hold main() function

flutter run --flavor staging -t lib/main_staging.dart

and I solved my error and built the .apk


Ok, I found that it's args in launch.json if you use vscode

enter image description here


Add below code in App label build.gradle file after buildTypes:

flavorDimensions "flavor"

productFlavors {
    staging {
        dimension "flavor"
    }
}

And Modify your Edit Configurations like below Image : enter image description here