diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index 343e12df..b904c1b0 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -46,12 +46,20 @@ jobs:
onesignal-app-id: ${{ vars.APPIUM_ONESIGNAL_APP_ID }}
onesignal-api-key: ${{ secrets.APPIUM_ONESIGNAL_API_KEY }}
+ - name: Write demo google-services.json
+ uses: OneSignal/sdk-shared/.github/actions/setup-google-services@main
+ with:
+ google-services-json: ${{ secrets.APPIUM_GOOGLE_SERVICES_JSON }}
+ path: examples/demo/android/app/google-services.json
+
- name: Build release APK
working-directory: examples/demo/android
# -PciSingleAbi → arm64-v8a-only APK (~10 MB) instead of the
# ~30 MB universal APK. BrowserStack devices we test against
# are all arm64-v8a.
- run: ./gradlew assembleRelease -PciSingleAbi --quiet --console=plain --warning-mode=summary
+ # FIREBASE_INSTALLATION_ID_ENABLED turns on Firebase Installation ID registration,
+ # which needs the google-services.json written above.
+ run: ./gradlew assembleRelease -PciSingleAbi -PFIREBASE_INSTALLATION_ID_ENABLED=true --quiet --console=plain --warning-mode=summary
- name: Upload APK
uses: actions/upload-artifact@v7
@@ -144,6 +152,7 @@ jobs:
app-artifact: demo-apk
app-filename: app-arm64-v8a-release.apk
sdk-type: react-native
+ bundle-id: com.onesignal.sdkdemo
build-name: react-native-android-${{ github.ref_name }}-${{ github.run_number }}
e2e-ios:
diff --git a/examples/build.md b/examples/build.md
index 5b338012..f3c84f52 100644
--- a/examples/build.md
+++ b/examples/build.md
@@ -22,6 +22,8 @@ mv demo examples/demo
- Architecture: provider + hook (`OneSignalProvider` / `useOneSignal`), no repository class, no reducer
- Separate component files per section
- Support both Android and iOS
+- Android `namespace` and `applicationId` in `android/app/build.gradle` are `com.onesignal.sdkdemo`, to match the shared `google-services.json`. The iOS bundle id stays `com.onesignal.example`.
+- Android applies the Google Services plugin only when `android/app/google-services.json` exists (gitignored), and depends on `firebase-messaging` 25.1.2+ for Firebase Installation ID registration. The `firebase_messaging_installation_id_enabled` manifest flag is off unless Gradle gets `-PFIREBASE_INSTALLATION_ID_ENABLED=true`, which also requires `google-services.json`.
App bar logo: import SVG directly via `react-native-svg-transformer`:
@@ -55,7 +57,7 @@ Package scripts (`examples/demo/package.json`):
"android": "bash ../run-android.sh",
"ios": "bash ../run-ios.sh",
"update:pods": "(cd ios && pod update OneSignalXCFramework --no-repo-update)",
- "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.example >/dev/null 2>&1 || true",
+ "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.sdkdemo >/dev/null 2>&1 || true",
"clean:ios": "rm -rf ios/build ios/Pods",
"start": "react-native start"
},
@@ -126,7 +128,7 @@ apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
- `ONESIGNAL_APP_ID` -- app id passed to `OneSignal.initialize(...)`.
- `ONESIGNAL_API_KEY` -- REST key used by `OneSignalApiService` for sends and Live Activity update/end.
- `ONESIGNAL_ANDROID_CHANNEL_ID` -- channel id sent with the WITH SOUND push (`android_channel_id`).
-- `src/hooks/useOneSignal.ts` defines a hardcoded `DEFAULT_APP_ID` fallback used when `ONESIGNAL_APP_ID` is unset/empty.
+- `ONESIGNAL_APP_ID` is required. `metro.config.js` fails the bundle when it's unset; there is no default app id.
---
diff --git a/examples/demo-no-location/android/app/build.gradle b/examples/demo-no-location/android/app/build.gradle
index 2a391427..74272196 100644
--- a/examples/demo-no-location/android/app/build.gradle
+++ b/examples/demo-no-location/android/app/build.gradle
@@ -78,9 +78,9 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
- namespace "com.onesignal.example"
+ namespace "com.onesignal.sdkdemo"
defaultConfig {
- applicationId "com.onesignal.example"
+ applicationId "com.onesignal.sdkdemo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
diff --git a/examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainActivity.kt b/examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainActivity.kt
similarity index 96%
rename from examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainActivity.kt
rename to examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainActivity.kt
index 8527f6fb..77581ea1 100644
--- a/examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainActivity.kt
+++ b/examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainActivity.kt
@@ -1,4 +1,4 @@
-package com.onesignal.example
+package com.onesignal.sdkdemo
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
diff --git a/examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainApplication.kt b/examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainApplication.kt
similarity index 96%
rename from examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainApplication.kt
rename to examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainApplication.kt
index 05522e0f..de75de91 100644
--- a/examples/demo-no-location/android/app/src/main/java/com/onesignal/example/MainApplication.kt
+++ b/examples/demo-no-location/android/app/src/main/java/com/onesignal/sdkdemo/MainApplication.kt
@@ -1,4 +1,4 @@
-package com.onesignal.example
+package com.onesignal.sdkdemo
import android.app.Application
import com.facebook.react.PackageList
diff --git a/examples/demo-no-location/package.json b/examples/demo-no-location/package.json
index 2c894442..746f2641 100644
--- a/examples/demo-no-location/package.json
+++ b/examples/demo-no-location/package.json
@@ -10,7 +10,7 @@
"ios": "bash ../run-ios.sh",
"pods": "bundle install && (cd ios && ONESIGNAL_DISABLE_LOCATION=true bundle exec pod install)",
"update:pods": "(cd ios && ONESIGNAL_DISABLE_LOCATION=true pod update OneSignalXCFramework --no-repo-update)",
- "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.example >/dev/null 2>&1 || true",
+ "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.sdkdemo >/dev/null 2>&1 || true",
"clean:ios": "rm -rf ios/build ios/Pods",
"start": "react-native start"
},
diff --git a/examples/demo/.env.example b/examples/demo/.env.example
index 10c390f0..e0cdf10e 100644
--- a/examples/demo/.env.example
+++ b/examples/demo/.env.example
@@ -1,5 +1,5 @@
-# Default App ID (used if ONESIGNAL_APP_ID is empty): 77e32082-ea27-42e3-a898-c72e141824ef
-ONESIGNAL_APP_ID=your-onesignal-app-id
+# Required. The Metro bundle fails when this is unset.
+ONESIGNAL_APP_ID=
ONESIGNAL_API_KEY=your-onesignal-api-key
# Optional: Android Notification Channel ID for the WITH SOUND test notification.
diff --git a/examples/demo/.gitignore b/examples/demo/.gitignore
index d1b390a3..2b08a2e2 100644
--- a/examples/demo/.gitignore
+++ b/examples/demo/.gitignore
@@ -1,5 +1,6 @@
# Environment
.env
+android/app/google-services.json
.rn-demo-env.stamp
# OSX
diff --git a/examples/demo/README.md b/examples/demo/README.md
index c4925e47..40089f72 100644
--- a/examples/demo/README.md
+++ b/examples/demo/README.md
@@ -2,7 +2,7 @@
Reference app for `react-native-onesignal`. It showcases SDK features including push notifications, in-app messaging, user management, tags, triggers, outcomes, live activities, and more, using the SDK packed from this repository.
-The demo uses package/bundle id `com.onesignal.example`.
+The demo uses Android package `com.onesignal.sdkdemo` and iOS bundle id `com.onesignal.example`.
## Prerequisites
@@ -28,16 +28,18 @@ cp .env.example .env
Set your OneSignal credentials in `.env`:
```sh
-ONESIGNAL_APP_ID=your-onesignal-app-id
+ONESIGNAL_APP_ID=
ONESIGNAL_API_KEY=your-onesignal-api-key
ONESIGNAL_ANDROID_CHANNEL_ID=
```
-- `ONESIGNAL_APP_ID`: falls back to a built-in default App ID when empty.
+- `ONESIGNAL_APP_ID`: required. `metro.config.js` fails the bundle when it's unset.
- `ONESIGNAL_API_KEY`: REST API key, used to update and end live activities. Sending notifications from the demo doesn't need it.
- `ONESIGNAL_ANDROID_CHANNEL_ID`: optional Android notification channel for the sound test notification. Falls back to a built-in default channel.
-The OneSignal app needs FCM credentials for Android and APNs credentials for the `com.onesignal.example` bundle ID on iOS.
+The OneSignal app needs FCM credentials for the `com.onesignal.sdkdemo` Android package and APNs credentials for the `com.onesignal.example` bundle ID on iOS.
+
+To use Firebase on Android, put a `google-services.json` with a `com.onesignal.sdkdemo` client in `android/app/`. It's gitignored, and the Google Services plugin is applied only when it exists. Pass `-PFIREBASE_INSTALLATION_ID_ENABLED=true` to Gradle to turn on Firebase Installation ID registration; the build fails if the flag is on without the file.
For iOS, install CocoaPods on first run:
@@ -63,12 +65,12 @@ It then builds and launches the app with the React Native CLI, which starts Metr
## Other scripts
-| Script | Purpose |
-| ---------------------- | -------------------------------------------------------------------- |
-| `vp run setup` | Build, pack, and install the SDK into the demo. |
-| `vp run start` | Start Metro. |
-| `vp run update:pods` | Run `pod update OneSignalXCFramework` after native SDK changes. |
-| `vp run clean:android` | Wipe Android build outputs and uninstall the app from the device. |
+| Script | Purpose |
+| ---------------------- | --------------------------------------------------------------------- |
+| `vp run setup` | Build, pack, and install the SDK into the demo. |
+| `vp run start` | Start Metro. |
+| `vp run update:pods` | Run `pod update OneSignalXCFramework` after native SDK changes. |
+| `vp run clean:android` | Wipe Android build outputs and uninstall the app from the device. |
| `vp run clean:ios` | Wipe iOS build outputs and `ios/Pods`. Run `pod install` again after. |
## Testing iOS Action Button Icons
diff --git a/examples/demo/android/app/build.gradle b/examples/demo/android/app/build.gradle
index f4d3e73a..186568dd 100644
--- a/examples/demo/android/app/build.gradle
+++ b/examples/demo/android/app/build.gradle
@@ -73,18 +73,29 @@ def enableProguardInReleaseBuilds = true
*/
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'
+def hasGoogleServices = file("google-services.json").exists()
+
+// Off by default so local builds keep the legacy token path. E2E opts in with
+// `-PFIREBASE_INSTALLATION_ID_ENABLED=true`; the flag does nothing without the default FirebaseApp.
+def firebaseInstallationIdEnabled =
+ (findProperty("FIREBASE_INSTALLATION_ID_ENABLED") ?: "false").toString().trim().toBoolean()
+if (firebaseInstallationIdEnabled && !hasGoogleServices) {
+ throw new GradleException("FIREBASE_INSTALLATION_ID_ENABLED requires examples/demo/android/app/google-services.json")
+}
+
android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
- namespace "com.onesignal.example"
+ namespace "com.onesignal.sdkdemo"
defaultConfig {
- applicationId "com.onesignal.example"
+ applicationId "com.onesignal.sdkdemo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
+ manifestPlaceholders.firebaseInstallationIdEnabled = firebaseInstallationIdEnabled.toString()
}
signingConfigs {
debug {
@@ -127,6 +138,8 @@ apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
+ // OneSignal resolves firebase-messaging 24.x; Installation ID registration needs 25.1.2+.
+ implementation("com.google.firebase:firebase-messaging:25.1.3")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
@@ -134,3 +147,7 @@ dependencies {
implementation jscFlavor
}
}
+
+if (hasGoogleServices) {
+ apply plugin: "com.google.gms.google-services"
+}
diff --git a/examples/demo/android/app/src/main/AndroidManifest.xml b/examples/demo/android/app/src/main/AndroidManifest.xml
index 0050d432..0c0624b2 100644
--- a/examples/demo/android/app/src/main/AndroidManifest.xml
+++ b/examples/demo/android/app/src/main/AndroidManifest.xml
@@ -13,6 +13,10 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="${usesCleartextTraffic}"
android:supportsRtl="true">
+
+
/dev/null 2>&1 || true",
+ "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.sdkdemo >/dev/null 2>&1 || true",
"clean:ios": "rm -rf ios/build ios/Pods",
"start": "react-native start"
},
diff --git a/examples/demo/src/hooks/useOneSignal.ts b/examples/demo/src/hooks/useOneSignal.ts
index eb1d4707..3e20af33 100644
--- a/examples/demo/src/hooks/useOneSignal.ts
+++ b/examples/demo/src/hooks/useOneSignal.ts
@@ -28,10 +28,9 @@ import { log } from '../services/LogService';
import OneSignalApiService from '../services/OneSignalApiService';
import PreferencesService from '../services/PreferencesService';
-const DEFAULT_APP_ID = '77e32082-ea27-42e3-a898-c72e141824ef';
-
+// metro.config.js fails the bundle when this is unset.
function resolveAppId(): string {
- return ONESIGNAL_APP_ID?.trim() || DEFAULT_APP_ID;
+ return ONESIGNAL_APP_ID.trim();
}
const apiService = OneSignalApiService.getInstance();