Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/scripts/verify-android-apk-signature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <apk> <expected-certificate-sha256>" >&2
exit 2
fi

apk_path="$1"
expected_sha256="$(printf '%s' "$2" | tr -d ':' | tr '[:upper:]' '[:lower:]')"

if [[ ! -f "$apk_path" ]]; then
echo "Release artifact not found: $apk_path" >&2
exit 1
fi

apksigner_path="$(find "$ANDROID_HOME/build-tools" -type f -name apksigner -print | sort -V | tail -n 1)"
if [[ -z "$apksigner_path" ]]; then
echo "apksigner was not found in Android build-tools." >&2
exit 1
fi

apk_verification="$("$apksigner_path" verify --verbose --print-certs "$apk_path")"
apk_sha256="$(printf '%s\n' "$apk_verification" | awk -F': ' '/certificate SHA-256 digest:/{print $NF; exit}')"
if [[ -z "$apk_sha256" || "$apk_sha256" != "$expected_sha256" ]]; then
echo "APK signer does not match the expected upload certificate." >&2
exit 1
fi

echo "APK signature verified with the expected upload certificate."
23 changes: 1 addition & 22 deletions .github/scripts/verify-android-release-signatures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ fi

aab_path="$1"
apk_path="$2"
expected_sha256="$(printf '%s' "$3" | tr -d ':' | tr '[:upper:]' '[:lower:]')"

if [[ ! -f "$apk_path" ]]; then
echo "Release artifact not found: $apk_path" >&2
exit 1
fi

"$(dirname "$0")/verify-android-aab-signature.sh" "$aab_path" "$3"

apksigner_path="$(find "$ANDROID_HOME/build-tools" -type f -name apksigner -print | sort -V | tail -n 1)"
if [[ -z "$apksigner_path" ]]; then
echo "apksigner was not found in Android build-tools." >&2
exit 1
fi

apk_verification="$($apksigner_path verify --verbose --print-certs "$apk_path")"
apk_sha256="$(printf '%s\n' "$apk_verification" | awk -F': ' '/certificate SHA-256 digest:/{print $NF; exit}')"
if [[ -z "$apk_sha256" || "$apk_sha256" != "$expected_sha256" ]]; then
echo "APK signer does not match the expected upload certificate." >&2
exit 1
fi

echo "AAB signature verified with the expected upload certificate."
echo "APK signature verified with the expected upload certificate."
"$(dirname "$0")/verify-android-apk-signature.sh" "$apk_path" "$3"
18 changes: 9 additions & 9 deletions .github/workflows/android-app-distribution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
set -euo pipefail
version_code=$((1000000000 + GITHUB_RUN_NUMBER))
if (( version_code > 2100000000 )); then
echo "App Distribution versionCode exceeds the Google Play limit." >&2
echo "App Distribution versionCode exceeds the Android limit." >&2
exit 1
fi
echo "ANDROID_VERSION_CODE=$version_code" >> "$GITHUB_ENV"
Expand Down Expand Up @@ -66,25 +66,25 @@ jobs:
echo "ANDROID_UPLOAD_KEYSTORE_PATH=$keystore_path" >> "$GITHUB_ENV"
echo "GOOGLE_APPLICATION_CREDENTIALS=$firebase_credentials_path" >> "$GITHUB_ENV"

- name: Build signed App Bundle
- name: Build signed APK
env:
ANDROID_UPLOAD_STORE_PASSWORD: ${{ secrets.ANDROID_UPLOAD_STORE_PASSWORD }}
ANDROID_UPLOAD_KEY_ALIAS: ${{ secrets.ANDROID_UPLOAD_KEY_ALIAS }}
ANDROID_UPLOAD_KEY_PASSWORD: ${{ secrets.ANDROID_UPLOAD_KEY_PASSWORD }}
run: ./gradlew :app:bundleRelease --stacktrace
run: ./gradlew :app:assembleRelease --stacktrace

- name: Verify App Bundle signature
- name: Verify APK signature
working-directory: .
run: |
.github/scripts/verify-android-aab-signature.sh \
android/app/build/outputs/bundle/release/app-release.aab \
.github/scripts/verify-android-apk-signature.sh \
android/app/build/outputs/apk/release/app-release.apk \
"$EXPECTED_UPLOAD_CERT_SHA256"

- name: Upload signed App Bundle artifact
- name: Upload signed APK artifact
uses: actions/upload-artifact@v4
with:
name: android-app-distribution-${{ github.sha }}-${{ github.run_number }}
path: android/app/build/outputs/bundle/release/app-release.aab
path: android/app/build/outputs/apk/release/app-release.apk
if-no-files-found: error
retention-days: 7

Expand All @@ -98,7 +98,7 @@ jobs:
if ! distribution_output="$(
npx --yes "firebase-tools@$FIREBASE_TOOLS_VERSION" \
appdistribution:distribute \
app/build/outputs/bundle/release/app-release.aab \
app/build/outputs/apk/release/app-release.apk \
--app "$FIREBASE_APP_ID" \
--groups "$FIREBASE_TESTER_GROUP" \
--release-notes "$release_notes" \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ skipped). Android Build and iOS Build stay manual.
| iOS Checks | PR (non-draft) + dispatch | Build, analyzer, unit tests |
| Android Build | `workflow_dispatch` | Assemble debug APK |
| Android Release | `workflow_dispatch` on `main` | Build and verify signed AAB + APK, then publish to Play internal |
| Android App Distribution | `push` to `main` | Build and verify a signed AAB, then distribute it to the private Firebase tester group |
| Android App Distribution | `push` to `main` | Build and verify a signed APK, then distribute it to the private Firebase tester group |
| Android Test Lab | `workflow_dispatch` on `main` | Run bounded Robo tests against a signed release APK |
| iOS Build | `workflow_dispatch` | Simulator build |

Expand Down
21 changes: 11 additions & 10 deletions docs/features/android-release-distribution/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,23 @@ infrastructure. The intentional difference remains recorded in

**Status:** Accepted for OPE-73 implementation

**Decision:** Distribute AABs through Firebase App Distribution and Google Play
internal app sharing. Treat this as a separate install channel from the Play
**Decision:** Distribute upload-key-signed APKs directly through Firebase App
Distribution. Treat this as a separate install channel from the Play
internal testing track. The owner uninstalls the Play-internal build once before
installing the first Firebase build; later Firebase builds update within that
channel.

**Why:** Google Play re-signs internal-app-sharing APKs with a dedicated test
certificate that differs from the normal Play app-signing certificate. An
in-place update across those certificates is not possible. AAB delivery still
provides device-specific APKs and a stable certificate for subsequent private
tester updates.
**Why:** The first real AAB attempt proved that Firebase rejects bundle delivery
while the Play app remains an unreviewed draft. Publishing it would require
store-policy declarations and review outside this private distribution scope.
The upload-key certificate still differs from the normal Play app-signing
certificate, so an in-place update across channels is not possible; direct APK
delivery provides a stable certificate for subsequent private tester updates.

**Versioning:** Use `1000000000 + github.run_number` for the App Distribution
workflow. The reserved high range is monotonic inside this channel and remains
separate from the canonical Play release workflow's version sequence.

**Revisit when:** Firebase supports delivery with the normal Play app-signing
certificate or the project replaces App Distribution with a Play testing-track
release on every merge.
**Revisit when:** The Play app is intentionally reviewed and published, Firebase
supports delivery with the normal Play app-signing certificate, or the project
replaces App Distribution with a Play testing-track release on every merge.
14 changes: 7 additions & 7 deletions docs/features/android-release-distribution/ope-73-plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@
<main>
<h1>OPE-73 — Firebase App Distribution On Every Merge</h1>
<p class="lead">
Every successful merge to <code>main</code> produces one AAB and distributes
Every successful merge to <code>main</code> produces one signed APK and distributes
it to the private <code>android-internal</code> tester group without publishing
another Play testing-track release.
</p>

<section class="cards" aria-label="Plan summary">
<div class="card"><strong>Trigger</strong>Every push to protected <code>main</code></div>
<div class="card"><strong>Artifact</strong>Signed Android App Bundle</div>
<div class="card"><strong>Artifact</strong>Signed Android APK</div>
<div class="card"><strong>Audience</strong>Private <code>android-internal</code> group</div>
<div class="card"><strong>Status</strong><span class="ok">Ready for first run</span></div>
</section>

<h2>Delivery flow</h2>
<div class="flow">
<div class="flow-step"><strong>1. Merge</strong><span>Exact commit lands on main</span></div>
<div class="flow-step"><strong>2. Build</strong><span>Protected CI signs and verifies the AAB</span></div>
<div class="flow-step"><strong>3. Distribute</strong><span>Firebase uploads through Play internal app sharing</span></div>
<div class="flow-step"><strong>4. Install</strong><span>Private tester receives the Play-generated build</span></div>
<div class="flow-step"><strong>2. Build</strong><span>Protected CI signs and verifies the APK</span></div>
<div class="flow-step"><strong>3. Distribute</strong><span>Firebase receives the signed APK directly</span></div>
<div class="flow-step"><strong>4. Install</strong><span>Private tester receives the Firebase build</span></div>
</div>

<h2>Checkpoints</h2>
Expand All @@ -103,7 +103,7 @@ <h2>Checkpoints</h2>
</tr>
<tr>
<td>Agent implementation</td>
<td>Add the main-push workflow, signing and signature verification, AAB upload, release notes, summaries, serialization, and cleanup.</td>
<td>Add the main-push workflow, signing and signature verification, APK upload, release notes, summaries, serialization, and cleanup.</td>
<td class="ok">Implemented</td>
</tr>
<tr>
Expand All @@ -118,7 +118,7 @@ <h2>Boundaries and risks</h2>
<table>
<thead><tr><th>Topic</th><th>Contract</th></tr></thead>
<tbody>
<tr><td>Signing</td><td>Upload-key-signed AAB; internal app sharing generates APKs with a separate test certificate. The first Firebase install requires uninstalling the Play-internal build.</td></tr>
<tr><td>Signing</td><td>Upload-key-signed APK; its certificate differs from Play App Signing. The first Firebase install requires uninstalling the Play-internal build.</td></tr>
<tr><td>Versioning</td><td>App Distribution reserves <code>1000000000 + run_number</code> for monotonic updates inside its separate tester channel.</td></tr>
<tr><td>Credentials</td><td>Dedicated Firebase App Distribution Admin identity in the protected environment; PRs receive no credentials.</td></tr>
<tr><td>Run ordering</td><td>Serialize without cancellation so a later merge cannot suppress an earlier distribution.</td></tr>
Expand Down
53 changes: 27 additions & 26 deletions docs/features/android-release-distribution/ope-73-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Companion visual review: [`ope-73-plan.html`](ope-73-plan.html).

## Outcome

Every successful merge to `main` automatically produces one Android App Bundle
Every successful merge to `main` automatically produces one signed Android APK
and distributes it to a private Firebase App Distribution tester group. The
path is independent from the manually dispatched Play internal release and
Firebase Test Lab workflows.
Expand All @@ -16,8 +16,8 @@ Firebase Test Lab workflows.
OPE-73 includes:

- a GitHub Actions workflow triggered by every `push` to `main`;
- one AAB built from the exact merged commit;
- Firebase App Distribution through Google Play internal app sharing;
- one signed APK built from the exact merged commit;
- direct Firebase App Distribution without a Play-track publication;
- a private tester group, initially containing only the owner/tester;
- merge-commit release notes and durable workflow links;
- a dedicated least-privilege App Distribution service account and protected
Expand All @@ -28,29 +28,31 @@ OPE-73 does not include:

- a second Play testing-track release or a change to the canonical manual
Android Release workflow;
- APK distribution, public invite links, or unrestricted tester enrollment;
- AAB distribution, public invite links, or unrestricted tester enrollment;
- an App Distribution runtime SDK, in-app update alerts, or feedback UI;
- Crashlytics, Analytics, Test Lab, FCM, or Remote Config scope changes;
- PR-triggered distribution or credentials exposed to pull requests; or
- iOS App Distribution, TestFlight, or App Store work.

## Why AAB
## Why APK

Firebase App Distribution integrates AAB delivery with Google Play internal app
sharing. Google Play generates device-specific APKs and signs them with its
internal-app-sharing certificate. That certificate is distinct from both the
upload key and the normal Play app-signing key. The first Firebase tester
install therefore requires uninstalling the Play-internal build; subsequent
App Distribution builds share the internal-app-sharing certificate and can
update within that tester channel.
The first real AAB distribution run proved that Firebase rejects AAB delivery
while the linked Play app remains an unreviewed draft. Making Play accept that
path would require completing store-policy declarations and submitting the app
for review, which is outside this private merge-distribution scope. Direct APK
delivery avoids an unintended Play publication boundary.

Internal app sharing permits reused version codes, but Android update behavior
is clearer with monotonic values. This workflow reserves
The APK is signed with the existing upload key. That certificate is distinct
from the normal Play app-signing key, so the first Firebase tester install
requires uninstalling the Play-internal build. Subsequent App Distribution
APKs share the upload-key certificate and can update within that tester channel.

This workflow reserves
`1000000000 + github.run_number` for App Distribution, separate from the
canonical Play release workflow's low run-number sequence. Moving between the
Play-internal and App Distribution channels requires uninstall/reinstall
because their final APK certificates differ. The AAB is not promoted to an
internal, closed, open, or production Play track.
because their APK certificates differ. The APK is not promoted to an internal,
closed, open, or production Play track.

## Trigger And Failure Contract

Expand All @@ -77,8 +79,8 @@ Do not reuse the Test Lab or Play publisher identity. Do not commit or print
the JSON key. Decode it into the runner temporary directory, expose its path
through `GOOGLE_APPLICATION_CREDENTIALS`, and delete it in an `always()` step.

The existing upload key may sign the AAB before upload, but Google Play internal
app sharing re-signs generated APKs with its dedicated test certificate.
The existing upload key signs the distributed APK. Firebase stores and serves
that signed artifact without routing it through Google Play.

## Tester Contract

Expand Down Expand Up @@ -114,11 +116,11 @@ before execution.

- [x] Add an `Android App Distribution` workflow triggered only by pushes to
`main`.
- [x] Build the AAB from the merged commit with CI-provided signing values.
- [x] Verify the AAB signature before upload.
- [x] Build the APK from the merged commit with CI-provided signing values.
- [x] Verify the APK signature before upload.
- [x] Authenticate with the dedicated service-account key from the protected
environment.
- [x] Upload the AAB to Firebase App Distribution for group
- [x] Upload the APK to Firebase App Distribution for group
`android-internal`.
- [x] Use the merge commit subject and short SHA as content-safe release notes.
- [x] Put the Firebase console and tester URLs in the workflow summary without
Expand All @@ -132,11 +134,11 @@ before execution.

- [x] Workflow structure proves that PRs and non-`main` refs cannot access the
protected secrets.
- [x] Focused workflow syntax and release bundle/signature checks pass.
- [x] Focused workflow syntax and release APK/signature checks pass.
- [ ] A merged commit automatically starts exactly one App Distribution run.
- [ ] Firebase shows the expected commit/version and `android-internal` group.
- [ ] The owner receives or can open the tester release and installs the
Play-generated build on the physical Android device.
signed Firebase build on the physical Android device.
- [ ] The App Distribution build does not publish a new Play testing-track
release or trigger Test Lab.
- [ ] Durable acceptance evidence is recorded without tester identifiers or
Expand All @@ -145,14 +147,13 @@ before execution.
## Acceptance

OPE-73 is complete only when every merge to protected `main` automatically
reaches the private Firebase tester group through an AAB, the workflow uses a
reaches the private Firebase tester group through a signed APK, the workflow uses a
dedicated protected identity, one real merged build is installed through the
tester flow, and Play-track publication, Test Lab, runtime SDKs, PR credentials,
iOS, and public tester access remain unchanged.

## Primary References

- [Firebase App Distribution](https://firebase.google.com/docs/app-distribution)
- [Distribute Android apps using Gradle](https://firebase.google.com/docs/app-distribution/android/distribute-gradle)
- [Distribute Android apps using the Firebase CLI](https://firebase.google.com/docs/app-distribution/android/distribute-cli)
- [Firebase App Distribution service-account authentication](https://firebase.google.com/docs/app-distribution/authenticate-service-account)
- [Google Play internal app sharing](https://support.google.com/googleplay/android-developer/answer/9844679)
19 changes: 12 additions & 7 deletions docs/features/android-release-distribution/operator-runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,34 +158,39 @@ passed `MediumPhone.arm-36-en-portrait` and
## Automatic Firebase App Distribution

`Android App Distribution` triggers on every push to protected `main`. It builds
one upload-key-signed AAB from the exact merged commit, verifies the upload
certificate, and distributes the bundle to the private Firebase group alias
one upload-key-signed APK from the exact merged commit, verifies the upload
certificate, and distributes the APK to the private Firebase group alias
`android-internal`. It does not publish a Play testing-track release, run Test
Lab, or expose credentials to pull requests.

The workflow uses Firebase CLI `15.24.0` with Application Default Credentials
from `FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_JSON`. It records the merge
subject and short commit SHA as release notes, then places only the stable
Firebase console and tester-experience links in the workflow summary. The
signed AAB artifact is retained for seven days. Firebase App Distribution
signed APK artifact is retained for seven days. Firebase App Distribution
releases remain available for 150 days.

App Distribution version codes use `1000000000 + github.run_number`, a
monotonic range reserved for this workflow. Google Play internal app sharing
re-signs generated APKs with its dedicated test certificate. That certificate
differs from the normal Play app-signing certificate, so the first migration
monotonic range reserved for this workflow. The APK uses the upload-key
certificate, which differs from the normal Play app-signing certificate, so the
first migration
from a Play-internal installation requires:

1. Confirm the desired Firebase release is assigned to `android-internal`.
2. Uninstall the Play-internal build from the physical device.
3. Open the tester-experience link while signed in as the private tester.
4. Install and launch the Firebase release.

Later App Distribution builds use the same internal-app-sharing certificate and
Later App Distribution builds use the same upload-key certificate and
can update within the Firebase channel. Moving back to Play internal also
requires uninstall/reinstall. Do not create a public invite link. Tester
membership remains a Firebase console/operator action.

The first merged AAB attempt failed because Firebase requires the linked Play
app to be published rather than an unreviewed draft. The direct APK path keeps
the app private and avoids completing Play store-policy declarations or
submitting it for review solely to support merge distribution.

If automatic distribution fails, inspect the workflow's build, signature,
authentication, and Firebase upload steps. A failed run does not revert the
merge. Rotate only the dedicated App Distribution key if that credential is
Expand Down
Loading
Loading