react-native-notifications: registerRemoteNotificationsRegistered not triggered on Android

I have installed the library following all the steps in the documentaiton, created the app on firebase using the SHA-1 from the project (generating using gradle), downloaded the google-services.json file and add it under the folder app.

Here’s the code:

  useEffect(() => {
    Notifications.events().registerRemoteNotificationsRegistered(
      ({ deviceToken }) => {}
    );

    Notifications.events().registerRemoteNotificationsRegistrationFailed(
      (event) => {
        console.error(event);
      }
    );
  }, []);

But the registerRemoteNotificationsRegistered is not triggered, neither registerRemoteNotificationsRegistrationFailed.

The only step I’m missing from the guide is the four (https://wix.github.io/react-native-notifications/docs/installation-android) because apply plugin: 'com.google.gms.google-services' cause the build to fail.

Some problems were found with the configuration of task ':react-native-notifications:processReactNative60DebugGoogleServices' (type 'GoogleServicesTask').
  - In plugin 'com.google.gms.google-services' type 'com.google.gms.googleservices.GoogleServicesTask' field 'intermediateDir' without corresponding getter has been annotated with @OutputDirectory.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'intermediateDir'.
      2. Remove the annotations on 'intermediateDir'.

Here is the version: react-native: 0.71.4 => 0.71.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15

Most upvoted comments

What solved the problem for me was calling registerRemoteNotificationsRegistered before calling registerRemoteNotifications, unlike how the docs suggest.

Using react-native 0.72.3 with the workaround from https://github.com/wix/react-native-notifications/issues/975#issuecomment-1623856736 .

android/build.gradle contains classpath("com.google.gms:google-services:4.3.15")

android/app/build.gradle contains:

    implementation project(':react-native-notifications')

    implementation platform('com.google.firebase:firebase-bom:32.2.0')
    implementation "com.google.firebase:firebase-messaging"

I followed all the steps at https://wix.github.io/react-native-notifications/docs/installation-android/ but I can’t get registerRemoteNotificationsRegistered() to return a token while running on Android. I’m on react-native 0.71.7. The registration event never occurs.

      Notifications.registerRemoteNotifications()

        Notifications.events().registerRemoteNotificationsRegistered(event => {
            // TODO: Send the token to my server so it could send back push notifications...
            console.log('Device Token Received', event.deviceToken)
        })
        Notifications.events().registerRemoteNotificationsRegistrationFailed(event => {
            console.error(event)
        })

I’m suspecting that Notifications.registerRemoteNotifications() is busted. How to debug it?

@jkoutavas, instead of adding this lines to ./android/app/build.gradle:

dependencies {
    ...
    implementation project(':react-native-notifications')
    implementation 'com.google.firebase:firebase-core:16.0.0'
} 

as said in docs (https://wix.github.io/react-native-notifications/docs/installation-android), add this:

dependencies {
    ...
    implementation project(':react-native-notifications')
    implementation platform('com.google.firebase:firebase-bom:32.0.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
}

In your top build.gradle instead of classpath 'com.google.gms:google-services:4.0.0' Try this: classpath ("com.google.gms:google-services:4.3.15")

It’s what the docs in firebase say to do, and it doesnt cause the app to crash

@Isurumw Thanks. The same: ios is fine, android - only with disabled new architecture (newArchEnabled=false in android/gradle.properties).

I’m still having this same issue with React-native version 0.78.0, only for Android but working fine for iOS

It worked for me again by disabling the new architecture for Android.

I don’t think the issues are related, the gradle problems and not receiving the tokens. I didnt have my gradle set up properly but still received tokens. Just had other issues such as the one at the beginning of this post.

Check again, for completeness. Make sure you completed these correctly:

Also, make sure your FCM is set up sorrectly

Yep I also had this issue and fixed it as above. There’s also a PR open to update the docs: #953.

This issue can be closed.