π [firebase_messaging] `onBackgroundMessage` throws NoSuchMethodError on Android.
Bug report
Describe the bug
Simply, use firebase_messaging package and set onBackgroundMessage callback, then the app throws some exception below:
NoSuchMethodError: No top-level getter '_registerPlugins' declared.
Receiver: top-level
Tried calling: _registerPlugins
In my environment, the stack trace was missing so that no further information could be obtained.

Steps to reproduce
Check my example project that reproduces this issue for details.
( A google-services.json is not committed, so please use your own Firebase project when try to run this. )
- Use Flutter version 2.0.4 (currently latest version of stable channel).
- Import
firebase_messaging: ^9.1.1 - Set callback function for background message.
- Turn on
Break on exceptionsfeature in Android Studio, and run app.
Expected behavior
Just run app with no errors.
Flutter doctor
Run flutter doctor and paste the output below:
Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[β] Flutter (Channel stable, 2.0.4, on macOS 11.1 20C69 darwin-x64, locale ja-JP)
[β] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[β] Xcode - develop for iOS and macOS
[β] Chrome - develop for the web
[β] Android Studio (version 4.1)
[β] IntelliJ IDEA Ultimate Edition (version 2020.3.2)
[β] IntelliJ IDEA Community Edition (version 2020.3.2)
[β] VS Code (version 1.55.0)
[β] Connected device (3 available)
β’ No issues found!
Flutter dependencies
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
Dart SDK 2.12.2
Flutter SDK 2.0.4
firebase_playground 1.0.0+1
dependencies:
- firebase_core 1.0.3 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 9.1.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
transitive dependencies:
- async 2.5.0 [collection]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.2.0
- clock 1.1.0
- collection 1.15.0
- fake_async 1.2.0 [clock collection]
- firebase_core_platform_interface 4.0.0 [flutter meta plugin_platform_interface]
- firebase_core_web 1.0.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 2.1.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 1.0.4 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- js 0.6.3
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- path 1.8.0
- plugin_platform_interface 2.0.0 [meta]
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- vector_math 2.1.0
@Kurogoma4D The error:
NoSuchMethodError: No top-level getter '_registerPlugins' declared.
Receiver: top-level
Tried calling: _registerPlugins
indicates that it cannot find the value _registerPlugins in global scope because it may not have been imported or could be due to a parse error before the import.
Can you try running flutter analyze and see if it reports anything related to _registerPlugins ?
Also, can you also try the official flutter_messaging plugin example and see if you get similar error with it too or not ?
@darshankawar
flutter analyze result is here:
$ flutter analyze
Analyzing firebase_playground...
No issues found! (ran in 2.5s)
And I tried running firebase_messaging v9.1.1 example project, I got same error:

Thanks for checking. I think this is coming from after calling
// Set the background messaging handler early on, as a named top-level function
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
Which in turn calls:
await channel.invokeMapMethod('Messaging#startBackgroundIsolate', {
'pluginCallbackHandle': bgHandle.toRawHandle(),
'userCallbackHandle': userHandle.toRawHandle(),
});
And finally here:
Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async {
assert(method != null);
final ByteData? result = await binaryMessenger.send(
name,
codec.encodeMethodCall(MethodCall(method, arguments)),
);
if (result == null) {
if (missingOk) {
return null;
}
throw MissingPluginException('No implementation found for method $method on channel $name');
}
return codec.decodeEnvelope(result) as T?;
}
Hey @Kurogoma4D, I followed your instructions and I ran your code sample from both android studio and vscode. In both instances, I didn't receive an error. I did receive this log:
I/FLTFireMsgService( 4705): FlutterFirebaseMessagingBackgroundService started!
Perhaps there is an environment difference?
Hi @russellwheatley , I tried reproduce this in my another environment, and confirmed it on Android Studio (VSCode couldn't catch that exception). In Android Studio, make sure set to break on all exceptions.

Looks the same to me:

Hi. I have same issue in firebase_messaging 9.1.2. Do you know how to fix it?
Hey @Kurogoma4D. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Update: As we continued to investigate this issue, I was able to confirm that only reproduces in Android Emulator with API Level 30.
Hey @Kurogoma4D, did you manage to resolve this issue?
Hi @russellwheatley, I was no longer aware of this issue because it doesn't affect my project now. I ran firebase_messaging example v9.1.4 with Flutter v2.2.3, and confirmed that there is no error.
Thanks.
Thanks for the feedback, @Kurogoma4D.