react-native-batch-push icon indicating copy to clipboard operation
react-native-batch-push copied to clipboard

[Android] Provider "FCM" could not register for push

Open pierpo opened this issue 5 years ago • 7 comments

I've been struggling a lot to setup Batch for Android. I did an install with the newest react-native and newest firebase module versions. And yet, I had the following error in logcat:

Push - Provider "FCM" could not register for push: Firebase Core is missing. Did you add 'com.google.firebase:firebase-core' to your gradle dependencies?

After investigation, it turns out that the following line was reporting this issue https://github.com/BatchLabs/Batch-Android-SDK/blob/af04acfd6d6bcca28280c45d12ac52e83baaa10e/Sources/sdk/src/main/java/com/batch/android/push/FCMRegistrationProvider.java#L110

The error was thrown by this line: https://github.com/BatchLabs/Batch-Android-SDK/blob/af04acfd6d6bcca28280c45d12ac52e83baaa10e/Sources/sdk/src/main/java/com/batch/android/push/FCMRegistrationProvider.java#L158

So, the class "com.google.firebase.iid.FirebaseInstanceId" was missing. I still don't understand why this class was not available...

A solution I found was yarn add @react-native-firebase/iid. Somehow, this provides the missing class.

I thought this could help. I don't know if this needs to be documented or not, since I'm still not sure if I made a mistake somewhere during the installation process.

pierpo avatar Aug 11 '21 09:08 pierpo

Hello!

Thanks for your feedback.

This class might be missing if you're using the latest Firebase Messaging library, which made the iid classes not part of the standard distribution but available as an addon, as you've noticed.

Support for the new API (FCM Tokens) is coming in a future SDK release, but in the meantime we have added some documentation to work around the issue for our native SDK. Looks like our React Native doc is missing this.

Rest assured that IID will work perfectly for the time being as google deprecated it but didn't announce any shutdown date. Both APIs are functionally equivalent too.

We'll update our documentation with your suggestion.

Thanks!

abarisain avatar Aug 11 '21 11:08 abarisain

Hi,

Fantastic, glad to hear that you will update the docs 😊 You may close the issue once this is done!

Thanks!

pierpo avatar Aug 12 '21 10:08 pierpo

Unfortunately iid causes an error on iOS

image

https://github.com/invertase/react-native-firebase/issues/3746

Actually the iid package doesn't even exist anymore in react-native-firebase. Is there any other way around?

pierpo avatar Aug 12 '21 14:08 pierpo

I downgraded everything to the latest iid version. Looks like everything works on iOS and Android.

{
  "dependencies": {
    "@react-native-firebase/app": "11.5.0",
    "@react-native-firebase/crashlytics": "11.5.0",
    "@react-native-firebase/iid": "11.5.0",
    "@react-native-firebase/messaging": "11.5.0",
    "@react-native-firebase/perf": "11.5.0",
  }
}

pierpo avatar Aug 12 '21 15:08 pierpo

instead of downgrading everything its also possible to exclude the autolink for iOS adding this on the react-native.config.js:

 '@react-native-firebase/iid': {
      platforms: {
        ios: null,
      },
    },

susanapons89 avatar Nov 02 '21 11:11 susanapons89

See official Batch Android SDK Doc: https://doc.batch.com/android/sdk-integration#adding-push-notifications-support

Note: If you're using firebase-core >= 19.0 and firebase-messaging >= 22.0, please add the Firebase Installations library to your dependencies or you will not be able to receive push notifications: implementation "com.google.firebase:firebase-iid:21.1.0". A future SDK release will bring support for FCM Tokens. You can also try downgrading firebase-messaging to 21.0 by editing the firebaseMessagingVersion variable.

You can also just patch your build.gradle for Android.

Aure77 avatar Nov 08 '21 14:11 Aure77

Thanks @pierpo for your contribution. I'm closing this issue as Batch released a new version and this repository is being archived.

This should be addressed in https://github.com/BatchLabs/Batch-React-Native-Plugin

marekkalnik avatar Jul 28 '22 09:07 marekkalnik