← Articles

Switching Flutter flavors in Android Studio without the terminal

By Ann Tech · 6 October 2024

Switching Flutter flavors in Android Studio is faster than typing the full terminal command each time. Here is how to set up run configurations so switching is one click.

Creating run configurations in Android Studio

  1. Open Run → Edit Configurations (or click the configuration dropdown next to the run button)
  2. Click +Flutter
  3. Configure for each flavor:

Dev configuration:

  • Name: dev
  • Dart entrypoint: lib/main_dev.dart
  • Additional run args: --flavor dev
  • Build flavor: dev

Staging configuration:

  • Name: staging
  • Dart entrypoint: lib/main_staging.dart
  • Additional run args: --flavor staging
  • Build flavor: staging

Production configuration:

  • Name: production
  • Dart entrypoint: lib/main.dart
  • Additional run args: --flavor production
  • Build flavor: production

Click ApplyOK. The dropdown now shows all three — click to switch.

VS Code launch.json

In VS Code, configurations live in .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Dev",
      "request": "launch",
      "type": "dart",
      "program": "lib/main_dev.dart",
      "args": ["--flavor", "dev"]
    },
    {
      "name": "Staging",
      "request": "launch",
      "type": "dart",
      "program": "lib/main_staging.dart",
      "args": ["--flavor", "staging"]
    },
    {
      "name": "Production (debug)",
      "request": "launch",
      "type": "dart",
      "program": "lib/main.dart",
      "args": ["--flavor", "production"]
    },
    {
      "name": "Production (profile)",
      "request": "launch",
      "type": "dart",
      "flutterMode": "profile",
      "program": "lib/main.dart",
      "args": ["--flavor", "production"]
    }
  ]
}

Switch with Cmd+Shift+D (Mac) → select from the dropdown → F5 to run.

Adding --dart-define to the IDE config

If your flavors use --dart-define in addition to --flavor:

Android Studio: In the configuration's Additional run args field:

--flavor dev --dart-define=ENVIRONMENT=dev --dart-define=API_BASE_URL=http://localhost:3000

VS Code:

{
  "name": "Dev",
  "type": "dart",
  "program": "lib/main_dev.dart",
  "args": [
    "--flavor", "dev",
    "--dart-define", "ENVIRONMENT=dev",
    "--dart-define", "API_BASE_URL=http://localhost:3000"
  ]
}

Or use --dart-define-from-file for many values:

{
  "name": "Dev",
  "type": "dart",
  "program": "lib/main_dev.dart",
  "args": ["--flavor", "dev", "--dart-define-from-file", "config/dev.json"]
}

Making the configuration available to the team

For Android Studio, run configurations live in .idea/runConfigurations/. Check these into version control:

.idea/runConfigurations/dev.xml
.idea/runConfigurations/staging.xml
.idea/runConfigurations/production.xml

For VS Code, .vscode/launch.json is already file-based — just commit it.

Selecting a device

In Android Studio:

  • The device dropdown (top toolbar) selects target device
  • Selecting a configuration + device and pressing Run builds for that exact combination

In VS Code:

  • Cmd+Shift+PFlutter: Select Device to set the active device
  • Then run the launch configuration with F5

Running a release build from the IDE

For testing release-mode behavior without a full build:

Android Studio: Edit configuration → Build moderelease

VS Code:

{
  "name": "Staging (release)",
  "type": "dart",
  "flutterMode": "release",
  "program": "lib/main_staging.dart",
  "args": ["--flavor", "staging"]
}

Common pitfalls

Setting the flavor in Additional args but not Build flavor. In Android Studio, you need to set both the --flavor argument and the Build flavor field. Omitting the Build flavor field means the Gradle task doesn't know which variant to compile, causing a build error.

Config not appearing for teammates. Android Studio configurations in .idea/runConfigurations/ are only shared if they're committed to version control. Add the directory to git and confirm .gitignore isn't excluding it.

Launching the wrong main file. Each flavor needs its own entry point (e.g., lib/main_dev.dart). Launching lib/main.dart with --flavor dev means the main function runs production initialization, regardless of the flavor.

Sign in to like, dislike, or report.

Switching Flutter flavors in Android Studio without the terminal — ANN Tech