From cf1323ac8f9be8eb83673856420bb8f4aa391905 Mon Sep 17 00:00:00 2001 From: Waozi Date: Thu, 29 Oct 2026 16:22:59 -0300 Subject: [PATCH] Keep Firebase's Gradle plugin in the Google Play edition Only the -gplay edition may read a Google library. The google-services plugin's classpath moves from the root plugins block into droid/app/gplay-classpath.gradle and its application into droid/app/gplay.gradle, both applied only in a Gradle run whose tasks name gplay. Such a run refuses release or debug tasks beside it, so the Makefile and the release workflow build the normal and gplay APKs in separate runs, and the normal and F-Droid builds never resolve the plugin. The Moto check builds only the normal APK and no longer writes the Firebase config. CI checks the Gradle files with Kryon's google-free action, the release workflow checks the normal, per-ABI and -fdroid APKs and finds Play Billing in the -gplay APK, and the F-Droid workflow checks F-Droid's own APK. --- .github/workflows/android-moto.yml | 5 ----- .github/workflows/ci.yml | 12 ++++++++++++ .github/workflows/fdroid.yml | 8 ++++++++ .github/workflows/release.yml | 26 +++++++++++++++++++++++++- droid/app/build.gradle | 26 ++++++++++++++++++-------- droid/app/gplay-classpath.gradle | 10 ++++++++++ droid/app/gplay.gradle | 6 ++++++ droid/build.gradle | 1 - mk/android.mk | 3 ++- 9 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 droid/app/gplay-classpath.gradle create mode 100644 droid/app/gplay.gradle diff --git a/.github/workflows/android-moto.yml b/.github/workflows/android-moto.yml index c7d216cdc..fe19b21d6 100644 --- a/.github/workflows/android-moto.yml +++ b/.github/workflows/android-moto.yml @@ -106,11 +106,6 @@ jobs: mkdir -p ~/.android printf '%s' "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore - - name: Prepare Firebase config - env: - GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} - run: ./scripts/write-google-services-json.sh - - name: Copy Android assets run: ./scripts/copy-android-assets.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02bad56f8..6833200d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,18 @@ jobs: fi python3 scripts/check-file-size.py --since "$base" + google-free: + name: Google libraries only in the gplay edition + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + # The normal and F-Droid builds read no Google library or plugin; only + # gplay-scoped configurations and gplay files may name one. + - name: Keep Google libraries out of the normal and F-Droid build files + uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179 + guard-package-urls: name: Package URLs are public HTTPS runs-on: ubuntu-latest diff --git a/.github/workflows/fdroid.yml b/.github/workflows/fdroid.yml index 78fcf5afc..e524545e7 100644 --- a/.github/workflows/fdroid.yml +++ b/.github/workflows/fdroid.yml @@ -65,6 +65,14 @@ jobs: - name: Build and scan with F-Droid without cached package sources run: python3 build/xyz.waozi.inbe/scripts/check-fdroid.py + # F-Droid's scanner checked the source; its APK must hold no Google + # library either. + - name: Keep Google libraries out of F-Droid's APK + uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179 + with: + packages: tmp/*.apk + source: '' + - name: Preserve APK, exact metadata and scanner evidence if: always() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 649a8dc72..5d05e365e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -981,7 +981,13 @@ jobs: run: | set -euo pipefail chmod +x droid/gradlew - ./droid/gradlew -p droid assembleRelease assembleGplay \ + ./droid/gradlew -p droid assembleRelease \ + -Pkeystore.path="$HOME/.android/inbe-release.keystore" \ + -Pkeystore.alias="$KEY_ALIAS" \ + -Pkeystore.password="$KEYSTORE_PASSWORD" \ + --stacktrace + # Only the Google Play edition's own Gradle run reads its Google plugin. + ./droid/gradlew -p droid assembleGplay \ -Pkeystore.path="$HOME/.android/inbe-release.keystore" \ -Pkeystore.alias="$KEY_ALIAS" \ -Pkeystore.password="$KEYSTORE_PASSWORD" \ @@ -1034,6 +1040,24 @@ jobs: done cp "build/android/inbe-$VERSION-gplay.aab" build/release/android/ + # Only the Google Play edition may hold a Google library, in its build + # files as in its APK. The universal and both x86 APK names end in a digit. + - name: Keep Google libraries out of the normal and F-Droid APKs + uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179 + with: + packages: >- + build/release/android/inbe-*[0-9].apk + build/release/android/inbe-*-arm*.apk + build/release/android/inbe-*-fdroid.apk + # The Google check must still recognise Play Billing, or its passes on + # the other editions prove nothing. + - name: Find Play Billing in the Google Play APK + uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179 + with: + packages: build/release/android/inbe-*-gplay.apk + source: '' + expect-google: 'true' + - name: Upload Android Artifacts uses: actions/upload-artifact@v4 with: diff --git a/droid/app/build.gradle b/droid/app/build.gradle index ddf2e5323..1ca102d29 100644 --- a/droid/app/build.gradle +++ b/droid/app/build.gradle @@ -1,16 +1,26 @@ +buildscript { + // Only the Google Play edition may read a Google library or plugin + // (gplay-classpath.gradle, gplay.gradle), so it builds in its own Gradle + // run, apart from the direct and F-Droid builds. + ext.buildingGplay = gradle.startParameter.taskNames.any { it.toLowerCase().contains('gplay') } + if (buildingGplay && gradle.startParameter.taskNames.any { + def name = it.toLowerCase() + name.contains('release') || name.contains('debug') + }) { + throw new GradleException('Build the gplay edition in its own Gradle run') + } + if (buildingGplay) { + apply from: 'gplay-classpath.gradle', to: buildscript + } +} + plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' } -def hasGplayFirebaseConfig = file("src/gplay/google-services.json").exists() -if (hasGplayFirebaseConfig) { - apply plugin: 'com.google.gms.google-services' - tasks.configureEach { task -> - if (task.name == "processDebugGoogleServices" || task.name == "processReleaseGoogleServices") { - task.enabled = false - } - } +if (buildingGplay) { + apply from: 'gplay.gradle' } def appOnlyAbi = (project.findProperty('app.onlyAbi') ?: '').toString() def verificationInstance = (project.findProperty('app.verificationInstance') ?: 'false').toString().toBoolean() diff --git a/droid/app/gplay-classpath.gradle b/droid/app/gplay-classpath.gradle new file mode 100644 index 000000000..0926bcaf8 --- /dev/null +++ b/droid/app/gplay-classpath.gradle @@ -0,0 +1,10 @@ +// The Google Play edition's Firebase Cloud Messaging plugin, which +// build.gradle adds to its own classpath (beside the Android plugin it +// extends) only in a Gradle run that builds the gplay build type. +repositories { + google() + mavenCentral() +} +dependencies { + classpath 'com.google.gms:google-services:4.5.0' +} diff --git a/droid/app/gplay.gradle b/droid/app/gplay.gradle new file mode 100644 index 000000000..9906fa845 --- /dev/null +++ b/droid/app/gplay.gradle @@ -0,0 +1,6 @@ +// Firebase Cloud Messaging for the Google Play edition (classpath in +// gplay-classpath.gradle). CI writes src/gplay/google-services.json; local +// Play builds without it keep push inert. +if (file('src/gplay/google-services.json').exists()) { + apply plugin: 'com.google.gms.google-services' +} diff --git a/droid/build.gradle b/droid/build.gradle index 09e238ee8..0c055470b 100644 --- a/droid/build.gradle +++ b/droid/build.gradle @@ -1,5 +1,4 @@ plugins { id 'com.android.application' version '8.13.2' apply false id 'org.jetbrains.kotlin.android' version '2.3.0' apply false - id 'com.google.gms.google-services' version '4.5.0' apply false } diff --git a/mk/android.mk b/mk/android.mk index 59617b34a..9021373c5 100644 --- a/mk/android.mk +++ b/mk/android.mk @@ -47,7 +47,8 @@ android-release: $(MAKE) android-copy-assets $(MAKE) android-local-properties @if [ -n "$(PASSWORD)" ]; then \ - $(ANDROID_GRADLE_ENV) $(GRADLE) -p droid assembleRelease assembleGplay -Pkeystore.path="$(ANDROID_KEYSTORE)" -Pkeystore.alias="$(ANDROID_KEY_ALIAS)" -Pkeystore.password="$(PASSWORD)" $(ANDROID_GRADLE_ARGS) || exit $$?; \ + $(ANDROID_GRADLE_ENV) $(GRADLE) -p droid assembleRelease -Pkeystore.path="$(ANDROID_KEYSTORE)" -Pkeystore.alias="$(ANDROID_KEY_ALIAS)" -Pkeystore.password="$(PASSWORD)" $(ANDROID_GRADLE_ARGS) || exit $$?; \ + $(ANDROID_GRADLE_ENV) $(GRADLE) -p droid assembleGplay -Pkeystore.path="$(ANDROID_KEYSTORE)" -Pkeystore.alias="$(ANDROID_KEY_ALIAS)" -Pkeystore.password="$(PASSWORD)" $(ANDROID_GRADLE_ARGS) || exit $$?; \ else \ echo "Set PASSWORD=your-keystore-password for release builds"; \ exit 1; \