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 0000000..5851dad Binary files /dev/null and b/mobile/assets/notification-icon.png differ 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;