Open ben-xD opened 2 years ago
Hey, We are using firebase_messaging and ably together and facing issues as described above.
Version:
firebase_messaging
- 10.0.5
ably_flutter
- 1.2.8
Error Trace from Flutter
I/zygote (13606): Thread[3,tid=13612,WaitingInMainSignalCatcherLoop,Thread*=0xa874ec00,peer=0x12d80328,"Signal Catcher"]: reacting to signal 3
I/zygote (13606):
I/zygote (13606): Wrote stack traces to '[tombstoned]'
This happens after a few seconds we receive a push notification through firebase. Below is the ANR
ANR from adb through adb -s emulator-5556 logcat ActivityManager:E *:S
01-06 19:51:57.910 7430 7444 E ActivityManager: ANR in com.creatorstack.commune.preprod
01-06 19:51:57.910 7430 7444 E ActivityManager: PID: 13606
01-06 19:51:57.910 7430 7444 E ActivityManager: Reason: Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.creatorstack.commune.preprod cmp=com.creatorstack.commune.preprod/io.ably.flutter.plugin.push.FirebaseMessagingReceiver (has extras) }
flutter doctor -v
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.3.1 20E241 darwin-x64, locale en-IN)
• Flutter version 2.2.3 at /Users/cs/flutter
• Framework revision f4abaa0735 (6 months ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/cs/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5.1, Build version 12E507
• CocoaPods version 1.10.1
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.63.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.32.0
[✓] Connected device (1 available)
• Android SDK built for x86 (mobile) • emulator-5556 • android-x86 • Android 8.1.0 (API 27) (emulator)
! Doctor found issues in 1 category.
Here is a crashlytics log trace
Adding this to the AndroidManifest of your project disables the notification receiver from ably plugin.
<receiver android:name="io.ably.flutter.plugin.push.FirebaseMessagingReceiver"
tools:node="remove">
</receiver>
Hope this helps.
Adding this to the AndroidManifest of your project disables the notification receiver from ably plugin.
<receiver android:name="io.ably.flutter.plugin.push.FirebaseMessagingReceiver" tools:node="remove"> </receiver>
Hope this helps.
Thanks this fixed it 🙌🏽
I also have a problem with iOS with the onMessage handler not being invoked. Tried everything... Push setup is ok, I see that the device is in an Active state in the Ably dashboard, notification is displayed when the phone is locked (sleeping), but when the app is in the foreground, the onMessage handler is never invoked. Android works fine. We don't have firebase_messaging dependency. It was present a long time ago when the initial setup for the app was created, but we removed it before installing ably. Now I am not sure if something is left over that still causes the issue. Any ideas?
Got this error when I add this:
<receiver android:name="io.ably.flutter.plugin.push.FirebaseMessagingReceiver" tools:node="remove">
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:generateDebugBuildConfig'.
Failed to calculate the value of task ':app:generateDebugBuildConfig' property 'buildConfigPackageName'. Failed to query the value of property 'packageName'. org.xml.sax.SAXParseException; systemId: file:/Users/macbook/Documents/Projects/dang-app/android/app/src/main/AndroidManifest.xml; lineNumber: 32; columnNumber: 37; The prefix "tools" for attribute "tools:node" associated with an element type "receiver" is not bound.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
@Asharulislam Do you have the xmlns:tools="http://schemas.android.com/tools"
namespace in the Android manifest?
here is my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.appiskey.dang.dev">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Permissions options for the `location` group -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application android:label="Dang" android:icon="@mipmap/ic_launcher" android:allowBackup="false"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:showWhenLocked="true" android:turnScreenOn="true" android:windowSoftInputMode="adjustResize">
<receiver android:name="io.ably.flutter.plugin.push.FirebaseMessagingReceiver"
tools:node="remove">
</receiver>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="FCM_CHANNEL" />
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
@Asharulislam You should have the <manifest>
block at the beggining of the XML file, with namespaces configured, something like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your pacakage name">
Thanks alot @ikurek
onMessage also not receiving data on IOS only is there any solution yet?
@Asharulislam Please open an issue with more details, so someone from our team can investigate
IOS forground notification not triggered if I am using flutter messaging and Ably package both Android issue is resolved by adding block of code in manifest file.
It seems the issue has escalated and now my app crashes in iOS when tapping on notifications and the cause seems to be ably.
I'm using: Flutter: 3.0.3 ably_flutter: 1.2.14 firebase_core: 1.18.0 firebase_messaging: 11.4.2
Flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.3, on macOS 12.4 21F79 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Android Studio (version 2021.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
This crash happens when you tap on the notification to open the app, when the app is either in the background or closed. I haven't tested android yet.
This compatibility issue needs to be addressed, is no longer a minor inconvenience.
I'll try to downgrade my packages to fix it.
Upgrading to firebase_messaging v11.4.2
(latest) will cause a crash when using together with ably_flutter
on iOS, downgrading to 11.4.1
fixes it, but now I'll be unable to upgrade firebase_messaging
package until this is solved.
Using Firebase Messaging along with Ably plugin causes issue that prevent FirebaseMessaging.onBackgroundMessage
callback to work properly. I agree that this should be moved as a separate package.
I am able to receive message but not popping up the notification only in foreground on ios device. What might be issue ?
`import 'dart:io'; import 'package:copart_vehicle_bidding/app_state.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationServices { //initialising firebase message plugin FirebaseMessaging messaging = FirebaseMessaging.instance;
//initialising firebase message plugin final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
//function to initialise flutter local notification plugin to show notifications for android when app is active void initLocalNotifications( BuildContext context, RemoteMessage message) async { var androidInitializationSettings = const AndroidInitializationSettings('@mipmap/ic_launcher'); var iosInitializationSettings = const DarwinInitializationSettings( requestAlertPermission: false, requestBadgePermission: false, requestSoundPermission: false, );
var initializationSetting = InitializationSettings(
android: androidInitializationSettings, iOS: iosInitializationSettings);
await _flutterLocalNotificationsPlugin.initialize(initializationSetting,
onDidReceiveNotificationResponse: (payload) {
// handle interaction when app is active for android
handleMessage(context, message);
});
}
void firebaseInit(BuildContext context) { FirebaseMessaging.onMessage.listen((message) { RemoteNotification? notification = message.notification; AndroidNotification? android = message.notification!.android;
if (kDebugMode) {
print("notifications title:${notification!.title}");
print("notifications body:${notification.body}");
// print('count:${android!.count}');
// print('data:${message.data.toString()}');
}
if (Platform.isIOS) {
foregroundMessage();
}
if (Platform.isAndroid) {
initLocalNotifications(context, message);
if (FFAppState().Remem) {
if (FFAppState().authtoken.isNotEmpty) {
showNotification(message);
debugPrint('Hello - init');
}
return;
} else if (FFAppState().authtoken.isNotEmpty) {
showNotification(message);
debugPrint('Hello - no remember init');
}
}
});
}
void requestNotificationPermission() async { NotificationSettings settings = await messaging.requestPermission( alert: true, announcement: true, badge: true, carPlay: true, criticalAlert: true, provisional: false, sound: true, );
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
if (kDebugMode) {
print('user granted permission');
}
} else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
if (kDebugMode) {
print('user granted provisional permission');
}
} else {
// appsetting.AppSettings.openNotificationSettings();
if (kDebugMode) {
print('user denied permission');
}
}
}
// function to show visible notification when app is active
Future
AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('pushnotificationapp', 'pushnotificationapp',
channelDescription: 'pushnotificationapp',
importance: Importance.high,
priority: Priority.high,
playSound: true,
ticker: 'ticker',
sound: channel.sound
// sound: RawResourceAndroidNotificationSound('jetsons_doorbell')
// icon: largeIconPath
);
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
presentBanner: true,
);
NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails, iOS: darwinNotificationDetails);
Future.delayed(Duration.zero, () {
_flutterLocalNotificationsPlugin.show(
0,
message.notification!.title.toString(),
message.notification!.body.toString(),
notificationDetails,
);
});
}
//handle tap on notification when app is in background or terminated
Future
if (initialMessage != null) {
handleMessage(context, initialMessage);
}
//when app ins background
FirebaseMessaging.onMessageOpenedApp.listen((event) {
handleMessage(context, event);
});
}
void handleMessage(BuildContext context, RemoteMessage message) { // if (message.data['type'] == 'msj') { if (FFAppState().Remem) { if (FFAppState().authtoken.isNotEmpty) { showNotification(message); debugPrint('Hello'); } return; } else if (FFAppState().authtoken.isNotEmpty) { debugPrint('hello from no remeber'); showNotification(message); }
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => MessageScreen(
// id: message.data['id'] ,
// )));
// }
}
Future foregroundMessage() async { await messaging.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); }
//function to get device token on which we will send the notifications
Future
void isTokenRefresh() async { messaging.onTokenRefresh.listen((event) { event.toString(); if (kDebugMode) { print('refresh'); } }); } } `
Code for reference..also I am initialising all methods at app run time
Version of packages
ably_flutter: ^1.2.30 firebase_messaging: ^14.9.2
Problem
There may be compatibility issues with Firebase Messaging and Ably Flutter, now that we handle push notifications in the native side and send them to the Dart side for users to handle them in their flutter application without writing native code. We should investigate to what extent issues exist, and to fix it, if necessary.
Incompatibility might show up in either Ably Flutter or Firebase Messaging not receiving push notifications when they should, errors being logged or app crashes.
When a flutter package plugin (containing iOS/Android) code is installed in an application, there is native code that always run, regardless of the Flutter application code.
Potential high level approaches:
Some investigation: specific issues
Merely having
firebase_messaging
inpubspec.yaml
will cause issues:iOS issues
firebase_messaging
is installed.Android issues
onMessage
andsetOnBackgroundMessage
is working as expected. -onNotificationTap
is not working. You cannot handle notification taps if firebase_messaging is installed.Running firebase_messaging code.
More investigation needed to see if firebase_messaging handlers are also broken, and if any further features are broken in Ably Flutter if Dart code inside firebase_messaging is ran.
┆Issue is synchronized with this Jira Story by Unito