OneSignal
Integrate the OneSignal platform to display custom local notifications with Notify Kit.
OneSignal is a platform for sending cloud messages to mobile devices.
Version scope: this guide targets
react-native-onesignalversions prior to 4.0.0. Modern versions (4.x and later) restructured their native dependencies and no longer require the Firebase-module excludes described below — follow OneSignal's current React Native setup documentation instead.
In their react-native documentation they describe several things you must do, but users here have noticed incompatibilities (and also here) when following the documentation because the older OneSignal libraries pulled in conflicting Firebase modules.
With special thanks to users Ashok Kumar and burhanDebug and zaweisise for helping us figure it out and confirm a solution, this is how to integrate Notify Kit with OneSignal:
- Do not use the onesignal gradle plugin (currently step 3.2 in their documentation)
- If using a
react-native-onesignalversion earlier than 4.0.0 - editnode_modules/react-native-onesignal/android/build.gradle:
In the android dependencies modify the api ('com.onesignal:OneSignal:3.15.1') to
api ('com.onesignal:OneSignal:3.15.1') {
exclude group: 'com.google.android.gms', module: 'play-services-location'
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-ads-identifier'
exclude group: 'com.google.firebase', module: 'firebase-messaging'
}
We understand that editing files directly in node_modules is unconventional advice, we strongly recommend the use of patch-package in order to manage this change.
patch-package will make a patch for this change that you put in source control, it will reliably install the patch when you install npm packages, and it will give you a friendly warning in case One Signal updates their module.
To use patch-package in this case follow these steps:
- Clean out android build items so they do not clutter the patch:
cd android && ./gradlew clean && cd .. - Install patch-package according to their docs (
mkdir patchesand edit package.json to add patch-package to your postinstall) - Create the patch:
npx patch-package react-native-onesignal - Add the patch to source control (for example for git
git add patches && git commit)
