Sub topic 14
Automating the release pipeline
Earlier chapters built a release by hand: you set the version, signed with a keystore, built an App Bundle and an IPA, and uploaded them. This chapter turns those steps into a repeatable pipeline. It assumes you can already build a signed Android release locally, that you know what --dart-define does, and that you have used Git tags. It uses GitHub Actions for the examples. The same ideas apply to GitLab CI, Bitrise, Codemagic, and others.
Why automate releases
A manual release depends on one person's machine. The keystore sits in a home directory, the right Xcode version is installed, and the right --dart-define values are remembered from last time. Each of these is a place for a release to break or ship with the wrong backend URL.
A pipeline fixes this by running the same commands in a clean environment every time. It gives you four things:
- Reproducibility. The build starts from a fresh checkout, so a build never depends on leftover local files.
- Gates. Analysis and tests run before anything is signed or uploaded.
- Controlled secrets. Signing material lives in the CI system's secret store instead of on laptops.
- An audit trail. Every release maps to a commit, a tag, and a log.
Shape of a release pipeline
Most Flutter pipelines use the same stages. Only the signing and upload mechanics differ between Android and iOS.
Run the Android and iOS jobs separately. Android builds run on cheap Linux runners. iOS builds need macOS runners, which cost more and queue longer.
Choosing a trigger
The trigger decides when a release happens. Three common choices:
| Trigger | Typical use | Trade-off |
|---|---|---|
| Push to `main` | Internal or nightly builds | Fast feedback, but every merge produces a build. |
| Pushing a tag such as `v1.2.0` | Store releases | Explicit and traceable, and it needs a manual tagging step. |
| Manual dispatch | Hotfixes, re-running a failed upload | Flexible, and easy to run from the wrong branch. |
A tag trigger works well because the tag can supply the version name, which keeps pubspec.yaml and the release in agreement. The build number can come from the CI run counter. Both --build-name and --build-number override the values in version: 1.2.0+7, so nobody edits the build number by hand.
Keeping secrets out of the repository
The key.properties file and the keystore must never be committed. In CI you store them as encrypted secrets and rebuild the files at build time.
| Item | Where it lives in CI | How it reaches the build |
|---|---|---|
| Upload keystore (`.jks`) | Secret, Base64-encoded | Decoded to a temporary file. |
| Store and key passwords, alias | Secrets | Written into `android/key.properties`. |
| Google Play service account JSON | Secret | Passed to the upload tool. |
| App Store Connect API key (`.p8`), key ID, issuer ID | Secrets | Passed to fastlane or `xcrun`. |
| `API_BASE_URL` | Variable (not secret) | Passed with `--dart-define`. |
Create the Base64 value once on your machine:
base64 -i ~/upload-keystore.jks | pbcopy # macOS
base64 -w 0 ~/upload-keystore.jks # LinuxPaste the output into a repository secret named UPLOAD_KEYSTORE_BASE64.
An Android release workflow
The following workflow runs on a version tag. It verifies the code, restores the keystore, builds an obfuscated App Bundle, and saves the bundle and symbols as artifacts. It reuses the Gradle signing configuration from the signing chapter, which reads android/key.properties.
# .github/workflows/release-android.yml
name: release-android
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- run: flutter pub get
- run: flutter analyze
- run: flutter test
- name: Restore upload keystore
env:
KEYSTORE_BASE64: ${{ secrets.UPLOAD_KEYSTORE_BASE64 }}
run: echo "$KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/upload-keystore.jks"
- name: Write key.properties
env:
STORE_PASSWORD: ${{ secrets.UPLOAD_STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.UPLOAD_KEY_PASSWORD }}
run: |
cat > android/key.properties <<EOF
storePassword=$STORE_PASSWORD
keyPassword=$KEY_PASSWORD
keyAlias=upload
storeFile=$RUNNER_TEMP/upload-keystore.jks
EOF
- name: Build App Bundle
run: |
flutter build appbundle --release \
--build-name="${GITHUB_REF_NAME#v}" \
--build-number="${{ github.run_number }}" \
--obfuscate --split-debug-info=build/symbols \
--dart-define=API_BASE_URL="${{ vars.API_BASE_URL }}"
- uses: actions/upload-artifact@v4
with:
name: android-release
path: |
build/app/outputs/bundle/release/app-release.aab
build/symbols
- name: Remove signing files
if: always()
run: rm -f android/key.properties "$RUNNER_TEMP/upload-keystore.jks"Four details in this workflow matter:
${GITHUB_REF_NAME#v}strips the leadingv, so the tagv1.2.0becomes the version name1.2.0.github.run_numberincreases with every run of this workflow, so each upload has a higher build number than the last. Google Play rejects a version code it has already seen.- The symbols folder is uploaded as an artifact. Without it, stack traces from the obfuscated build cannot be decoded later.
- The cleanup step uses
if: always()so the signing files are removed even when a build step fails. On GitHub-hosted runners the machine is discarded anyway. On self-hosted runners this step matters.
Uploading from the pipeline
Building an artifact is half the job. Uploading it needs credentials that identify your automation to each store.
For Google Play, create a service account in Google Cloud, grant it access to the app in Play Console, and store its JSON key as a secret. Many teams use fastlane for the upload because one tool covers both stores. The first upload of a new app often has to be done through the Play Console by hand, so plan for that before you rely on the pipeline.
For App Store Connect, create an API key under Users and Access. This key lets automation upload builds without an Apple ID password or two-factor prompts.
A minimal fastlane/Fastfile with one lane per store:
# fastlane/Fastfile
default_platform(:android)
platform :android do
lane :internal do
upload_to_play_store(
track: 'internal',
aab: File.expand_path('../build/app/outputs/bundle/release/app-release.aab', __dir__),
json_key_data: ENV['PLAY_SERVICE_ACCOUNT_JSON']
)
end
end
platform :ios do
lane :beta do
api_key = app_store_connect_api_key(
key_id: ENV['ASC_KEY_ID'],
issuer_id: ENV['ASC_ISSUER_ID'],
key_content: ENV['ASC_KEY_P8']
)
upload_to_testflight(
api_key: api_key,
ipa: File.expand_path('../build/ios/ipa/my_app.ipa', __dir__),
skip_waiting_for_build_processing: true
)
end
endReplace my_app.ipa with the name your build produces under build/ios/ipa. Uploading to the internal track is a safe default. Promoting a build to production stays a deliberate step in the Play Console or a separate manual workflow.
The iOS side
The iOS job runs on a macOS runner and calls flutter build ipa --release with the same --build-name, --build-number, and --dart-define flags. The hard part is code signing, because a fresh runner has no certificate or provisioning profile. There are two common approaches:
- Automatic signing with an API key. Xcode can create and fetch certificates and profiles using the App Store Connect API key. This is the least setup, but it can create new certificates unexpectedly.
- fastlane match. Certificates and profiles are stored encrypted in a private Git repository or cloud bucket. Each runner downloads the same ones. This is more setup and gives the most predictable results.
Whichever approach you pick, the runner needs a temporary keychain, because macOS will not let a headless job use the login keychain without a prompt. Most CI platforms and fastlane's setup_ci action create and unlock one for you.
Common failures
- Version code already used. The build number did not increase. This often happens when you migrate to a new CI system whose run counter restarts at 1. Start the counter above your last uploaded number, or compute the number as
run_number + offset. - Signing config not found. The
key.propertiesfile was written to the wrong path, orstoreFilepoints to a path that does not exist on the runner. - Works locally, fails in CI on
flutter analyze. The CI runner uses a different Flutter version. Pin the version insubosito/flutter-actionwithflutter-versioninstead of thestablechannel when you need exact reproducibility. - iOS build fails with "No signing certificate". The keychain was not unlocked or the profile did not download. Check that the bundle identifier matches the profile.
- Obfuscated crash reports are unreadable. The symbol files were not archived. Store them for every release and keep them as long as that version is in use.
Exercises
Exercise
Your workflow builds with --build-number="${{ github.run_number }}", but the team moves to a different CI provider whose run counter starts at 1. The last build uploaded from the old system had build number 214. What happens on the next upload, and how do you fix it?
Show answer
Google Play and App Store Connect reject a build number that is not higher than a previous upload for the same version, so the new pipeline's early builds would fail. Fix it by adding an offset, for example $((RUN_NUMBER + 214)), or by seeding the new counter above 214.
Exercise
Why does the workflow write key.properties and the keystore during the job instead of committing them, and why is the cleanup step marked if: always()?
Show answer
Committing signing material exposes it to anyone with repository access and keeps it in Git history. Storing it as encrypted secrets and writing it at build time limits exposure to the job. The cleanup step runs even when an earlier step fails, so the files are not left on a runner, which matters most on self-hosted runners.
Exercise
A crash report from a pipeline-built release shows only lines like package:my_app/... +0x4f2a3. What was skipped in the pipeline, and what do you need to read the trace?
Show answer
The build used --obfuscate, so stack frames are not readable without the matching symbol files from --split-debug-info. The pipeline must archive build/symbols for each release. Then you can decode the trace with flutter symbolize against the symbol file from that exact build.