Amplify-js: I keep getting undefined is not an object (evaluating 'RNPushNotification.initialize')

Created on 4 May 2018  路  7Comments  路  Source: aws-amplify/amplify-js

Hi Guys,

I literally followed all the steps detailed in this guide -> https://aws.github.io/aws-amplify/media/push_notifications_setup#configure-your-app

However, when I try to include the push notifications in my React native project I get the following error. Not sure what I am doing wrong, I have done react-native link, uninstalled, re-linked, installed the amplify lib as a project dependency.

screenshot_1525448046

Still same error :(

Please see my package.json dependencies below

"dependencies": { "aws-amplify": "^0.3.3", "aws-amplify-react-native": "^0.2.9", "moment": "^2.22.1", "moment-timezone": "^0.5.16", "prop-types": "^15.6.1", "react": "16.3.1", "react-native": "0.55.3", "react-native-elements": "^0.19.1", "react-native-vector-icons": "^4.6.0", "react-navigation": "^1.5.11" },

documentation good first issue investigating

Most helpful comment

@oluomoniyi

  1. make your android/settings.gradle like:
rootProject.name = 'pushnotificationdemo'
include ':aws-amplify-react-native'
project(':aws-amplify-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/aws-amplify-react-native/android')

include ':app'
  1. in your android/app/build.gradle:
dependencies {
    compile project(':aws-amplify-react-native')

   // ....
}
  1. in your android/app/main/..../MainApplication.java:
@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNPushNotificationPackage()
      );
    }

Also there was some changes merged in the doc yesterday so please check that again.

All 7 comments

Can you make sure the push notification package is correctly linked into your app? You can check android/app/src/main/.../MainApplication.java to see if it is under getPackages()

@powerful23 thanks for the reply. I had a look in the android/app/src/main/.../MainApplication.java file the only packages imported are React native packages.

However when I run react native link it is always successful. I am guessing there is a bit of an issue with the linking process

Is there a way to manually add the package?

@oluomoniyi

  1. make your android/settings.gradle like:
rootProject.name = 'pushnotificationdemo'
include ':aws-amplify-react-native'
project(':aws-amplify-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/aws-amplify-react-native/android')

include ':app'
  1. in your android/app/build.gradle:
dependencies {
    compile project(':aws-amplify-react-native')

   // ....
}
  1. in your android/app/main/..../MainApplication.java:
@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNPushNotificationPackage()
      );
    }

Also there was some changes merged in the doc yesterday so please check that again.

Hi guys!
Im having the same issue as @oluomoniyi in an _almost_ bare project
Already tried @powerful23 suggestion but getting the same error.
Any ideas?

@powerful23 followed the steps you suggested and like @nachocifu still getting the error.

I think the root cause of this issue is that the aws-amplify-react-native module is not correctly linked into your project. You may try out a new blank project and follow the docs step by step and if it works, check out the android folder to see how it links the module.

I think I got it probably an obvious one @nachocifu @powerful23 but after you add the package to MainApplication.java you need to run the react-native run-android command (not npm start) to rebuild and reinstall the app on the emulator.

Quick way to test if you actually have access to push notifications in your react native project.

import { NativeModules} from 'react-native';
console.log("Should return RNPushNotification method", NativeModules.RNPushNotification);

Another thing to note before adding the below in your, android/app/main/..../MainApplication.java: make sure your import import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage; at the top of the file.

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNPushNotificationPackage()
      );
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

josoroma picture josoroma  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments

cgarvis picture cgarvis  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

callmekatootie picture callmekatootie  路  3Comments