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

No task registered for key RNFirebaseBackgroundMessage #1174

Closed
kishanj918 opened this issue Jun 5, 2018 · 19 comments
Closed

No task registered for key RNFirebaseBackgroundMessage #1174

kishanj918 opened this issue Jun 5, 2018 · 19 comments
Labels
help: general General help wanted help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. plugin: messaging FCM only - ( messaging() ) - do not use for Notifications
Milestone

Comments

@kishanj918
Copy link

kishanj918 commented Jun 5, 2018

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

@Ehesp Ehesp added the plugin: messaging FCM only - ( messaging() ) - do not use for Notifications label Jun 5, 2018
@kishanj918 kishanj918 changed the title Getting error from fabric.io com.facebook.react.common.JavascriptException: No task registered for key RNFirebaseBackgroundMessage No task registered for key RNFirebaseBackgroundMessage Jun 5, 2018
@bunea
Copy link

bunea commented Jun 5, 2018

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!

@kishanj918
Copy link
Author

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

@bunea
Copy link

bunea commented Jun 5, 2018

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

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

from your AndroidManifest.xml

@kishanj918
Copy link
Author

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

@luskin
Copy link

luskin commented Aug 7, 2018

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

@luskin
Copy link

luskin commented Sep 2, 2018

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

@Salakar Salakar reopened this Sep 27, 2018
@Salakar
Copy link
Member

Salakar commented Sep 27, 2018

Re-opened as per @luskin 's request.

@pscarey
Copy link

pscarey commented Oct 2, 2018

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.

@Salakar Salakar added help: general General help wanted Hacktoberfest labels Oct 2, 2018
@luskin
Copy link

luskin commented Oct 2, 2018

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

@pscarey
Copy link

pscarey commented Oct 9, 2018

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.

@LuisRizo
Copy link

LuisRizo commented Oct 12, 2018

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.

@pscarey
Copy link

pscarey commented Oct 24, 2018

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

@Salakar Salakar modified the milestones: v5.1.0, v5.2.0 Oct 31, 2018
@Salakar Salakar added docs help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. and removed Hacktoberfest labels Oct 31, 2018
@Salakar
Copy link
Member

Salakar commented Jan 4, 2019

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 😞

@Salakar Salakar modified the milestones: v5.2.0, v6.0.0 Jan 4, 2019
@rasom
Copy link

rasom commented Jan 14, 2019

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.

@ikhattab
Copy link

ikhattab commented Apr 5, 2019

Sorry to ask again but any updates about this issue?

@Salakar
Copy link
Member

Salakar commented Apr 5, 2019

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.

@taylorkline
Copy link

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?

@mikehardy
Copy link
Collaborator

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 ☕ and read through that and it will likely be eye-opening

@Salakar
Copy link
Member

Salakar commented May 3, 2019

Hey all, this has landed on React Native master in facebook/react-native#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: react-native-community/releases#116 (comment) please track this there

@Salakar Salakar closed this as completed May 3, 2019
@invertase invertase locked as resolved and limited conversation to collaborators May 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help: general General help wanted help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. plugin: messaging FCM only - ( messaging() ) - do not use for Notifications
Projects
None yet
Development

No branches or pull requests