Repository: flutter
Issue: [Android] Not specifying the flavor does not let Flutter exit early when building.
Labels: tool,P2,team-tool,triaged-tool

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. `flutter create flavor_sample`
2. Add `productFlavors` in app/build.gradle. See the code sample.
3. Run the app on an Android device with `flutter run`
4. The process terminates with an error.
5. Now run `flutter run --flavor=<name>` and provide the name of a flavor.
6. The app is built correctly.

### Expected results

The `flutter run` invocation should exit early with a tool exit.

See also the discussion in https://github.com/flutter/flutter/issues/96514 

### Actual results

The tool encounters an exception, as seen in the logs.

### Code sample

<details><summary>Code sample</summary>

```groovy
    flavorDimensions "app"
    productFlavors {
        "dev" {
            applicationId = "com.example.flavor_sample_dev"
        }

        "production" {
            applicationId = "com.example.flavor_sample"
        }
    }
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details><summary>Logs</summary>

```console
navaronbracke@MacBook-Pro-van-Navaron flavor_sample % flutter run
Launching lib/main.dart on motorola one in debug mode...
Running Gradle task 'assembleDebug'...                             67.8s
Exception: Gradle build failed to produce an .apk file. It's likely that this file was generated under /Users/navaronbracke/Desktop/flavor_sample/build, but the tool couldn't find it.
navaronbracke@MacBook-Pro-van-Navaron flavor_sample % flutter run --flavor=dev
Launching lib/main.dart on motorola one in debug mode...
Running Gradle task 'assembleDevDebug'...                          16.5s
✓  Built build/app/outputs/flutter-apk/app-dev-debug.apk.
Installing build/app/outputs/flutter-apk/app-dev-debug.apk...        26.3s
Syncing files to device motorola one...                             80ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on motorola one is available at: http://127.0.0.1:52545/0hHyXTeHQLg=/
The Flutter DevTools debugger and profiler on motorola one is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:52545/0hHyXTeHQLg=/
W/Gralloc3(14914): mapper 3.x is not supported

Application finished.
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.0, on macOS 14.0 23A344 darwin-x64, locale
    en-BE)
    • Flutter version 3.16.0 on channel stable at
      /Users/navaronbracke/Documents/flutter
    • Upstream repository git@github.com:navaronbracke/flutter.git
    • FLUTTER_GIT_URL = git@github.com:navaronbracke/flutter.git
    • Framework revision db7ef5bf9f (2 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/navaronbracke/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/navaronbracke/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (3 available)
    • motorola one (mobile) • ZL5228NFL7 • android-arm64  • Android 10 (API 29)
    • macOS (desktop)       • macos      • darwin-x64     • macOS 14.0 23A344
      darwin-x64
    • Chrome (web)          • chrome     • web-javascript • Google Chrome
      119.0.6045.199

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>