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
54 changes: 54 additions & 0 deletions desktop/ox-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,60 @@ artifact by the producer's artifact ID in the same run and publishes
`mobile-android-arm64-signed` after checking the release certificate and
alignment. Keep the signing key for future updates.

### Build an Android App Bundle for a Google Play internal test

The Gradle pilot project can also produce an unsigned ARM64 App Bundle (`.aab`)
for Google Play internal testing. It reuses `build-android.sh` for the release
Rust library and the same staging and Gradle project as the APKs, and runs
Gradle's `bundleRelease` task. Sign the bundle with the Play upload key
before uploading it. Google Play App Signing signs the APKs it serves to
testers. [Play App Signing](https://developer.android.com/studio/publish/app-signing)

Build the standard bundle, which keeps Firebase out of the plugin, dependency,
manifest overlay and Java source set:

```sh
OX_ANDROID_VERSION_CODE=42 OX_ANDROID_VERSION_NAME=0.1.0 \
desktop/ox-mobile/build-android-fcm.sh --bundle
```

That writes
`desktop/ox-mobile/target/aarch64-linux-android/OXMobile-unsigned.aab`.

To build the Firebase bundle, pass the same validated app configuration as the
Firebase APK. The file must stay outside the checkout:

```sh
OX_ANDROID_VERSION_CODE=42 OX_ANDROID_VERSION_NAME=0.1.0 \
OX_FIREBASE_GOOGLE_SERVICES_JSON=/absolute/path/outside/checkout/google-services.json \
desktop/ox-mobile/build-android-fcm.sh --bundle
```

That writes
`desktop/ox-mobile/target/aarch64-linux-android/OXMobile-fcm-unsigned.aab`.
`--bundle` implies `--unsigned`, defaults to `aarch64-linux-android` and refuses
another target. Both bundles keep package `dev.ox.mobile`, minSdk 28, targetSdk
36 and the version code and name from the environment.

Before moving the bundle, the script checks that it has `BundleConfig.pb`, the
base manifest and dex, the emoji assets, only `arm64-v8a` native libraries
including the Rust library, and no `META-INF` signing entries. Package, minSdk,
targetSdk and the version come from the existing Gradle sources and the version
variables. The standard bundle excludes the Firebase plugin, dependency,
manifest overlay and Java source set; the FCM bundle includes them.

For an independent manifest and structure check, point `OX_BUNDLETOOL_JAR` at
a bundletool jar you already have. The script then runs `bundletool dump
manifest` to enforce the package, version and SDK range plus the Firebase or
non-Firebase manifest, and `bundletool validate`. Without that variable, run
`bundletool validate --bundle=<path>` yourself before uploading. Play also
validates the bundle on upload. The existing APK debug, release and
`--validate-config` paths are unchanged.

Upload the signed bundle to the Play Console internal testing track. To test
locally, use bundletool to generate installable APKs.
[Play internal testing](https://support.google.com/googleplay/android-developer/answer/9845334)

## Opt-in Android Firebase pilot

The normal Android build above stays config-free. A separately configured
Expand Down
41 changes: 29 additions & 12 deletions desktop/ox-mobile/android/fcm-pilot/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@

plugins {
id("com.android.application")
id("com.google.gms.google-services")
}

fun requiredProperty(name: String): String =
providers.gradleProperty(name).orNull
?: throw GradleException("missing -P$name; run desktop/ox-mobile/build-android-fcm.sh")

// build-android-fcm.sh passes -Pox.fcm=false for a standard Google Play app
// bundle. The Firebase APKs and the optional Firebase bundle omit the
// property, so they keep the existing plugin, dependency and source set.
val fcmEnabled = providers.gradleProperty("ox.fcm").getOrElse("true").toBoolean()
if (fcmEnabled) {
apply(plugin = "com.google.gms.google-services")
}

val abi = requiredProperty("ox.abi")
val nativeLibsDir = requiredProperty("ox.jniLibsDir")
val assetsDir = requiredProperty("ox.assetsDir")
val gpuiJavaDir = requiredProperty("ox.gpuiJavaDir")
val googleServicesJson = requiredProperty("ox.googleServicesJson")
val googleServicesJson = if (fcmEnabled) requiredProperty("ox.googleServicesJson") else ""
val debugKeystore = providers.gradleProperty("ox.keystore").orNull

android {
Expand Down Expand Up @@ -62,16 +69,22 @@ android {

sourceSets {
val messagingManifest = "src/fcm/AndroidManifest.xml"
getByName("debug").manifest.srcFile(messagingManifest)
getByName("release").manifest.srcFile(messagingManifest)
if (fcmEnabled) {
getByName("debug").manifest.srcFile(messagingManifest)
getByName("release").manifest.srcFile(messagingManifest)
}
getByName("main") {
// Build the SDK and the app from the same sources as the normal
// APK. The manifest keeps dev.ox.mobile and the camera activity.
manifest.srcFile("../../AndroidManifest.xml")
// The Firebase classes are pilot-only: the normal build compiles
// android/java alone and therefore never sees them.
res.srcDir("../../res")
java.srcDirs(gpuiJavaDir, "../../java", "../../fcm-pilot/java")
if (fcmEnabled) {
java.srcDirs(gpuiJavaDir, "../../java", "../../fcm-pilot/java")
} else {
java.srcDirs(gpuiJavaDir, "../../java")
}
jniLibs.srcDir(nativeLibsDir)
assets.srcDir(assetsDir)
}
Expand All @@ -92,17 +105,21 @@ android {
}

dependencies {
// Published on Google Maven as an AAR whose classes expose
// FirebaseMessaging.register()/unregister() and
// FirebaseMessagingService.onRegistered(String).
implementation("com.google.firebase:firebase-messaging:26.0.2")
if (fcmEnabled) {
// Published on Google Maven as an AAR whose classes expose
// FirebaseMessaging.register()/unregister() and
// FirebaseMessagingService.onRegistered(String).
implementation("com.google.firebase:firebase-messaging:26.0.2")
}
}

// The Google Services plugin only searches fixed source-set locations. Point
// its task at the explicit file the caller supplied instead. This runs after
// the plugin's own afterEvaluate hook so the explicit value wins.
afterEvaluate {
tasks.withType<com.google.gms.googleservices.GoogleServicesTask>().configureEach {
googleServicesJsonFiles.set(listOf(file(googleServicesJson)))
if (fcmEnabled) {
afterEvaluate {
tasks.withType<com.google.gms.googleservices.GoogleServicesTask>().configureEach {
googleServicesJsonFiles.set(listOf(file(googleServicesJson)))
}
}
}
142 changes: 127 additions & 15 deletions desktop/ox-mobile/build-android-fcm.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
#!/usr/bin/env bash
# Build the opt-in Android Firebase pilot APK.
# Build the opt-in Android Firebase pilot APK or the unsigned Google Play
# App Bundle.
#
# The normal no-config APK still comes from build-android.sh. This variant adds
# the official Firebase Messaging SDK and a separately configured Firebase
# Android app. The project JSON never lives in the checkout: the caller passes
# its path in OX_FIREBASE_GOOGLE_SERVICES_JSON.
# The normal no-config APK still comes from build-android.sh. The Firebase APK
# and optional Firebase bundle add the official Firebase Messaging SDK and a
# separately configured Firebase Android app. A standard bundle uses the same
# Gradle project without Firebase. The project JSON never lives in the
# checkout: the caller passes its path in OX_FIREBASE_GOOGLE_SERVICES_JSON.
set -euo pipefail
invocation_dir="$PWD"
cd "$(dirname "$0")"

usage() {
cat <<'EOF'
usage: build-android-fcm.sh [--validate-config] [target [--unsigned]]
usage: build-android-fcm.sh [--validate-config] [--bundle] [target [--unsigned]]

target x86_64-linux-android (default) or aarch64-linux-android
--validate-config check OX_FIREBASE_GOOGLE_SERVICES_JSON and exit
--unsigned build an aligned, non-debuggable release APK without signing
--bundle build an unsigned ARM64 Android App Bundle (.aab) for a
Google Play internal test with bundleRelease. Without
OX_FIREBASE_GOOGLE_SERVICES_JSON the bundle omits Firebase
entirely; with it the bundle is the FCM variant.

Environment:
OX_FIREBASE_GOOGLE_SERVICES_JSON pilot google-services.json, outside this
checkout (required)
checkout (required for the Firebase APK and
the optional Firebase bundle)
OX_ANDROID_VERSION_CODE, OX_ANDROID_VERSION_NAME
app version (required with --unsigned)
app version (required with --unsigned or
--bundle)
ANDROID_HOME, JAVA_HOME Android SDK and JDK 21 or newer
OX_ANDROID_FCM_CACHE cache root, made absolute (default: target/fcm)
OX_ANDROID_FCM_GRADLE_USER_HOME Gradle home, made absolute
(default: target/gradle-user-home)
OX_ANDROID_FCM_GRADLE_LINES Gradle minor lines to try when the pinned
AGP's compatibility range is unknown
(default: 6)
OX_BUNDLETOOL_JAR optional local bundletool jar; the bundle
path then runs `dump manifest` and
`validate` as an extra check

The pilot uses an installed Gradle when it can configure the build, otherwise
the newest official stable Gradle release that is at least 24 hours old and
Expand All @@ -44,13 +55,15 @@ die() {
}

validate_only=false
bundle=false
variant=debug
target=x86_64-linux-android
target_set=false
for arg in "$@"; do
case "$arg" in
--validate-config) validate_only=true ;;
--unsigned) variant=release ;;
--bundle) bundle=true ;;
-h|--help) usage; exit 0 ;;
-*)
usage >&2
Expand All @@ -64,8 +77,19 @@ for arg in "$@"; do
esac
done

if $bundle; then
# Google Play delivers an app bundle per device, and the app has no
# 32-bit native build. Keep the artifact ARM64-only like the release APK.
$target_set || target=aarch64-linux-android
[[ "$target" == aarch64-linux-android ]] ||
die "a Google Play app bundle is built for ARM64 only: use aarch64-linux-android"
variant=release
fi

fcm_enabled=false
config="${OX_FIREBASE_GOOGLE_SERVICES_JSON:-}"
[[ -n "$config" ]] || die "set OX_FIREBASE_GOOGLE_SERVICES_JSON to the pilot's google-services.json (kept outside this checkout)"
if [[ -n "$config" ]]; then
fcm_enabled=true
[[ "$config" = /* ]] || config="$invocation_dir/$config"
[[ -f "$config" ]] || die "OX_FIREBASE_GOOGLE_SERVICES_JSON is not a file: $config"

Expand Down Expand Up @@ -165,6 +189,11 @@ PY
)" || exit 1

printf 'Validated Firebase app configuration for project %s (package dev.ox.mobile).\n' "$project_id"
elif $validate_only; then
die "set OX_FIREBASE_GOOGLE_SERVICES_JSON to the pilot's google-services.json (kept outside this checkout)"
elif ! $bundle; then
die "set OX_FIREBASE_GOOGLE_SERVICES_JSON to the pilot's google-services.json (kept outside this checkout), or pass --bundle for the standard bundle"
fi

if $validate_only; then
exit 0
Expand All @@ -179,8 +208,13 @@ esac
version_code=1
version_name=0.1.0
if [[ "$variant" == release ]]; then
: "${OX_ANDROID_VERSION_CODE:?Set OX_ANDROID_VERSION_CODE for a release APK}"
: "${OX_ANDROID_VERSION_NAME:?Set OX_ANDROID_VERSION_NAME for a release APK}"
if $bundle; then
: "${OX_ANDROID_VERSION_CODE:?Set OX_ANDROID_VERSION_CODE for an app bundle}"
: "${OX_ANDROID_VERSION_NAME:?Set OX_ANDROID_VERSION_NAME for an app bundle}"
else
: "${OX_ANDROID_VERSION_CODE:?Set OX_ANDROID_VERSION_CODE for a release APK}"
: "${OX_ANDROID_VERSION_NAME:?Set OX_ANDROID_VERSION_NAME for a release APK}"
fi
version_code="$OX_ANDROID_VERSION_CODE"
version_name="$OX_ANDROID_VERSION_NAME"
fi
Expand Down Expand Up @@ -210,7 +244,26 @@ cargo_target="${CARGO_TARGET_DIR:-$PWD/target}"
cargo_target="$(mkdir -p "$cargo_target" && cd "$cargo_target" && pwd -P)"
out="$cargo_target/$target"
staging="$cache_root/staging/$target"
if [[ "$variant" == release ]]; then
if $bundle; then
# Reuse the normal release Rust build and version checks, then let the
# existing Gradle project produce the app bundle. A standard bundle has no
# Firebase dependency, plugin, manifest overlay or Java source.
if $fcm_enabled; then
OX_ANDROID_FCM_ADAPTER=1 OX_ANDROID_NATIVE_ONLY=1 ./build-android.sh "$target" --unsigned
final="$out/OXMobile-fcm-unsigned.aab"
staging="$staging-bundle-fcm"
else
OX_ANDROID_FCM_ADAPTER=0 OX_ANDROID_NATIVE_ONLY=1 ./build-android.sh "$target" --unsigned
final="$out/OXMobile-unsigned.aab"
staging="$staging-bundle"
fi
task=:app:bundleRelease
gradle_output=release/app-release.aab
variant_args=(-Pox.versionCode="$version_code" -Pox.versionName="$version_name" -Pox.fcm="$fcm_enabled")
if $fcm_enabled; then
variant_args+=(-Pox.googleServicesJson="$config_abs")
fi
elif [[ "$variant" == release ]]; then
# Reuse the normal release profile and version checks. Native-only exits
# before the normal Java packaging and does not create a debug keystore.
OX_ANDROID_FCM_ADAPTER=1 OX_ANDROID_NATIVE_ONLY=1 ./build-android.sh "$target" --unsigned
Expand Down Expand Up @@ -255,9 +308,11 @@ gradle_args=(
-Pox.jniLibsDir="$staging/jniLibs"
-Pox.assetsDir="$staging/assets"
-Pox.gpuiJavaDir="$staging/java"
-Pox.googleServicesJson="$config_abs"
"${variant_args[@]}"
)
if ! $bundle; then
gradle_args+=(-Pox.googleServicesJson="$config_abs")
fi
gradle_args+=("${variant_args[@]}")

# Gradle is not pinned here. An installed Gradle is tried first; otherwise the
# pilot reads Gradle's own release metadata and keeps the newest stable release
Expand Down Expand Up @@ -530,12 +585,69 @@ fi

"$gradle_bin" "${gradle_args[@]}"

built="$PWD/android/fcm-pilot/app/build/outputs/apk/$gradle_output"
if $bundle; then
built="$PWD/android/fcm-pilot/app/build/outputs/bundle/$gradle_output"
else
built="$PWD/android/fcm-pilot/app/build/outputs/apk/$gradle_output"
fi
[[ -f "$built" ]] || die "Gradle did not produce $built"

tools="$ANDROID_HOME/build-tools/36.0.0"
android_jar="$ANDROID_HOME/platforms/android-36/android.jar"
[[ -f "$android_jar" ]] || die "missing $android_jar"

if $bundle; then
entries="$(unzip -Z1 "$built")" || die "cannot read the app bundle $built"
for required in BundleConfig.pb base/manifest/AndroidManifest.xml \
base/dex/classes.dex base/lib/arm64-v8a/libox_mobile.so \
base/assets/fonts/NotoColorEmoji.ttf \
base/assets/fonts/NotoColorEmoji-LICENSE.txt; do
grep -Fxq "$required" <<<"$entries" ||
die "the app bundle is missing $required"
done
other_abis="$(awk -F/ '/^base\/lib\// && $3 != "arm64-v8a" { print $3 }' <<<"$entries" | sort -u)"
[[ -z "$other_abis" ]] ||
die "the app bundle contains unexpected ABIs: $other_abis"
signing_entries="$(grep -Ei '^META-INF/([^/]+\.(SF|RSA|DSA|EC)|SIG-[^/]+)$' <<<"$entries" || true)"
[[ -z "$signing_entries" ]] ||
die "the app bundle contains signing entries: $signing_entries"

# Optional and local: use a bundletool the caller already has to read the
# protobuf manifest and validate the bundle. Play validates the uploaded
# bundle too, so this is an extra gate and never a download.
if [[ -n "${OX_BUNDLETOOL_JAR:-}" ]]; then
[[ -f "$OX_BUNDLETOOL_JAR" ]] ||
die "OX_BUNDLETOOL_JAR is not a file: $OX_BUNDLETOOL_JAR"
bundle_manifest="$("$JAVA_HOME/bin/java" -jar "$OX_BUNDLETOOL_JAR" dump manifest --bundle="$built")" ||
die "bundletool could not read the app bundle manifest"
grep -Fq 'package="dev.ox.mobile"' <<<"$bundle_manifest" ||
die "the app bundle package is not dev.ox.mobile"
grep -Fq "android:versionCode=\"$version_code\"" <<<"$bundle_manifest" ||
die "the app bundle version code is not $version_code"
grep -Fq "android:versionName=\"$version_name\"" <<<"$bundle_manifest" ||
die "the app bundle version name is not $version_name"
grep -Fq 'android:minSdkVersion="28"' <<<"$bundle_manifest" ||
die "the app bundle minSdk is not 28"
grep -Fq 'android:targetSdkVersion="36"' <<<"$bundle_manifest" ||
die "the app bundle targetSdk is not 36"
if $fcm_enabled; then
grep -Fq 'dev.ox.mobile.OXCloudMessagingService' <<<"$bundle_manifest" ||
die "the FCM app bundle has no messaging service"
elif grep -Fqi 'firebase' <<<"$bundle_manifest"; then
die "the standard app bundle contains a Firebase manifest entry"
fi
"$JAVA_HOME/bin/java" -jar "$OX_BUNDLETOOL_JAR" validate --bundle="$built" >/dev/null ||
die "bundletool rejected the app bundle"
fi

mv -- "$built" "$final"
printf 'Built %s\n' "$final"
if $fcm_enabled; then
printf 'Firebase project: %s\n' "$project_id"
fi
exit 0
fi

apk="$(mktemp "$out/.ox-mobile-fcm.XXXXXX.apk")"
trap 'rm -f -- "$apk"' EXIT
if [[ "$variant" == release ]]; then
Expand Down
Loading
Loading