iOS and Android releases with fastlane and GitHub Actions
Ship iOS and Android builds from a git tag with fastlane and GitHub Actions: match signing, store build numbers, CI secrets and Flutter-specific lanes.
On this page
When I push a version tag, CI runs a Fastfile that takes the build all the way to TestFlight and the Play internal track. On iOS that means match for signing, an App Store Connect API key instead of an Apple ID, a build number read from TestFlight, then build_app and upload_to_testflight. On Android it is a Gradle bundle, a version code read from Google Play and an upload to the internal track. I still handle release notes, review submission and the staged rollout by hand.
A release should not depend on one laptop
Done by hand, a release depends on one person's machine: their certificates, their Xcode, their copy of the keystore. When that person is away, nobody ships. Once it lives in a Fastfile, the release is code that goes through pull requests, and CI is the only machine that needs signing material.
I have run this setup with fastlane and GitHub Actions on a banking app, and the same lanes work from GitLab CI or any runner with Ruby. The layout is one fastlane/ folder at the repository root with a platform :ios and a platform :android block, and a Gemfile that pins fastlane so laptops and CI run the same version through bundle exec fastlane.
For an internal app that ships twice a year, I wouldn't bother. Xcode Organizer and the Play Console are enough. The setup starts paying for itself once you release monthly, or once more than one person has to be able to release.
The iOS lane: match, API key, TestFlight
platform :ios do
desc "Build the app and upload it to TestFlight"
lane :beta do
setup_ci # temporary keychain when running on CI
api_key = app_store_connect_api_key(
key_id: ENV.fetch("ASC_KEY_ID"),
issuer_id: ENV.fetch("ASC_ISSUER_ID"),
key_content: ENV.fetch("ASC_KEY_P8_BASE64"),
is_key_content_base64: true
)
match(type: "appstore", readonly: true, api_key: api_key)
build_number = latest_testflight_build_number(
api_key: api_key,
initial_build_number: 0
) + 1
increment_build_number(build_number: build_number, xcodeproj: "ios/App.xcodeproj")
build_app(workspace: "ios/App.xcworkspace", scheme: "App", export_method: "app-store")
upload_to_testflight(api_key: api_key, skip_waiting_for_build_processing: true)
end
endsetup_ci creates a temporary keychain on CI. Without it, certificates land in the runner's login keychain and codesign can stall on an access prompt nobody will answer.
The API key replaces Apple ID login, so there is no two-factor prompt and no session expiring halfway through a release. is_key_content_base64 lets the .p8 file live in a single-line secret.
match runs in readonly mode and only downloads certificates and profiles from the encrypted repository. Creating or renewing them is something I do on purpose, from my own machine. It is never a side effect of CI.
The build number comes from TestFlight. CI run numbers and commit counts reset or shift when a workflow is renamed or history is squashed, so I don't use them. increment_build_number relies on agvtool, which means the target needs the "Apple Generic" versioning system.
skip_waiting_for_build_processing ends the job as soon as the upload is accepted, because macOS minutes cost more than Linux ones. The price is that external testers can't get the build in the same run.
The Android lane: the version code comes from Play
platform :android do
desc "Build an AAB and upload it to the internal track"
lane :internal do
package = "com.example.app"
json_key = ENV.fetch("PLAY_JSON_KEY")
codes = %w[internal alpha beta production].flat_map do |track|
google_play_track_version_codes(
package_name: package, track: track, json_key_data: json_key
)
end
version_code = (codes.max || 0) + 1
gradle(
project_dir: "android",
task: "bundle",
build_type: "Release",
properties: { "versionCode" => version_code }
)
upload_to_play_store(
package_name: package,
json_key_data: json_key,
track: "internal",
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
end
endGoogle Play rejects any version code it has already seen, on any track, so the lane takes the highest code across every track I use and adds one. A code burned by a discarded draft doesn't show up in google_play_track_version_codes and can still collide. The error is explicit when that happens, and a one-off manual bump fixes it.
Gradle receives the code as a project property. In build.gradle.kts, versionCode = (findProperty("versionCode") as String?)?.toInt() ?: 1 keeps local builds working without it. upload_to_play_store picks up the AAB path that gradle stored in the lane context, so no output path is hard-coded.
Two pitfalls. An app that has never been published only accepts release_status: "draft"; the default, completed, fails until a first production release exists. And with Play App Signing, the keystore on CI is only the upload key. If it leaks, Google can reset it.
Secrets live in CI, never in the repository
Each value is a CI secret, exposed as an environment variable and read with ENV.fetch, so a missing one fails the lane in the first second instead of after the build.
| Secret | Consumed by | Format |
|---|---|---|
ASC_KEY_ID, ASC_ISSUER_ID | app_store_connect_api_key | plain text |
ASC_KEY_P8_BASE64 | app_store_connect_api_key | base64 of the .p8 |
MATCH_PASSWORD | match, to decrypt the repository | plain text |
MATCH_GIT_BASIC_AUTHORIZATION | match, to clone the repository | base64 of user:token |
PLAY_JSON_KEY | Play actions | service account JSON |
ANDROID_KEYSTORE_BASE64, ANDROID_KEYSTORE_PASSWORD | Gradle signing config | base64, plain text |
The key alias is not a secret and stays in build.gradle.kts. A PKCS12 keystore, the format current tools create, uses the store password for the key as well. An older JKS file with a separate key password needs one more secret.
# Run once on your machine (macOS base64 syntax)
base64 -i AuthKey_ABC123XYZ.p8 | gh secret set ASC_KEY_P8_BASE64
base64 -i upload-keystore.jks | gh secret set ANDROID_KEYSTORE_BASE64
gh secret set PLAY_JSON_KEY < play-service-account.json
printf '%s' "ci-bot:$MATCH_REPO_TOKEN" | base64 | gh secret set MATCH_GIT_BASIC_AUTHORIZATIONGitHub masks secrets in logs, but only their exact value. If a script decodes or reformats a secret and prints the result, it shows in clear. I also keep store credentials in a GitHub environment with required reviewers, so each release job waits for an explicit approval before it can read them.
One workflow, triggered by a tag, one job per platform
on:
push: { tags: ["v*"] }
concurrency: release
jobs:
ios:
runs-on: macos-15
environment: release
steps:
- uses: actions/checkout@v7
- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }
- uses: ruby/setup-ruby@v1
with: { ruby-version: "3.3", bundler-cache: true }
- run: bundle exec fastlane ios beta
env:
BUILD_NAME: ${{ github.ref_name }}
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_KEY_P8_BASE64: ${{ secrets.ASC_KEY_P8_BASE64 }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }}
android:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with: { distribution: temurin, java-version: "17", cache: gradle }
# same Flutter and Ruby setup steps as the iOS job
- run: echo "$KEYSTORE_B64" | base64 --decode > android/app/upload.jks
env: { KEYSTORE_B64: "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" }
- run: bundle exec fastlane android internal
env:
BUILD_NAME: ${{ github.ref_name }}
PLAY_JSON_KEY: ${{ secrets.PLAY_JSON_KEY }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}Releases start from a tag. Pushing v1.4.0 is an explicit decision recorded in git, and the tag doubles as the build name. Merging to main ships nothing.
iOS needs macOS, while Android runs on Ubuntu, which is cheaper. The two jobs run in parallel and fail independently: a Play API hiccup doesn't block TestFlight, and a failed job can be re-run on the same tag.
cache: true keeps the Flutter SDK, bundler-cache the gems and setup-java the Gradle files. For iOS I add an actions/cache step for ios/Pods, keyed on Podfile.lock.
concurrency lets only one release run at a time, so two runs never ask TestFlight for the same "latest" build number. GitHub keeps a single run waiting per group: push three tags in a row and the middle one is cancelled and has to be re-run.
The runner's default Xcode and the latest stable Flutter both move over time, so channel: stable above is a shortcut for the snippet. For real releases I select Xcode explicitly and pin flutter-version, and a tag rebuilt next month produces the same binary.
With Flutter, flutter build compiles and fastlane ships
On a Flutter project I don't call build_app or gradle directly. flutter build ipa and flutter build appbundle compile the Dart code, write the version into the native projects and produce the artifacts. fastlane keeps signing, build numbers and uploads.
lane :beta do # Flutter version of the iOS lane
# setup_ci, app_store_connect_api_key and match exactly as above
root = File.expand_path("..") # lane code runs inside fastlane/
build_name = ENV.fetch("BUILD_NAME").delete_prefix("v")
build_number = latest_testflight_build_number(api_key: api_key, initial_build_number: 0) + 1
sh("cd '#{root}' && flutter build ipa --release " \
"--build-name=#{build_name} --build-number=#{build_number} " \
"--export-options-plist=ios/ExportOptions.plist")
upload_to_testflight(
api_key: api_key,
ipa: Dir["#{root}/build/ios/ipa/*.ipa"].first,
skip_waiting_for_build_processing: true
)
endincrement_build_number is useless here. A Flutter Info.plist reads $(FLUTTER_BUILD_NUMBER), which flutter build writes from --build-number, and the Flutter Gradle plugin sets versionCode the same way. Those flags are the only override that sticks. version: 1.4.0+12 in pubspec.yaml just becomes the local default.
Watch the paths. sh runs inside fastlane/, while actions run from the project root, and an absolute root avoids a whole class of "file not found" errors.
Signing works as before. The Runner target uses the profile match installed (named like match AppStore com.example.app), and ExportOptions.plist maps the bundle identifier to it.
Android has the same shape: flutter build appbundle --build-number=#{version_code}, then upload_to_play_store(aab: "#{root}/build/app/outputs/bundle/release/app-release.aab").
When the app has extensions with their own profiles, a notification service for example, I go back to build_app. flutter build ios --config-only --release --build-number=N prepares the Xcode project, then build_app(workspace: "ios/Runner.xcworkspace", scheme: "Runner") archives it with full control over export.
What I still do by hand
Automation gets a signed build into TestFlight and onto the internal track. Whether that build reaches every user is a decision I keep for myself:
- fastlane can upload "What's new" text from
fastlane/metadata, but someone still has to write it for each locale, and someone who reads that language should check it. - I submit to App Review by hand and read any rejection notes myself.
- On Play, I promote from internal to production at a low percentage and raise it while watching Crashlytics. On the App Store, phased release spreads the update over seven days and can be paused.
upload_to_play_storesupportstrack_promote_toandrollout, but I keep this step manual because it depends on crash data and support feedback, not on a timer. - iOS privacy manifests and Google Play policy declarations change on the stores' schedule. I have had to fix both on a live app, and no lane warns you.
- If the app enforces a minimum version through Remote Config, I raise it only once the rollout has reached everyone.