[firebase_messaging] PluginRegistrantCallback is not set on Android
Fatal Exception: java.lang.RuntimeException
Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService:
java.lang.RuntimeException: PluginRegistrantCallback is not set.
This is caused by:
Caused by java.lang.RuntimeException: PluginRegistrantCallback is not set.
at io.flutter.plugins.firebasemessaging.
FlutterFirebaseMessagingService.executeDartCallbackInBackgroundIsolate(FlutterFirebaseMessagingService.java)
at io.flutter.plugins.firebasemessaging.
FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java)
This happens on Android when running a Flutter app built with firebase_messaging: 6.0.9 and Flutter 1.15.4-pre.199.
This also happens every time calling FirebaseMessaging.configure in the Flutter app when running on Android:
PlatformException(error, PluginRegistrantCallback is not set., null)
StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
FirebaseMessaging.configure (package:firebase_messaging/firebase_messaging.dart:130:16)
exact same issue. the error appears when using background notification.
I/mattuvandi.use(12720): Background concurrent copying GC freed 18711(1011KB) AllocSpace objects, 12(304KB) LOS objects, 50% free, 2MB/4MB, paused 11.526ms total 155.904ms
E/flutter (12720): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, PluginRegistrantCallback is not set., null)
E/flutter (12720): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (12720): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter (12720):
</details>
same issue, is there any solution yet?
Application.java replace:
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Application.java with:
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
@CallSuper
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry pluginRegistry) {
FirebaseMessagingPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
I run in to error while using @callsuper. As per android document it is deprecated. with your suggested code i get same error.
manifest.xml:
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Mattuvandi"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="*************************************"/>
<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" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Application"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this); //auto generated?
}
}
Application.java
public class Application extends FlutterApplication implements PluginRegistrantCallback { @Override // @CallSuper public void onCreate() { super.onCreate(); FlutterFirebaseMessagingService.setPluginRegistrant(this); }
@Override public void registerWith(PluginRegistry pluginRegistry) { FirebaseMessagingPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); } }````
Error:
@ClevercodeTech @h0x539 Could you maybe wrap your code into a <details> </details> to make this thread more readable?
@ClevercodeTech @h0x539 Could you maybe wrap your code into a
<details> </details>to make this thread more readable?
thanks for the suggestion. Updated as per your suggestion.
@ClevercodeTech
Try to make a standalone build of the android module.
Android Studio -> right click on android package -> Flutter -> Open Android module in Android Studio
Flutter Android module in Android Studio -> Terminal -> ./gradlew clean && ./gradlew build
Resolved the issue. Flutter instruction was not clear or i didn't get what they were saying. i changed the following line in the beginning of my manifest.xml:
~~android:name="io.flutter.app.FlutterApplication"~~
to
android:name=".Application"
<application
~~android:name="io.flutter.app.FlutterApplication"~~
android:name=".Application"
android:label="Mattuvandi"
android:icon="@mipmap/ic_launcher">
I did it and the error is out, but it is not calling the onBackgroundMessage anymore.
Closing this issue because it looks like it's resolved.
@kalibu if you are still experiencing issues calling the onBackgroundMessage with the latest version of Flutter and FlutterFire plugin, can you please provide your updated flutter doctor -v
and your flutter run --verbose/flutter build --verbose ?
Also, to better address the issue, would be helpful
if you could post a self contained app on github
or the steps to reproduce it.
Thank you
@helenaford
This has not been resolved at all.
Hint: there has not been an update to the plugin (on Android) since I opened this issue. I only replaced one deprecated method that had nothing to do with this, so basically there has not been an update since I opened the issue..
@creativecreatorormaybenot did you try the solution provided by @ClevercodeTech ?
@helenaford That "solution" only makes the error message go away and does not fix the underlying problem (the plugin is broken on Android, see #2017 for a start; there are way more issues for background messages).
The plugin would at least need to address this somewhere. Even if the underlying problem is not fixed immediately, the README section and more would need to be updated.
@helenaford That "solution" only makes the error message go away and does not fix the underlying problem (the plugin is broken on Android, see #2017 for a start; there are way more issues for background messages).
The plugin would at least need to address this somewhere. Even if the underlying problem is not fixed immediately, the
READMEsection and more would need to be updated.
Background message works for me.
you need to add a static method to capture the incoming message from firebase server. Below is a sample code
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
print(message);
return Future<void>.value();
}
below is the detailed code
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter/material.dart';
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
class FirebaseClass {
firebaseNotification(context,topic ) {
var platform = Theme.of(context).platform;
final requestServer = RequestServer();
print("firebaseinitiated");
_firebaseMessaging.subscribeToTopic(topic);
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
},
onBackgroundMessage: platform == TargetPlatform.iOS ? null : myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
if (platform == TargetPlatform.iOS) {
_firebaseMessaging
.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
}
_firebaseMessaging.getToken().then((String token) {
assert(token != null);
//setting fire base toke in own server this is needed to message from your server
// requestServer is a custom class to connect with my server
requestServer.requestServer("SetFirebaseToken", context).then((e) {
e == 1 ? print("Push Messaging token: $token") : print("errror sending data to server");
});
});
}
notification() async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid = new AndroidInitializationSettings('logo');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(0, 'plain title', 'plain body', platformChannelSpecifics,
payload: 'item x');
}
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
print(message);
return Future<void>.value();
}
}
@ClevercodeTech
If that works with all versions (Flutter beta + master too), then I suppose that would be a solution.
Still, the issue should remain open until this is at least integrated into the README.
@ClevercodeTech Can you provide detailed instructions?
@ClevercodeTech Can you provide detailed instructions?
Please follow the instruction as shown in the following link https://pub.dev/packages/firebase_messaging
for receiving background message. importantly you need to change your android manifest.
usually flutter application starts like this
<application
android:name="io.flutter.app.FlutterApplication"
you need to change the name to below
<application
android:name=".Application" ...>
.Application refers to Application.java. Which contains below. package com.mattuvandi.user is my application. This should be changed to yours. e.g
package com.domain.application
package com.mattuvandi.user;
import android.os.Bundle;
import io.flutter.app.FlutterApplication;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@override
public void registerWith(PluginRegistry pluginRegistry) {
FirebaseMessagingPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
Doesn't work for me. Tried to switch branch from stable to master, didn't help.
Doesn't work for me. Tried to switch branch from
stabletomaster, didn't help.
could you please post your code.
Sure.
// Application.kt
class Application : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
// ...
}
override fun registerWith(registry: PluginRegistry?) {
FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
// ...
}
}
// AndroidManifest.xml
<application
android:name=".Application" // Changed from `io.flutter.app.FlutterApplication`
... />
// build.gradle under app
// ...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-messaging:20.1.6'
// ...
}