Sub topic 8
iOS: schemes and build configurations
This chapter covers how Xcode schemes and build configurations map onto the --flavor flag, so that one iOS project can produce a dev app and a prod app. It assumes you can open ios/Runner.xcworkspace in Xcode, you know what a bundle ID is, and you have read the chapter on the --flavor flag. The Android equivalent is productFlavors in Gradle, covered in the previous chapter.
How Flutter finds the iOS side of a flavor
Android has a first-class "flavor" object. iOS does not. Flutter builds the same idea out of two Xcode concepts.
- A build configuration is a named set of build settings. A new Flutter project has three:
Debug,ProfileandRelease. - A scheme is a named recipe that says which target to build and which build configuration to use for each action (Run, Profile, Archive and so on).
When you run flutter run --flavor dev, Flutter does two things on iOS:
- It builds the scheme named exactly
dev. - It picks the build configuration whose name combines the build mode and the flavor, such as
Debug-dev,Profile-devorRelease-dev.
So the work in Xcode is to create a scheme and three configurations for each flavor, and to name them in this pattern.
Step 1: Create the build configurations
In Xcode, open ios/Runner.xcworkspace, select the Runner project (not the target) in the navigator, and open the Info tab. Under Configurations you will see Debug, Profile and Release.
For each flavor, duplicate each of the three configurations and rename the copies:
| Original | Dev copy | Prod copy |
|---|---|---|
| Debug | Debug-dev | Debug-prod |
| Profile | Profile-dev | Profile-prod |
| Release | Release-dev | Release-prod |
The mode in the name matters. Flutter reads the mode from the configuration name to decide whether to produce a debug, profile or release build. A configuration named Staging-dev does not tell Flutter what mode it is.
After duplicating, you can delete the original Debug, Profile and Release configurations if every build will use a flavor. Keep them if some builds run without --flavor.
Step 2: Create one scheme per flavor
Open Product > Scheme > Manage Schemes. Select the Runner scheme and duplicate it. Name the copy exactly dev, matching the flavor name in lowercase as you pass it to --flavor. Then edit the scheme:
- Under Run, set Build Configuration to
Debug-dev. - Under Profile, set it to
Profile-dev. - Under Archive, set it to
Release-dev.
Repeat for prod with the -prod configurations. Finally, tick the Shared checkbox for each scheme. Shared schemes are stored in ios/Runner.xcodeproj/xcshareddata/xcschemes/, which you commit. Unshared schemes live in your user data and do not exist on a teammate's machine or on CI.
Step 3: Update the Podfile
CocoaPods needs to know how each custom configuration relates to the built-in modes. Without this, it treats unknown configurations as release builds, which can break debug builds of plugins.
Open ios/Podfile and replace the plain project 'Runner' line (or add it before flutter_ios_podfile_setup) with an explicit map:
project 'Runner', {
'Debug-dev' => :debug,
'Profile-dev' => :release,
'Release-dev' => :release,
'Debug-prod' => :debug,
'Profile-prod' => :release,
'Release-prod' => :release,
}Profile maps to :release because profile builds are optimized like release builds. Then run pod install from the ios folder, or run flutter build ios --config-only --flavor dev, so CocoaPods generates the per-configuration files.
Step 4: Put per-flavor values in xcconfig files
You could edit build settings directly in Xcode for each configuration. That scatters the values across the project file and makes diffs hard to read. A cleaner approach is one small .xcconfig file per flavor holding the values, plus one file per configuration that pulls things together.
Create ios/Flutter/dev.xcconfig:
APP_DISPLAY_NAME = MyApp Dev
BUNDLE_ID_SUFFIX = .dev
APP_ICON_NAME = AppIcon-devCreate ios/Flutter/prod.xcconfig:
APP_DISPLAY_NAME = MyApp
BUNDLE_ID_SUFFIX =
APP_ICON_NAME = AppIconThen create ios/Flutter/Debug-dev.xcconfig:
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-dev.xcconfig"
#include "Generated.xcconfig"
#include "dev.xcconfig"The first line is the CocoaPods file for that configuration. The #include? form (with a question mark) means "include it if it exists", so a missing file before pod install does not stop the build. The second line pulls in Generated.xcconfig, which Flutter writes on every build and which carries FLUTTER_ROOT, the build name and number, and your --dart-define values. Without it the build fails or loses those values.
Create the other five files the same way. For a release configuration, change debug to release in the Pods path, for example Pods-Runner.release-prod.xcconfig. CocoaPods lowercases the configuration name in these file names.
Now attach each file to its configuration. In the project's Info tab, expand each configuration, and next to the Runner target, choose the matching .xcconfig file from the dropdown. Debug-dev uses Debug-dev.xcconfig, and so on.
Step 5: Use the values in the target
The xcconfig files define variables. The target must read them. In the Runner target's Build Settings, search for these settings and edit the value for every configuration:
PRODUCT_BUNDLE_IDENTIFIERbecomescom.example.myapp$(BUNDLE_ID_SUFFIX).ASSETCATALOG_COMPILER_APPICON_NAMEbecomes$(APP_ICON_NAME).
In ios/Runner/Info.plist, change the display name entry so it reads the variable:
<key>CFBundleDisplayName</key>
<string>$(APP_DISPLAY_NAME)</string>Xcode substitutes $(...) references in Info.plist at build time. The result is that the dev build installs as com.example.myapp.dev named "MyApp Dev", and the prod build installs as com.example.myapp named "MyApp". Because the bundle IDs differ, both can be on one device at the same time. The icon needs an AppIcon-dev set in Assets.xcassets; the next chapter covers per-flavor icons in detail.
The bundle ID must also match anything tied to it: provisioning profiles, push notification entitlements, and service config files such as Firebase's GoogleService-Info.plist. A bundle ID you change here needs a matching App ID registered in your Apple Developer account before you can run on a device or upload to TestFlight.
Running and building
With the scheme, configurations and Podfile in place, the commands are the ones from earlier chapters:
flutter run --flavor dev -t lib/main_dev.dart --dart-define-from-file=config/dev.json
flutter build ipa --release --flavor prod -t lib/main_prod.dart --dart-define-from-file=config/prod.jsonflutter run --flavor dev builds with Debug-dev. Adding --release selects Release-dev, and --profile selects Profile-dev. Because appFlavor is set from the flag, appFlavor in Dart returns dev at runtime.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| "The Xcode project does not define custom schemes" or "You must specify a --flavor option" | No shared scheme, or the scheme name does not match the flavor | Share the scheme and name it exactly like the flavor |
| "Unable to find expected configuration" or a similar configuration error | Configuration names do not follow `Mode-flavor` | Rename to `Debug-dev`, `Profile-dev`, `Release-dev` |
| App builds, but shows the wrong name or ID | xcconfig not attached to the configuration, or the target still has a hard-coded value | Check the Info tab and the target's Build Settings for overrides |
| `FLUTTER_ROOT` not set, or dart-define values missing | The per-configuration xcconfig does not include `Generated.xcconfig` | Add the include line |
| Pod build errors only in the dev configuration | Podfile map missing, or `pod install` not re-run | Update the `project` map and reinstall pods |
| Both flavors replace each other on the device | Bundle IDs are identical | Set the suffix through `BUNDLE_ID_SUFFIX` |
Edge cases
- Case. Flutter compares scheme and configuration names case-insensitively when it matches modes, but keeping everything lowercase avoids confusion across tools and scripts.
- Multiple dimensions. Android supports several flavor dimensions. iOS has no equivalent, so a combination such as
devwithfreebecomes one flavor name likedevFree, with one scheme and three configurations for it. The number of configurations grows quickly, so avoid this unless you need it. - Tests and extensions. Other targets, such as
RunnerTestsor a widget extension, also need the configurations. Xcode applies the project-level configurations to every target, but each target's bundle ID and any entitlements need their own suffix handling. - Unflavored builds. If you delete the original
Debug,ProfileandReleaseconfigurations,flutter runwithout--flavorfails. Keep them, with default values, if you want plain builds to keep working.
Exercise
You created the configurations Debug-staging, Profile-staging and Release-staging and a scheme named Staging. flutter run --flavor staging fails with an error that the scheme cannot be found. Name two things to check, and say which edit to the Podfile is also required before plugins build correctly.
Show answer
First, check that the scheme name matches the flavor. The scheme is named "Staging" while the flag is "staging", so rename it to "staging" for consistency. Second, check that the scheme is marked Shared, so that it exists as a file in ios/Runner.xcodeproj/xcshareddata/xcschemes/ and is committed. The Podfile needs a project 'Runner' map listing 'Debug-staging' => :debug, 'Profile-staging' => :release and 'Release-staging' => :release, followed by a pod install.