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-onesignal versions 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:

  1. Do not use the onesignal gradle plugin (currently step 3.2 in their documentation)
  2. If using a react-native-onesignal version earlier than 4.0.0 - edit node_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:

  1. Clean out android build items so they do not clutter the patch: cd android && ./gradlew clean && cd ..
  2. Install patch-package according to their docs (mkdir patches and edit package.json to add patch-package to your postinstall)
  3. Create the patch: npx patch-package react-native-onesignal
  4. Add the patch to source control (for example for git git add patches && git commit)