Sub topic 10
Building an iOS archive and IPA
This chapter assumes you have a working Flutter app, a Mac with Xcode installed, and an Apple Developer Program membership. It also assumes you know your app's bundle identifier and version settings from earlier chapters. Here you will turn a signed project into an archive and an IPA, and learn what to check when the build fails.
Archive and IPA: what you are building
An archive is an .xcarchive bundle. Xcode produces it from a release build and stores the compiled app, its debug symbols (dSYM files), and signing metadata. An IPA is the .ipa file you upload to App Store Connect or install on test devices. It is a zip file that contains the signed Runner.app.
The IPA is exported from the archive. The export step re-signs the app for a particular distribution method, such as App Store, Ad Hoc, or Enterprise. This is why one archive can produce different IPAs.
Before you build
Check these items first. Most archive failures come from one of them.
- You are on macOS. iOS archives cannot be built on Windows or Linux.
flutter doctorreports no problems in the Xcode section.- The bundle identifier in Xcode matches the app record you created in App Store Connect.
- The version and build number are set in
pubspec.yaml, for exampleversion: 1.2.0+7. - Signing is configured for the Runner target, as described in the signing chapter.
- CocoaPods dependencies are installed.
Flutter runs most of these steps for you, but a clean state helps when you see odd errors:
flutter clean
flutter pub get
cd ios && pod install && cd ..If pod install fails after a Flutter or plugin upgrade, try pod repo update first, then run pod install again.
Checking signing in Xcode
Open the workspace, not the project file:
open ios/Runner.xcworkspaceUsing Runner.xcodeproj skips the CocoaPods integration, and the build will fail with missing module errors.
In Xcode, select the Runner target and open Signing & Capabilities. For the Release configuration, check these settings:
- Team is set to your developer team.
- Bundle Identifier matches your App Store Connect record.
- Automatically manage signing is enabled, unless your team uses manual profiles.
With automatic signing, Xcode creates the distribution certificate and provisioning profile on demand. With manual signing, you pick a distribution certificate and an App Store profile yourself. Manual signing is common on CI machines.
Building with the Flutter command line
The simplest way to produce an IPA is one command:
flutter build ipa --releaseFlutter builds the Dart code in release mode, runs xcodebuild archive, and then exports an IPA using the signing settings in the project. It writes two outputs:
| Output | Location |
|---|---|
| Archive | `build/ios/archive/Runner.xcarchive` |
| IPA | `build/ios/ipa/<name>.ipa` |
The IPA name comes from the app's display name or product name. If the command succeeds, the IPA is ready to upload.
Passing build options
flutter build ipa accepts the same flags you used for Android. These are the ones you will use most:
flutter build ipa --release \
--build-name=1.2.0 \
--build-number=8 \
--dart-define=API_BASE_URL=https://api.example.com \
--obfuscate --split-debug-info=build/symbols--build-nameand--build-numberoverride the values frompubspec.yaml. They are useful on CI, where the build number often comes from the pipeline.--dart-definesupplies compile-time values read byString.fromEnvironment.--obfuscatewith--split-debug-infohides Dart symbol names and writes the mapping files to the folder you name. Keep that folder. You need it to decode crash stack traces.
Choosing an export method
By default, Flutter exports for App Store distribution. You can change this with --export-method:
flutter build ipa --export-method ad-hocValid values are app-store, ad-hoc, development, and enterprise. Ad Hoc and development IPAs install only on devices registered in your provisioning profile.
For full control, you can pass your own export options file:
flutter build ipa --export-options-plist=ios/ExportOptions.plistAn export options file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
<key>teamID</key>
<string>ABCDE12345</string>
<key>signingStyle</key>
<string>automatic</string>
<key>uploadSymbols</key>
<true/>
</dict>
</plist>Replace ABCDE12345 with your own team ID. You can find it in your Apple Developer account under Membership details.
Archiving in Xcode instead
You can also build the archive in the Xcode interface. This is helpful when you want to inspect signing problems visually.
- Run
flutter build ios --release --no-codesignonce. This generates the Flutter configuration files that Xcode needs. - Open
ios/Runner.xcworkspace. - In the device selector, choose Any iOS Device (arm64). The Archive command is disabled when a simulator is selected.
- Choose Product > Archive.
- When the Organizer window opens, select the archive and choose Distribute App.
- Pick App Store Connect, then Upload or Export, and follow the prompts.
The Organizer also lets you inspect the archive's contents and download its dSYM files.
Uploading the IPA
You can upload the IPA in three ways.
- Transporter: a free Apple app. Drag the IPA into it and click Deliver.
- Xcode Organizer: use Distribute App as described above.
- Command line: use
xcrun altoolor the newerxcrun notarytoolfamily only where Apple documents them for your case. For App Store uploads, an App Store Connect API key withaltoolis the common scripted route:
xcrun altool --upload-app --type ios \
--file build/ios/ipa/my_app.ipa \
--apiKey YOUR_KEY_ID \
--apiIssuer YOUR_ISSUER_IDThe API key file (AuthKey_YOUR_KEY_ID.p8) must be in one of the folders altool searches, such as ~/.appstoreconnect/private_keys. After upload, the build goes through automated processing. It appears in App Store Connect once processing finishes, which usually takes several minutes.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `No profiles for 'com.example.app' were found` | Wrong team or bundle ID, or automatic signing is off | Select the team in Xcode and enable automatic signing, then rebuild |
| `Provisioning profile doesn't include signing certificate` | The distribution certificate is not on this Mac | Install the certificate with its private key, or let Xcode create a new one |
| Archive option is greyed out | A simulator is selected as the destination | Choose Any iOS Device (arm64) |
| `The sandbox is not in sync with the Podfile.lock` | Pods are out of date | Run `pod install` in `ios/` |
| Upload rejected: build number already used | The build number was not increased | Increase the number after the `+` and rebuild |
| Upload rejected: missing icon or privacy strings | Required asset or `Info.plist` key is absent | Add the asset or the usage description key and rebuild |
| `flutter build ipa` finishes but no IPA appears | Export step failed, for example from a signing mismatch | Open the `.xcarchive` in Organizer and export there to read the error |
Failure modes worth knowing
- Archive succeeds, export fails. The archive is signed with a development identity but you asked for App Store export. Make sure the Release configuration uses a distribution identity.
- Build number reuse. App Store Connect rejects any upload whose build number is not higher than earlier uploads for the same version name. Generate build numbers from CI, not by hand.
- Missing symbols for crash reports. If you obfuscate and then lose
build/symbols, you cannot decode Dart stack traces for that build. - Stale configuration. If you change the version in
pubspec.yamland Xcode still shows the old value, runflutter build ios --config-onlyorflutter clean, then rebuild so the generated files refresh.
Verifying the result
Before uploading, you can inspect the IPA. An IPA is a zip file, so list its contents:
unzip -l build/ios/ipa/my_app.ipa | headYou should see Payload/Runner.app/ inside. To check the version stored in the app, extract the file and read its property list:
unzip -p build/ios/ipa/my_app.ipa 'Payload/Runner.app/Info.plist' > /tmp/Info.plist
plutil -p /tmp/Info.plist | grep -E 'CFBundleShortVersionString|CFBundleVersion'CFBundleShortVersionString is the version name and CFBundleVersion is the build number. They should match what you set in pubspec.yaml or passed on the command line.
Exercise
You run flutter build ipa --release and the command ends with an error, but build/ios/archive/Runner.xcarchive exists. What does this tell you, and what is your next step?
Show answer
The archive step worked, so the Dart build and compilation are fine. The failure happened in the export step, which is where distribution signing is applied. Open the archive in Xcode's Organizer, choose Distribute App, and read the signing error it shows. Then fix the certificate, profile, or team setting, or supply an export options plist, and rebuild.
Exercise
App Store Connect rejects your upload because the build number was already used. Your pubspec.yaml says version: 1.2.0+7. Which command builds a new IPA with build number 8 without editing the file?
Show answer
Run flutter build ipa --release --build-number=8. The flag overrides the number after the plus sign for that build.
Exercise
Why must you open Runner.xcworkspace instead of Runner.xcodeproj when archiving in Xcode?
Show answer
The workspace includes the CocoaPods project that holds Flutter plugins and the Flutter framework. Opening only the project file leaves those dependencies out, so the build fails with missing module errors.