Configure dev/staging/prod flavors and handle app signing for both platforms.
Flutter Flavors Overview
┌─────────────────────────────────────────────────────────────────────┐
│ FLAVOR ARCHITECTURE │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Dev │ │ Staging │ │ Prod │ │
│ ├─────────┤ ├─────────┤ ├─────────┤ │
│ │ .dev │ │ .staging│ │ .prod │ ← dart-define files │
│ │ API: dev│ │ API: │ │ API: │ │
│ │ DB: local│ │ staging │ │ prod │ │
│ │ BundleID: com.app.dev │ com.app.staging │ com.app │ │
│ └─────────┘ └─────────┘ └─────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
Dart Defines (Environment Config)
# lib/config/env.dart
abstract class Environment {
static const String apiBaseUrl = String.fromEnvironment('API_BASE_URL');
static const String appName = String.fromEnvironment('APP_NAME');
static const String bundleId = String.fromEnvironment('BUNDLE_ID');
static const bool enableLogging = bool.fromEnvironment('ENABLE_LOGGING');
static const String sentryDsn = String.fromEnvironment('SENTRY_DSN');
}# flutter_flavors.yaml (for flutter_flavorizr)
flavors:
dev:
app:
name: "MyApp Dev"
android:
applicationId: "com.example.myapp.dev"
icon: "assets/icons/dev/icon.png"
ios:
bundleId: "com.example.myapp.dev"
icon: "assets/icons/dev/icon.png"
ide:
android: true
ios: true
env:
API_BASE_URL: "https://dev-api.example.com"
APP_NAME: "MyApp Dev"
BUNDLE_ID: "com.example.myapp.dev"
ENABLE_LOGGING: "true"
SENTRY_DSN: ""
staging:
app:
name: "MyApp Staging"
android:
applicationId: "com.example.myapp.staging"
icon: "assets/icons/staging/icon.png"
ios:
bundleId: "com.example.myapp.staging"
icon: "assets/icons/staging/icon.png"
ide:
android: true
ios: true
env:
API_BASE_URL: "https://staging-api.example.com"
APP_NAME: "MyApp Staging"
BUNDLE_ID: "com.example.myapp.staging"
ENABLE_LOGGING: "true"
SENTRY_DSN: "https://staging@sentry.io/123"
prod:
app:
name: "MyApp"
android:
applicationId: "com.example.myapp"
icon: "assets/icons/prod/icon.png"
ios:
bundleId: "com.example.myapp"
icon: "assets/icons/prod/icon.png"
ide:
android: true
ios: true
env:
API_BASE_URL: "https://api.example.com"
APP_NAME: "MyApp"
BUNDLE_ID: "com.example.myapp"
ENABLE_LOGGING: "false"
SENTRY_DSN: "https://prod@sentry.io/123"# Install flavorizr and generate
flutter pub add flutter_flavorizr
flutter pub run flutter_flavorizrManual Flavor Setup (Android)
// android/app/build.gradle.kts
android {
flavorDimensions "environment"
productFlavors {
create("dev") {
dimension = "environment"
applicationId = "com.example.myapp.dev"
versionNameSuffix = "-dev"
resValue("string", "app_name", "MyApp Dev")
buildConfigField("String", "API_BASE_URL", "\"https://dev-api.example.com\"")
buildConfigField("boolean", "ENABLE_LOGGING", "true")
}
create("staging") {
dimension = "environment"
applicationId = "com.example.myapp.staging"
versionNameSuffix = "-staging"
resValue("string", "app_name", "MyApp Staging")
buildConfigField("String", "API_BASE_URL", "\"https://staging-api.example.com\"")
buildConfigField("boolean", "ENABLE_LOGGING", "true")
}
create("prod") {
dimension = "environment"
applicationId = "com.example.myapp"
resValue("string", "app_name", "MyApp")
buildConfigField("String", "API_BASE_URL", "\"https://api.example.com\"")
buildConfigField("boolean", "ENABLE_LOGGING", "false")
}
}
buildTypes {
getByName("debug") {
isDebuggable = true
isMinifyEnabled = false
}
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}
}Manual Flavor Setup (iOS)
# 1. Duplicate configurations in Xcode
# Project → Configurations → + → Duplicate "Debug" → "Debug-dev"
# Duplicate "Release" → "Release-dev"
# Repeat for staging, prod
# 2. Create schemes
# Product → Scheme → Manage Schemes → + → MyApp-dev
# Set Build Configuration: Debug-dev, Release-dev
# Repeat for staging, prod
# 3. Update Info.plist per flavor (or use xcconfig)// Configs/Dev.xcconfig
#include "Base.xcconfig"
APP_NAME = MyApp Dev
BUNDLE_IDENTIFIER = com.example.myapp.dev
API_BASE_URL = https://dev-api.example.com
ENABLE_LOGGING = YES// Configs/Prod.xcconfig
#include "Base.xcconfig"
APP_NAME = MyApp
BUNDLE_IDENTIFIER = com.example.myapp
API_BASE_URL = https://api.example.com
ENABLE_LOGGING = NOBuild & Run Commands
# Android
flutter run --flavor dev --dart-define=API_BASE_URL=https://dev-api.example.com
flutter build apk --flavor dev --dart-define=API_BASE_URL=https://dev-api.example.com
flutter build appbundle --flavor prod
# iOS
flutter run --flavor dev --dart-define=API_BASE_URL=https://dev-api.example.com
flutter build ios --flavor prod --dart-define=API_BASE_URL=https://api.example.com
# With flavorizr generated launch configurations:
# VS Code launch.json will have entries for each flavorSigning Configurations
// android/app/build.gradle.kts
android {
signingConfigs {
create("debug") {
storeFile = file("keystore/debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
create("release") {
storeFile = file("keystore/release.keystore")
storePassword = System.getenv("KEYSTORE_PASSWORD") ?: ""
keyAlias = System.getenv("KEY_ALIAS") ?: ""
keyPassword = System.getenv("KEY_PASSWORD") ?: ""
}
}
buildTypes {
getByName("debug") {
signingConfig = signingConfigs.getByName("debug")
}
getByName("release") {
signingConfig = signingConfigs.getByName("release")
}
}
}# Generate keystore
keytool -genkey -v -keystore keystore/release.keystore \
-alias upload -keyalg RSA -keysize 2048 -validity 10000 \
-storepass $KEYSTORE_PASSWORD -keypass $KEY_PASSWORD \
-dname "CN=MyApp, OU=Engineering, O=MyCompany, L=City, S=State, C=US"
# For Play App Signing - upload this keystore, Google manages the app signing keyiOS Code Signing
# Automatic signing (recommended for development)
# Xcode → Signing & Capabilities → Automatically manage signing
# Manual signing (for CI/CD)
# 1. Create certificates in Apple Developer Portal
# 2. Create provisioning profiles for each bundle ID
# 3. Download and install in Xcode
# 4. Export for CI:
security export -k login.keychain -t certs -f pkcs12 -o certificates.p12 -P "password"
# For Fastlane match:
# fastlane match appstore --readonly
# fastlane match development --readonlyCI/CD with Flavors
# .github/workflows/build.yml
jobs:
build-android:
strategy:
matrix:
flavor: [dev, staging, prod]
steps:
- name: Build ${{ matrix.flavor }}
run: |
flutter build apk --flavor ${{ matrix.flavor }} \
--dart-define=API_BASE_URL=${{ secrets[format('API_BASE_URL_{0}', upper(matrix.flavor))] }}
flutter build appbundle --flavor ${{ matrix.flavor }} \
--dart-define=API_BASE_URL=${{ secrets[format('API_BASE_URL_{0}', upper(matrix.flavor))] }}
build-ios:
strategy:
matrix:
flavor: [dev, staging, prod]
runs-on: macos-latest
steps:
- name: Build iOS ${{ matrix.flavor }}
run: |
flutter build ios --flavor ${{ matrix.flavor }} \
--dart-define=API_BASE_URL=${{ secrets[format('API_BASE_URL_{0}', upper(matrix.flavor))] }} \
--release --no-codesignTry It
Add flutter_flavorizr. Configure 3 flavors. Generate flavor configs. Build dev and prod APKs. Set up signing for release.
flutter pub add flutter_flavorizr
flutter pub run flutter_flavorizr
flutter build apk --flavor dev
flutter build apk --flavor prodConfigure build flavors
- Add flutter_flavorizr and configure dev/staging/prod
- Set up Android signing configs (debug + release keystore)
- Configure iOS schemes and build configurations
- Create GitHub Actions matrix build for all flavors
- Test installing dev and prod side-by-side on device
- Set up Play App Signing and TestFlight for prod flavor
Flavors let you install dev/staging/prod side-by-side. Use dart-define for compile-time constants. Android: productFlavors + signingConfigs. iOS: Xcode schemes + configurations. Automate with flavorizr. Store keystore passwords in CI secrets, never in code.
Resources
- Flutter Flavors: https://docs.flutter.dev/deployment/flavors
- flutter_flavorizr: https://pub.dev/packages/flutter_flavorizr
- Android Signing: https://developer.android.com/studio/publish/app-signing
- iOS Code Signing: https://developer.apple.com/documentation/xcode/distributing-your-app-for-beta-testing-and-releases