From 40514e1819fc9f551bb6532fab5ad0ce99300cf2 Mon Sep 17 00:00:00 2001 From: KM Koushik Date: Mon, 16 Nov 2026 15:55:40 +1100 Subject: [PATCH] fix(mobile): Android push notifications via Firebase --- mobile/.gitignore | 1 + mobile/RELEASING.md | 19 ++++++++--- mobile/app.config.ts | 7 ++-- mobile/assets/notification-icon.png | Bin 0 -> 2271 bytes mobile/src/lib/appConfig.test.ts | 50 ++++++++++++++++++++++++++++ mobile/src/lib/push.ts | 6 ++-- 6 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 mobile/assets/notification-icon.png create mode 100644 mobile/src/lib/appConfig.test.ts diff --git a/mobile/.gitignore b/mobile/.gitignore index d914c32..68fa4b1 100644 --- a/mobile/.gitignore +++ b/mobile/.gitignore @@ -10,6 +10,7 @@ web-build/ expo-env.d.ts # Native +google-services.json .kotlin/ *.orig.* *.jks diff --git a/mobile/RELEASING.md b/mobile/RELEASING.md index 703d3c3..a53170e 100644 --- a/mobile/RELEASING.md +++ b/mobile/RELEASING.md @@ -35,11 +35,7 @@ lists both. The links live in `src/components/Site/constants.ts`. ## Next 1. Get Android to 12 opted-in testers. The 14 days only start counting once there are 12. -2. Android push notifications need a Firebase project with an Android app `app.splitpro`. Then: - - add `google-services.json` (`android.googleServicesFile` in `app.config.ts`); - - upload the FCM V1 key to EAS; - - add a 96×96 notification icon; - - rebuild and release. +2. Verify Android push notifications on the next internal build (see Firebase setup below). 3. Before the public launch: - retake the store screenshots with realistic demo data; - use native Android confirm dialogs; @@ -86,6 +82,19 @@ node ~/.appstore/scripts/asc/play-release.mjs "" - `play-release.mjs` uploads the bundle once and releases it to internal and closed testing. - versionCode is incremented remotely by EAS. +### Android Firebase push setup + +- EAS must have an FCM V1 service account credential assigned to `app.splitpro`. +- `GOOGLE_SERVICES_JSON` is an EAS **file** environment variable with **secret** visibility in + both `production` and `preview`. `app.config.ts` reads its path; keep the file out of git. +- Local builds may omit the variable, but Android push requires it. To test push locally, set it + to the path of the maintainer's `google-services.json`. +- The notification plugin uses `assets/notification-icon.png`, a white-on-transparent logo mark. +- Android emulators need Google Play services to receive remote notifications. +- For an **internal-only** release, do not run `play-release.mjs` or `ship-builds.sh`: they also + publish to closed testing. Use `play-upload.mjs internal ""` for an internal + draft, then complete only that track through Play Console or the publishing API. + **Both at once** ```sh diff --git a/mobile/app.config.ts b/mobile/app.config.ts index db98860..11eab92 100644 --- a/mobile/app.config.ts +++ b/mobile/app.config.ts @@ -28,6 +28,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ }, android: { package: 'app.splitpro', + googleServicesFile: process.env.GOOGLE_SERVICES_JSON ?? undefined, adaptiveIcon: { foregroundImage: './assets/icon.png', backgroundColor: ICON_BACKGROUND, @@ -55,8 +56,10 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ microphonePermission: false, }, ], - // TODO: add `icon`, a 96x96 white-on-transparent PNG, or Android shows a white square. - ['expo-notifications', { color: '#06b6d4', defaultChannel: 'default' }], + [ + 'expo-notifications', + { icon: './assets/notification-icon.png', color: '#06b6d4', defaultChannel: 'default' }, + ], [ 'expo-splash-screen', { diff --git a/mobile/assets/notification-icon.png b/mobile/assets/notification-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5851dad605100b68429ccf7aafab8aa0d919581f GIT binary patch literal 2271 zcmV<52q5=~P)6T!#6;qec*h$g9`PbUBZz{E;w?y2@Idj0_(KHok2it`-Y6=lk@!Ot zQBFMbMu*-H4G!|J98T%Bk4 zb;7zy^+i%X1n{O5=iJxk`36-ga$!WS(3h)%_$z9Qpke;qRU(Syr`L-c|Cr+mbo|Y+|Ar@;$K1OniN@w2?zxpyHZ_pk`C4dlr zxRJz+gR`cKSP+>*312NF9|v%m{#4dMuN&Y8V6l=!@6UD4eGwW7J;wlVV#-U9oCDwj zH5W%TNqixSn2BiyMLX~|t3n3!nn#cW@{j;e{M!uiw@GYfS*ivhWDb&V851uJ@#m1-(OmC|>ROp|7=~@Z6q2Jz z9#8T*vrmWdKx76Cb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37oRgvh zde!s+dKDT1GNT)UXt{aK_tq410PltnkErAw>P?t9(3dqZYGlH~%0Lck&=dbmv!LH7 zd5HY}Zcn?TNj?$0m?XiwCCo<1&CI9<)3*E4NlTcTpVa3BO1odpCl~BZkbFvCWK-aQ z{6}MQuB#>DL1HE!-tHOXi~YZ^>k=06A4*U!ja<>ckR03V67W>eqmqJXH)@1~=;qT% zPVT^cB{SBkB%d@3_Gx-P&GXI9V@WdaZJ<6;o=rhH3czt%1Tyf6>9}1GA=*v}{8s^- z;GA2WC-L)Oz#`3VJ4#=+tYtXd5mbrv`H8&Bxz;%+YG-BM#LopJ50nHPx?4W9w}&$R zW{{k&$^`EZ0?}h*X002ovPDHLkV1f$?GlT#D literal 0 HcmV?d00001 diff --git a/mobile/src/lib/appConfig.test.ts b/mobile/src/lib/appConfig.test.ts new file mode 100644 index 0000000..1718fc4 --- /dev/null +++ b/mobile/src/lib/appConfig.test.ts @@ -0,0 +1,50 @@ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { describe, it } from 'node:test'; + +import appConfig from '../../app.config'; + +const context = { + config: { name: 'SplitPro', slug: 'splitpro' }, + projectRoot: process.cwd(), + staticConfigPath: null, + packageJsonPath: 'package.json', +}; + +describe('Android push build configuration', () => { + it('should use the Firebase file supplied by EAS and allow local builds without it', () => { + const previous = process.env.GOOGLE_SERVICES_JSON; + + try { + delete process.env.GOOGLE_SERVICES_JSON; + assert.equal(appConfig(context).android?.googleServicesFile, undefined); + + process.env.GOOGLE_SERVICES_JSON = '/eas/secret/google-services.json'; + assert.equal( + appConfig(context).android?.googleServicesFile, + '/eas/secret/google-services.json', + ); + } finally { + if (undefined === previous) { + delete process.env.GOOGLE_SERVICES_JSON; + } else { + process.env.GOOGLE_SERVICES_JSON = previous; + } + } + }); + + it('should configure the default channel and a 96x96 PNG notification icon', () => { + const config = appConfig(context); + assert.deepEqual( + config.plugins?.find((plugin) => Array.isArray(plugin) && 'expo-notifications' === plugin[0]), + [ + 'expo-notifications', + { icon: './assets/notification-icon.png', color: '#06b6d4', defaultChannel: 'default' }, + ], + ); + const icon = readFileSync('assets/notification-icon.png'); + assert.equal(icon.subarray(1, 4).toString(), 'PNG'); + assert.equal(icon.readUInt32BE(16), 96); + assert.equal(icon.readUInt32BE(20), 96); + }); +}); diff --git a/mobile/src/lib/push.ts b/mobile/src/lib/push.ts index 54b5904..c9cf5ba 100644 --- a/mobile/src/lib/push.ts +++ b/mobile/src/lib/push.ts @@ -3,8 +3,8 @@ * API (`user.registerPushToken`). The backend sends `data.url` with a web-style path such as * `/expenses/123`; `getPushRoute` maps it to an app route. * - * Push only works in a native build on a real device. On web and simulators every call here is a - * no-op that reports `unsupported`. + * Push requires a native build. Android emulators with Google Play services work too; web and + * iOS simulators report `unsupported`. */ import { createTRPCProxyClient, httpLink } from '@trpc/client'; import Constants from 'expo-constants'; @@ -35,7 +35,7 @@ export type PushState = 'unsupported' | 'undetermined' | 'denied' | 'disabled' | export type EnablePushResult = 'enabled' | 'denied' | 'unsupported' | 'unavailable'; export const isPushSupported = () => - ('ios' === Platform.OS || 'android' === Platform.OS) && Device.isDevice; + 'android' === Platform.OS || ('ios' === Platform.OS && Device.isDevice); const getProjectId = (): string | undefined => { const extra = Constants.expoConfig?.extra as { eas?: { projectId?: unknown } } | undefined;