OneSignal

Integrate the OneSignal platform to display custom local notifications with Notifee.

OneSignal is a platform for sending cloud messages to mobile devices

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 One Signal libraries appear to be a bit out of date.

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 notifee with OneSignal:

  • Do not use the onesignal gradle plugin (currently step 3.2 in their documentation)
  • 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:

  • 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 patches and 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)

Copyright 2020 - 2021 © Invertase Limited

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License and code samples are licensed under the Apache 2.0 License.

All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.