Describe the bug
When trying to configure the Firebase Cloud Messaging an Exception is thrown.
PlatformException (PlatformException(error, PluginRegistrantCallback is not set., null))
To Reproduce
Call the configure function.

Stack Trance
E/flutter (17015): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, PluginRegistrantCallback is not set., null)
E/flutter (17015): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:569
E/flutter (17015): #1 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:321
E/flutter (17015): <asynchronous suspension>
E/flutter (17015): #2 FirebaseMessaging.configure
package:firebase_messaging/firebase_messaging.dart:118
E/flutter (17015): #3 _configureMessaging
package:firebase_cloud_messaging_play/main.dart:28
E/flutter (17015): #4 main
package:firebase_cloud_messaging_play/main.dart:9
E/flutter (17015): #5 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter (17015): #6 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (17015): #7 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (17015): #8 _runZoned (dart:async/zone.dart:1516:10)
E/flutter (17015): #9 runZoned (dart:async/zone.dart:1500:12)
E/flutter (17015): #10 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter (17015): #11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
E/flutter (17015): #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
E/flutter (17015):
Additional context
The repo is here
https://github.com/earyzhe/firebase_cloud_messaging_play
Hello,
I have the same issue.
Any ideas how to solve it?
This issue should be rename to [firebase_messaging] PlatformException thrown on configuration
Please help I have same problem .
Several people have managed to get around the issue, me included (https://github.com/FirebaseExtended/flutterfire/issues/199 | https://github.com/FirebaseExtended/flutterfire/issues/116). In my case, there was an incompatibility caused by the barcode_scan package.
I still have this issue and it only works when I delete
// onBackgroundMessage: Platform.isIOS ? null : backgroundMessageHandler,
someone got any solution
Same Issue. :(
same issue.
Any news? I am getting the same issue... Did anyone try lower versions of the plugin?
Hello I followed the tutorial and had this problem.
1 - Replaces
GeneratedPluginRegistrant.registerWith ((FlutterEngine) registry);
3 - I put all functions (onMessage, onBackgroundMessage, onLaunch, onResume) as top-level.
4 - versions:
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms: google-services: 4.3.2'
5 - I added: implementation 'com.google.firebase: firebase-messaging: 20.1.0'
And the problem has now changed to:
[ERROR: flutter /lib/ui/ui_dart_state.cc (157)] Unhandled Exception: PlatformException (error, io.flutter.app.FlutterPluginRegistry cannot be cast to io.flutter.embedding.engine.FlutterEngine, null)
Hello I followed the tutorial and had this problem.
1 - Replaces2 - I had to add a cast to line 19 of Application.java:
GeneratedPluginRegistrant.registerWith ((FlutterEngine) registry);
3 - I put all functions (onMessage, onBackgroundMessage, onLaunch, onResume) as top-level.
4 - versions:
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms: google-services: 4.3.2'
5 - I added: implementation 'com.google.firebase: firebase-messaging: 20.1.0'And the problem has now changed to:
[ERROR: flutter /lib/ui/ui_dart_state.cc (157)] Unhandled Exception: PlatformException (error, io.flutter.app.FlutterPluginRegistry cannot be cast to io.flutter.embedding.engine.FlutterEngine, null)
To solve the problem, I removed the cast I had placed on line 19 and used the FirebaseCloudMessagingPluginRegistrant.java class that I found at this link:
https://stackoverflow.com/questions/59446933/pluginregistry-cannot-be-converted-to-flutterengine
And it worked perfectly in the background.
@marceloiavenissi did you use the sendNotificationOnBackground dart function from the stackoverflow as your (onMessage, onBackgroundMessage, onLaunch, onResume) at top-lavel?
@marceloiavenissi did you use the sendNotificationOnBackground dart function from the stackoverflow as your (onMessage, onBackgroundMessage, onLaunch, onResume) at top-lavel?
No, just the same FirebaseCloudMessagingPluginRegistrant class
But put as top-level was not relevant to: onMessage, onLaunch, onResume
So I also took these classes from SO. They seem to work, but I still have one problem... Here is my dart code:
`
class NotificationServiceImpl {
// make it singleton pls
static final NotificationServiceImpl _singleton = NotificationServiceImpl._internal();
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
print("triggerd");
if (message.containsKey('data')) {
// Handle data message
final dynamic data = message['data'];
}
if (message.containsKey('notification')) {
// Handle notification message
final dynamic notification = message['notification'];
}
return null;
// Or do other work.
}
bool _initialized = false;
String _fcmToken;
Future<void> init() async {
if (!_initialized) {
// For iOS request permission first.
_firebaseMessaging.requestNotificationPermissions();
// _firebaseMessaging.configure();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_fcmToken = await _firebaseMessaging.getToken();
print("Token : "+_fcmToken);
_initialized = true;
}
}
Future<String> getToken() async {
if (!_initialized) {
await init();
}
return _fcmToken;
}
}
`
So at this point the callback triggers on background. However at build Process i am still getting an error:
Unhandled Exception: Invalid argument(s): Failed to setup background message handler!onBackgroundMessage
E/flutter (24529): should be a TOP-LEVEL OR STATIC FUNCTION and should NOT be tied to a
E/flutter (24529): class or an anonymous function.
Am I doing something wrong here? Isn't it already top level or static?
@oe19fyfa This is not wrong anyway. But how is your application.java and the manifest?
So I have 3 files in my package: Application.java ,FirebaseCloudMessagingPluginRegistrant.java as mentioned in SO. I also have a MainActivity.java that i had prior to SO stuff.
`
package mapackag;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
`
And here is my manifest, forgot to mention:
`
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name="my.package.Application"
android:label="label"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="apikey"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<!-- BEGIN: Firebase Cloud Messaging -->
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- END: Firebase Cloud Messaging -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
`
No errors were corrected when replacing GeneratedPluginRegistrant with FirebaseCloudMessagingPluginRegistrant on line 19 of the Application.
hey guys, while following the guide on the package i also got the error.
I referenced some code from over a year ago using the package and the following works inside initState:
`
_messaging.requestNotificationPermissions();
_messaging.configure(onLaunch: (data) {
print("onLaunch $data");
}, onMessage: (data) {
print("onMessage $data");
}, onResume: (data) {
print("OnResume $data");
});
`
will at least get rid of the error, and should still allow your devices to receive notifications - at least on android. I havent tested on iOS.
Piggybacking on this issue to point out that firebase_messaging does not properly support Flutter Android Embedding V2. This same error is thrown when the pluginRegistrantCallback is not set, but this is not required for V2. It should not be required to extend FlutterApplication and call FlutterFirebaseMessagingService.setPluginRegistrant when using newer Flutter versions, unless I am missing something with how the V2 Embedding on Android works.
Same here, any solutions? Pls help
Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.14.6 18G3020)
• Flutter version 1.12.13+hotfix.8 at /Users/kk/flutter
• Framework revision 0b8abb4724 (9 days ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0
Hello - please can you check whether this is an issue on the latest messaging plugin (6.0.13 at this time). Thanks,
Several people have managed to get around the issue, me included (#199 | #116). In my case, there was an incompatibility caused by the barcode_scan package.
@Eddydpyl Any luck getting barcode_scan to work with firebase_messaging or did you have to find an alternative?
@ejprok In the end I switched to qrcode_reader, which worked for me.
I have followed the code in the example app with a blank app from Flutter create (Flutter version: 1.12.13+hotfix.9 and with version 6.0.13) and I get the following error:
java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
And the application just dies when receiving a notification (this is without setting the backgroundMessages handler). If I set it, then I get the following error on app initialization:
PlatformException (PlatformException(error, PluginRegistrantCallback is not set., null))
Any pointers?
I have followed the code in the example app with a blank app from Flutter create (Flutter version: 1.12.13+hotfix.9 and with version 6.0.13) and I get the following error:
java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
And the application just dies when receiving a notification (this is without setting the backgroundMessages handler). If I set it, then I get the following error on app initialization:
PlatformException (PlatformException(error, PluginRegistrantCallback is not set., null))
Any pointers?
So, got it working by patching info from several sources. For some reason my MainActivity was in Kotlin, so the Application class needs to be in Kotlin as well. My Application.kt file looks like this:
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
Using solution from (https://github.com/FirebaseExtended/flutterfire/issues/1613#issuecomment-565293988). I also needed to add the following (per https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-577028200):
in android/app/build.gradle
implementation "com.google.firebase:firebase-messaging:20.1.0"
This is still a very big issue clearly from researching the errors involved in registering the plugin on Android.
Most users are hacking together from 10-20 sources and there is no definite answer to the problem.
Can we get some updated documentation on this issue related to Kotlin?
I have the same issue with latest version of the plugin
firebase_messaging: ^6.0.16
I have followed the code in the example app with a blank app from Flutter create (Flutter version: 1.12.13+hotfix.9 and with version 6.0.13) and I get the following error:
java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
And the application just dies when receiving a notification (this is without setting the backgroundMessages handler). If I set it, then I get the following error on app initialization:
PlatformException (PlatformException(error, PluginRegistrantCallback is not set., null))
Any pointers?
So, got it working by patching info from several sources. For some reason my MainActivity was in Kotlin, so the Application class needs to be in Kotlin as well. My Application.kt file looks like this:
import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() FlutterFirebaseMessagingService.setPluginRegistrant(this) } override fun registerWith(registry: PluginRegistry?) { io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); } }Using solution from (#1613 (comment)). I also needed to add the following (per #1607 (comment)):
in android/app/build.gradle
implementation "com.google.firebase:firebase-messaging:20.1.0"
Implementing this solved my problem.
Be aware if you are a noob like me:
android:name="io.flutter.app.FlutterApplication" by android:name=".Application" in AndroidManifest.xmlMainActivity.ktApplication.kt do not forget to add package com.yourpackage.example
Hey @earyzhe. 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!
Since there haven't been any recent updates here, I am going to close this issue.
@earyzhe if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
Most helpful comment
Please help I have same problem .