Sub topic 8
iOS: schemes and build configurations
Assume you can run Flutter commands, edit the ios/ folder in Xcode, and understand bundle IDs. You will connect an Xcode scheme to a Flutter flavor so that each environment can use a different app ID, name, icon, and service configuration.
How iOS selects an environment
An iOS build configuration is a named collection of build settings. Xcode includes Debug, Profile, and Release configurations by default. A scheme tells Xcode which configuration to use for actions such as Run, Test, and Archive.
For environments, create matching configuration sets:
| Environment | Run configuration | Archive configuration | Bundle ID |
|---|---|---|---|
| dev | Debug-dev | Release-dev | `com.example.myapp.dev` |
| staging | Debug-staging | Release-staging | `com.example.myapp.staging` |
| prod | Debug-prod | Release-prod | `com.example.myapp` |
You usually also create Profile-dev, Profile-staging, and Profile-prod for Flutter profile builds.
A scheme named dev is selected by Flutter when you run flutter run --flavor dev. The scheme name is case-sensitive.
Creating schemes in Xcode
Open the iOS workspace, not only the project file:
open ios/Runner.xcworkspaceIn Xcode:
- Select the
Runnerproject in the project navigator. - Select the
Runnerproject, then duplicate theDebug,Profile, andReleaseconfigurations. - Rename the copies to
Debug-dev,Profile-dev, andRelease-dev. - Repeat for
stagingandprod. - Choose Product > Scheme > Manage Schemes.
- Duplicate the existing
Runnerscheme and rename the copiesdev,staging, andprod. - Edit each scheme.
- Under Run, Test, and Profile, select the matching environment configuration.
- Under Archive, select the matching release configuration.
For example, the dev scheme should use Debug-dev when running and Release-dev when archiving. The prod scheme should use Debug-prod and Release-prod.
Keep the schemes shared if developers and CI must see them. In Manage Schemes, enable the Shared checkbox. Xcode stores shared schemes under ios/Runner.xcodeproj/xcshareddata/xcschemes/.
Storing settings in xcconfig files
An .xcconfig file is a text file containing Xcode build settings. It keeps environment values out of the project editor and makes them easier to review.
For example, a development configuration can contain:
PRODUCT_BUNDLE_IDENTIFIER = com.example.myapp.dev
APP_DISPLAY_NAME = MyApp Dev
API_BASE_URL = https://api.dev.example.com
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon-DevAssign this file to the Debug-dev, Profile-dev, and Release-dev configurations, or create one file for each configuration when their values differ.
Use the settings in Info.plist with build-setting substitution:
<key>CFBundleDisplayName</key>
<string>$(APP_DISPLAY_NAME)</string>The bundle identifier must be unique for every app that should install side by side. The display name controls the label shown under the icon. The app icon setting selects an icon set from the asset catalog.
Running and building a scheme
Use the same flavor name in the Flutter command and the Xcode scheme:
flutter run --flavor dev
flutter build ipa --flavor prodIn Xcode, select dev or prod from the scheme selector beside the Run button. Selecting a scheme in Xcode changes the native iOS settings. Passing --flavor to Flutter makes the command-line build select the same scheme.
Common errors
--flavor devfails because no shared scheme nameddevexists.- The scheme exists, but its Run action still points to plain
Debug. - The app replaces the production app because both configurations use the same bundle ID.
- An archive uses development settings because Archive still points to
Debug-dev. - CI cannot find a scheme because the scheme was not shared or was not committed.
- Signing fails because the bundle ID does not have a matching provisioning profile.
Exercise
You created a dev scheme, but flutter run --flavor dev still installs over the production app. What should you check first?
Show answer
Check that the dev configuration sets a different PRODUCTBUNDLEIDENTIFIER, such as com.example.myapp.dev, and that the dev scheme uses that configuration for Run.