Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I keep getting undefined is not an object (evaluating 'RNPushNotification.initialize') #790

Closed
oluomoniyi opened this issue May 4, 2018 · 7 comments

Comments

Projects
None yet
5 participants
@oluomoniyi
Copy link
Contributor

commented May 4, 2018

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" },

@powerful23

This comment has been minimized.

Copy link
Contributor

commented May 4, 2018

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()

@elorzafe elorzafe self-assigned this May 7, 2018

@oluomoniyi

This comment has been minimized.

Copy link
Contributor Author

commented May 8, 2018

@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?

@powerful23

This comment has been minimized.

Copy link
Contributor

commented May 8, 2018

@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.

@nachocifu

This comment has been minimized.

Copy link

commented May 12, 2018

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?

@oluomoniyi

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2018

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

@powerful23

This comment has been minimized.

Copy link
Contributor

commented May 14, 2018

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.

@oluomoniyi

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2018

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()
      );
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.