Issue #461 I got the following error message. package com.wix.reactnativenotifications does not exist I fixed it by making the following changes. 1. Added the following line to Project/app/build.gradle implementation project(':react-native-notifications') 2. Changed the following lines in MainApplication.java - protected List<ReactPackage> getPackages() { - return Arrays.<ReactPackage>asList( - new MainReactPackage(), - // ... - // Add this line: - new RNNotificationsPackage(MainApplication.this) + protected List<ReactPackage> getPackages() { + @SuppressWarnings("UnnecessaryLocalVariable") + List<ReactPackage> packages = new PackageList(this).getPackages(); + // ... + // Add this line: + packages.add(new RNNotificationsPackage(MainApplication.this)); + return packages; + }
2.3 KiB
Executable File
id, title, sidebar_label
| id | title | sidebar_label |
|---|---|---|
| installation-android | Android Installation | Android Installation |
Add the library to your application class (e.g. MainApplication.java):
import com.wix.reactnativenotifications.RNNotificationsPackage;
...
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// ...
// Add the following line:
packages.add(new RNNotificationsPackage(MainApplication.this));
return packages;
}
Receiving push notifications
Note: This section is only necessary in case you wish to be able to receive push notifications in your React-Native app.
Push notifications on Android are managed and dispatched using Google's FCM service. The following installation steps are a TL;DR of Google's FCM setup guide. You can follow them to get FCM integrated quickly, but we recommend that you will in the very least have a peek at the guide's overview.
Step #1: Subscribe to Google's FCM
To set FCM in your app, you must first create a google-services.json file. If you have no existing API project yet, the easiest way to go about in creating one is using this step-by-step installation process;
Step #2: Copy google-services.json
After creating google-services.json, copy it into your project's android/app folder.
Step #3: Add google-services package to Project/build.gradle
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.0.0'
}
}
Step #4: Add firebase-core package and apply google-services plugin in Project/app/build.gradle
dependencies {
...
implementation project(':react-native-notifications')
implementation 'com.google.firebase:firebase-core:16.0.0'
}
apply plugin: 'com.google.gms.google-services'
Step #5: Link react-native-notifications in Project/android/settings.gradle
include ':react-native-notifications'
project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/lib/android/app')