## Learning Objectives

By the end of this chapter, you will be able to:

- Prepare Flutter apps for release on Google Play and Apple App Store
- Configure signing, versioning, and build flavors for production and staging
- Run store-required checks and produce required assets (icons, screenshots, metadata)
- Automate builds and releases with CI/CD pipelines and manage rollout strategies
- Maintain post-release monitoring, updates, and compliance

1

## Release Checklist

- App bundle/APK or IPA built in release mode and code-signed.
- Versioning and build numbers incremented consistently.
- App icons, adaptive icons (Android), and launch/splash assets provided.
- Privacy policy, support URL, and contact information prepared.
- App store metadata: title, short/long descriptions, localized screenshots, feature graphics.
- Tests passing and smoke-tested release candidate on target devices.

2

## Versioning and Build Numbers

- Use semantic versioning for human-facing versionName (e.g., 1.2.3).
- Increment platform build numbers (versionCode on Android, CFBundleVersion on iOS) for each release.
- Automate version bumps in CI or via a small script and store metadata in a single source (pubspec.yaml or CI variables).

### Android Example

version: 1.2.3+45 where +45 maps to Android versionCode.

### iOS Example

Set CFBundleShortVersionString to 1.2.3 and CFBundleVersion to build number.

3

## Android Signing and Release Process

- Create a signing key (keystore) and secure it: store in your secret manager, not in repo.
- Configure key properties in android/key.properties and reference them from build.gradle or supply via CI secrets.
- Build release AAB (recommended) or APK:
  - `flutter build appbundle --release`
  - `flutter build apk --release`
- Test the generated artifact on devices and internal testing tracks prior to production rollout.

### Security Notes

Protect keystore passwords and upload keys; consider Google Play App Signing to simplify key management.

4

## iOS Signing and App Store Process

- Register bundle identifier and provisioning profiles in Apple Developer account.
- Use Xcode or the Flutter build pipeline:
  - `flutter build ipa --release` or build via Xcode for archive.
- Configure code signing with automatic signing or supply provisioning profiles and certificates via CI secrets.
- Test on physical devices and run TestFlight distribution for beta testing before App Store submission.

### Key Items

- Ensure correct entitlements (Push, Associated Domains) and update Info.plist with usage descriptions.
- Manage App Store Connect metadata, privacy declarations, and export compliance answers.

5

## Release Tracks and Rollout Strategies

- Use staged rollouts to limit exposure: internal testing, closed beta, open beta, then gradual production rollout.
- Monitor crash and performance metrics during staged rollout and pause or rollback if issues are detected.
- Apply feature flags and server-side toggles to gradually enable risky features without issuing a new binary.

6

## CI/CD for Releases

### Automation

Automate building, signing, and publishing with CI providers (GitHub Actions, Bitrise, Codemagic, Fastlane).

### Typical Pipeline Steps

1. Checkout code and install Flutter.
2. Run flutter analyze and flutter test.
3. Build release artifacts for target platforms.
4. Sign artifacts using secrets from CI secret store.
5. Upload to store (Play Console API, App Store Connect API) or to distribution services (TestFlight, Firebase App Distribution).

Use environment-specific build flavors and secrets per channel.

### Fastlane Pattern

Use Fastlane to manage codesigning, provisioning, and uploads; store credentials in CI secrets and use match or App Store Connect API for provisioning.

7

## Store Assets and Metadata

- Prepare high-quality screenshots for required device sizes and locales.
- Provide app icon variants, promotional graphics, and feature images as required.
- Craft concise, localized app descriptions and prepare a privacy policy URL.
- Fill content rating, category, and contact information accurately for compliance.

### Design Tips

- Capture screenshots that highlight the core user flows and value.
- Localize store listings for target markets to increase installs.

8

## Privacy, Compliance, and Legal

- Provide a privacy policy URL and ensure it covers data collection, storage, and sharing practices.
- Declare permissions and APIs used (camera, location, contacts) and provide justifications in store metadata and app prompts.
- Answer export compliance and encryption questions on App Store Connect correctly.
- Implement data deletion and export workflows if required by regional privacy laws.

9

## Monitoring and Post-Release Operations

- Integrate crash reporting (Sentry, Firebase Crashlytics) and analytics (Firebase Analytics, Amplitude).
- Monitor ANR, crash rate, and key user journeys after each release.
- Set up alerts for spikes in crashes or degraded performance.
- Collect user feedback and respond to critical reviews and issues quickly.

10

## Rollbacks and Hotfixes

- For critical regressions, release hotfix builds with higher build numbers and limited rollouts.
- Use server-side feature toggles to disable failing features quickly without releasing a new build.
- Maintain a changelog and use semantic releases to track hotfix vs minor/major releases.

11

## Build Flavors, Environment Config, and Secrets

- Use build flavors (Android productFlavors, iOS schemes) to separate dev/staging/prod configurations.
- Inject environment-specific variables at build time (API endpoints, feature flags) via Dart defines or platform configs.
- Keep secrets out of source control and provision them via CI secret stores or secure key management.

### Dart Define Example

    flutter build apk --release --dart-define=API_URL=https://api.example.com

12

## Automation and Release Notes

- Generate changelogs from commit messages or PR descriptions and include plain-text release notes for store submissions.
- Use CI to attach artifacts and changelogs to release tickets or GitHub Releases for auditability.
- Tag releases in version control and link artifacts to tags for reproducibility.

13

## Testing on Real Devices and Emulators

- Validate builds on a matrix of devices and OS versions representative of your user base.
- Test critical flows offline, with poor connectivity, and under constrained resources.
- Use beta testers for broader coverage; incorporate feedback before wide rollout.

14

## Common Pitfalls and Checks

- Missing or incorrect signing credentials causing build/upload failures.
- Mismatched bundle identifiers or package names between code and store configuration.
- Forgetting to increment build numbers, causing store rejections.
- Hard-coded debug flags or test endpoints left in production builds.
- Failing to include required privacy or permission explanations in Info.plist or Android manifest.

### Preflight Checklist

Verify signing, bundle ID, versions, assets, privacy policy, and app functionality in release mode before submission.

15

## Exercises

### 1. Release checklist runbook

Create a release runbook checklist for your app that covers version bumps, signing, store metadata, and post-release monitoring steps.

### 2. CI release pipeline

Implement a CI workflow that builds a release artifact and uploads it to a distribution channel (TestFlight or internal Play track). Use CI secrets for signing and document the steps.

### 3. Staged rollout and monitoring

Perform a staged rollout and set up crashlytics alerts. Simulate a regression and practice rollback or feature toggle disabling.