React-native-firebase: No task registered for key RNFirebaseBackgroundMessage

Created on 5 Jun 2018  路  19Comments  路  Source: invertase/react-native-firebase

Issue Description

I have installed fabric for crash reporting. I have released build to play store. I am getting this crash in fabric in new release. I am not getting this error in debug. Basically i am trying to set local schedule notification in app.

Environment

  • React Native Navigation version: "react-native-navigation": "^1.1.458"
  • React Native version: "react-native": "0.55.4"
  • Platform(s) (iOS, Android, or both?): Android only
  • Device info (Simulator/Device? OS version? Debug/Release?): Release (It's Uploaded on playstore)
Fatal Exception: com.facebook.react.common.JavascriptException: No task registered for key RNFirebaseBackgroundMessage, stack:
startHeadlessTask@281:2354
value@28:3582
<unknown>@28:1067
value@28:3009
value@28:1039

       at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:56)
       at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:40)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
       at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
       at android.os.Looper.loop(Looper.java:164)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
       at java.lang.Thread.run(Thread.java:764)

screen shot 2018-06-05 at 11 04 27 am

General Good First Issue Messaging Docs

Most helpful comment

@kishanj918 If you don't need data only notifications you can remove

<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

from your AndroidManifest.xml

All 19 comments

It happens because you did not follow the optional steps listed here. Unfortunately if you followed the steps and added the RNFirebaseBackgroundMessagingService those steps should not be optional as it will lead to crashes because the headless task can not be found.

Documentation should be updated to reflect this. RNFirebaseBackgroundMessagingService will crash the app if the headless task is not registered as well!

@bunea But i am setting up local notifications only. Still i have to do this for local also? they didn't mention it for local.

@kishanj918 If you don't need data only notifications you can remove

<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

from your AndroidManifest.xml

@bunea thanks! will give it a try. for now closing this.

Can we re-open? I am seeing this thousands of times and have combed through the documentation. The odd part is that it looks to be working (the functionality of the background handler) but still receiving tons of crashes on crashlytics, see attached:

screen shot 2018-08-07 at 10 59 25 am

AndroidManifest.xml:

<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

MainApplication.java:

  @Override
  public void onCreate() {
    super.onCreate();
    System.out.println("----- START ANDROID APP -----");
    SoLoader.init(this, false);
    ..........
  }

In start() of React Native App: AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => backgroundNotificationHandler)

const backgroundNotificationHandler = async () => {
  Log('Received Background Notification', ':satellite:')
  await fetchCurrentLocation()
  return Promise.resolve()
}

@kishanj918 Can you re-open this please? We are still receiving this error.

Re-opened as per @luskin 's request.

We're experiencing the same error in prod. Current attempt to fix is to upgrade from:
'com.google.firebase:firebase-messaging:17.3.0' -> 'com.google.firebase:firebase-messaging:17.3.2'

Release notes on version bump indicate a potential issue/fix:
Update - September 18, 2018
Cloud Messaging version 17.3.2
Fixed an issue that would occasionally cause apps to crash with Android Not Responding (ANR) errors when receiving a message.
https://firebase.google.com/support/release-notes/android#latest_sdk_versions

Will report back on results. Thought I'd share in case it helps someone else before we have definitive results.

Thanks @pscarey, curious to see how this works out for you.

At this stage, it looks like our error rates have dropped. IIRC, we also had to tweak some other dependencies to get the upgraded libraries to build.

I had this crash when sending data-only notifications to my android app with RN version 55.4, and RNF version 4.3.8.
I was missing the optional steps of adding the headless task to my app. Following the steps in the guide:
https://rnfirebase.io/docs/v4.3.x/messaging/receiving-messages#4)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background
fixed the crash.

Our root cause was writing AppRegistry.registerComponent rather than AppRegistry.registerHeadlessTask.

I'm not entirely sure what to do with this one right now, there's no way in React Native on the Android side to detect whether AppRegistry.registerHeadlessTask has been called to register a task - the Error is thrown in JS as well so I can't even catch it in the Android service.

Open to suggestions? It is pretty much a case of documentation but then it'd be better if it could not crash if you forget to register a task, kind of makes the optional step not optional as well 馃槥

In our case, this exception happens if app was force closed. RNFMessagingService continues receiving messages but when these messages are passed to the headless task "No task registered for key RNFirebaseBackgroundMessage" exception is thrown.

Sorry to ask again but any updates about this issue?

I will see what I can do for this on the v5.3.0 release today but as mentioned above I'm not sure what I can do based on the limitations.

Is there a reason why this error would occur if we never send any data-only messages? Yes, we currently have our setup misconfigured such that the service is in the AndroidManifest.xml but we don't have a background message handler, but why would that even be triggered?

If you ever use apkanalyzer you will be surprised at the amount of things firebase injects. I'm guessing it's one of those

e.g.
apkanalyzer manifest print android/app/build/outputs/apk/dev/debug/app-dev-universal-debug.apk

Get a cup of :coffee: and read through that and it will likely be eye-opening

Hey all, this has landed on React Native master in https://github.com/facebook/react-native/pull/24671 thanks to @timwangdev 馃帀 this change means it will no longer throw an exception but instead warn - making tasks optional now.

I've made a request to get it cherry-picked into the RN 0.60.x release: https://github.com/react-native-community/releases/issues/116#issuecomment-489066854 please track this there

Was this page helpful?
0 / 5 - 0 ratings