flutter / flutter/flutter

Docs needed how to build Android app using flavors and target files

Open
#152,135 2 comments 0 reactions 0 assignees View on GitHub
d: api docs P2 platform-android team-android triaged-android
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

## Steps to Reproduce

I have a flutter app with following flavors and target main files:
- `tst - lib/main_tst.dart`
- `prod - lib/main_prod.dart`

I would like to be able to open `android` directory in Android Studio/IntelliJ and be able to run/debug/build it by providing the desired target and flavor.

There's a documentation chapter regarding running the Flutter app in the context of `android` directory [here](https://docs.flutter.dev/tools/android-studio#android-ide), but it assumes that the project does not include Android flavors and the entry point is `main.dart`. When trying to make it with different target file a following error can be seen:

```
2024-07-12T12:48:01.521+0200 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'command '/Users/dominik/fvm/versions/stable/bin/flutter''. Working directory: /Users/dominik/Projects/project/project-app Command: /Users/dominik/fvm/versions/stable/bin/flutter --quiet assemble --no-version-check --depfile /Users/dominik/Projects/project/project-app/build/app/intermediates/flutter/prodDebug/flutter_build.d --output /Users/dominik/Projects/project/project-app/build/app/intermediates/flutter/prodDebug -dTargetFile=lib/main.dart -dTargetPlatform=android -dBuildMode=debug -dTrackWidgetCreation=true -dFlavor=prod -dAndroidArchs=android-arm android-arm64 android-x64 -dMinSdkVersion=28 debug_android_application
2024-07-12T12:48:01.521+0200 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
2024-07-12T12:48:01.521+0200 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command '/Users/dominik/fvm/versions/stable/bin/flutter'.
2024-07-12T12:48:01.525+0200 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
2024-07-12T12:48:01.525+0200 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
2024-07-12T12:48:01.525+0200 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command '/Users/dominik/fvm/versions/stable/bin/flutter''
2024-07-12T12:48:02.728+0200 [ERROR] [system.err] lib/main.dart: Error: Error when reading 'lib/main.dart': No such file or directory
2024-07-12T12:48:02.838+0200 [ERROR] [system.err] Target kernel_snapshot failed: Exception
2024-07-12T12:48:02.863+0200 [ERROR] [system.err]
```

My request is to add some more information about running/building Flutter apps with non-standard target files (and flavors) to the Android Studio/IntelliJ documentation on flutter.dev.

## Version info

flutter doctor

```
❯ f doctor -v
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale pl-PL)
• Flutter version 3.22.2 on channel stable at /Users/dominik/fvm/versions/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 761747bfc5 (5 weeks ago), 2024-06-05 22:15:13 +0200
• Engine revision edd8546116
• Dart version 3.4.3
• DevTools version 2.34.3

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/dominik/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15F31d
• CocoaPods version 1.15.2

[✓] Android Studio (version 2024.1)
• 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.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.91.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.92.0

[✓] Connected device (3 available)
redacted

[✓] Network resources
• All expected network resources are available.

! Doctor found issues in 1 category.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.