React-native-fcm: "undefined is not an object" ANDROID PROBLEM

Created on 19 Sep 2016  路  15Comments  路  Source: evollu/react-native-fcm

Hi, i try to install your component.

On iOS all works fine, but on Android when i call FCM.requestPermissions(); or FCM.getFCMToken().then(token => {}})

Error:
undefined is not an object (evaluating 'RNFIRMessaging.requestPermissions')

I have this component installed previously but i dont think its relevant
https://github.com/evollu/react-native-firebase-analytics

PD: I have import FCM from 'react-native-fcm';

media-20160919

Most helpful comment

public class MainApplication extends Application implements ReactApplication {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new FIRMessagingPackage()
      );
    }
}

All 15 comments

馃憤 having the same problem.

we ran react-native link and console.log(FCM) shows us the object attributes. As soon as we call one we get an undefined is not an object.

RNFIRMessaging is undefined here:

FCM.getBadgeNumber = () => {
    return RNFIRMessaging.getBadgeNumber();
}

Any suggestions?

U r probably not linking the android project in a correct way

@sibelius yes it probably is that - although we ran the usual react-native link command. Any suggestions for how to double check successful linking?

Project compile, and i did all steps on readme... I think it is linking correctly

public class MainApplication extends Application implements ReactApplication {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new FIRMessagingPackage()
      );
    }
}

clean project on android studio and try to build again

I am getting the below error when I run react-native run-android. Could this be part of the problem?

google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.

I have added apply plugin: "com.google.gms.google-services" to the android/app/build.gradle.

Btw thanks for the help!!

@sibelius Lol! My bad! Thanks! I havnt it. What i have to import to add this?

public class MainApplication extends Application implements ReactApplication {
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new FIRMessagingPackage()
      );
    }
}

android studio can help fix import stuff

import com.evollu.react.fcm.FIRMessagingPackage;

O true, sorry, my bad habit of use Atom for all xd Thanks!

Now dont crash, but app in Android dont give token :s xD Tomorrow i will see it with more detail

Fixed, just went through everything again and had no problems second time around.

Thanks!

On android Notifications from Firebase console arrive, but dont give Token and dont call Component method to receive notifications with app Open. But with app closed or in background the notifications arrive correctly :s

EDIT: It fixed alone xd thanks all

react-native link doesn't seem to correctly add the code to MainApplication.java - why is that?

same question that @mypark here! any ideas?

@sibelius thank you. Finally, it works!

Was this page helpful?
0 / 5 - 0 ratings