flutterfire
flutterfire copied to clipboard
[firebase_messaging]: android.os.MessageQueue.nativePollOnce (Native method)
Is there an existing issue for this?
- [X] I have searched the existing issues.
Which plugins are affected?
Messaging
Which platforms are affected?
Android
Description
Flutter Doctor [✓] Flutter (Channel stable, 3.19.6, on macOS 14.0 23A344 darwin-x64, locale tr-TR) • Flutter version 3.19.6 on channel stable at /Users/benpetto/flutter_projects/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (5 days ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/benpetto/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.15.2
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0
[✓] VS Code (version 1.78.1) • VS Code at /Users/benpetto/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.86.0
[✓] Connected device (5 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 14 (API 34) (emulator) • macOS (desktop) • macos • darwin-x64 • macOS 14.0 23A344 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.61
[✓] Network resources • All expected network resources are available.
• No issues found!
Issue: When a notification is sent while the application is in the foreground, it crashes with the android.os.MessageQueue.nativePollOnce (Native method) error. There is no issue with the first notification; it arrives promptly. However, subsequent notifications experience delays. After a while, all pending notifications arrive simultaneously, leading to a crash of the application.
packages: firebase_core: ^2.30.0 firebase_messaging: ^14.8.2
Reproducing the issue
1-) Launch the application on an Android device. 2-) Send multiple push notifications to the device within a short period. 3-) Notice the delay in receiving subsequent notifications. 4-) After some time, observe all pending notifications being delivered simultaneously, leading to a crash of the application.
Firebase Core version
2.30.0
Flutter Version
3.19.6
Relevant Log Output
android.os.MessageQueue.nativePollOnce (Native method)
android.os.MessageQueue.next (MessageQueue.java:335)
android.os.Looper.loopOnce (Looper.java:161)
android.os.Looper.loop (Looper.java:288)
android.app.ActivityThread.main (ActivityThread.java:7872)
java.lang.reflect.Method.invoke (Native method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)
Flutter dependencies
Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
No response
Hello @kdrgrgn,
Could you please try out the Flutter example app available at this link? Configure it with your Firebase backend using the FlutterFire CLI, which you can find here. After setting it up, could you let us know if the issue still occurs? Thanks!
Helo @TarekkMA We applied the example in the link. The same issue is happening there too, only on Android. The first message works fine. Then the subsequent messages come in bulk, and despite not setting the default message, the rest of the messages fall into background messaging while the app is open. Then a crash occurs.
Could you please provide details on the payload you are using with firebase-admin, as well as the method you are employing to send these messages? This information will help us reproduce and diagnose the issue effectively. Thank you!
@TarekkMA I can't share the structure I normally use with you. However, I'm experiencing the same issue even when I push with Postman
@kdrgrgn, Can you use firebase-admin and see if this still causes issue as well?
An example script can be as follows:
// 0. install firebase-admin via npm
var admin = require('firebase-admin');
// 1. Download a service account key (JSON file) from your Firebase console and add to the example/scripts directory
var serviceAccount = require('./key.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
// 2. Copy the token for your device that is printed in the console on app start (`flutter run`) for the FirebaseMessaging example
const androidToken = 'token here';
// 3. From your terminal run `npm install`.
// 4. Run the script using node and your app will receive messages in any state; foreground, background, terminated.
// If you find your messages have stopped arriving, it is extremely likely they are being throttled by the platform. iOS in particular
// are aggressive with their throttling policy.
admin
.messaging()
.send(
{
token: androidToken,
data: {
foo: 'bar',
float: '12034'
},
notification: {
title: 'A great title',
body: 'Great content',
},
android: {
// Required for background/terminated app state messages on Android
priority: 'high',
},
apns: {
payload: {
aps: {
// Required for background/terminated app state messages on iOS
contentAvailable: true,
},
},
},
},
)
.then((res) => {
if (res.failureCount) {
console.log('Failed', res.results[0].error);
} else {
console.log('Success');
}
})
.catch((err) => {
console.log('Error:', err);
});
Hey @kdrgrgn. 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.
@kdrgrgn 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.
@kdrgrgn, Can you use
firebase-adminand see if this still causes issue as well?An example script can be as follows:
// 0. install firebase-admin via npm var admin = require('firebase-admin'); // 1. Download a service account key (JSON file) from your Firebase console and add to the example/scripts directory var serviceAccount = require('./key.json'); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), }); // 2. Copy the token for your device that is printed in the console on app start (`flutter run`) for the FirebaseMessaging example const androidToken = 'token here'; // 3. From your terminal run `npm install`. // 4. Run the script using node and your app will receive messages in any state; foreground, background, terminated. // If you find your messages have stopped arriving, it is extremely likely they are being throttled by the platform. iOS in particular // are aggressive with their throttling policy. admin .messaging() .send( { token: androidToken, data: { foo: 'bar', float: '12034' }, notification: { title: 'A great title', body: 'Great content', }, android: { // Required for background/terminated app state messages on Android priority: 'high', }, apns: { payload: { aps: { // Required for background/terminated app state messages on iOS contentAvailable: true, }, }, }, }, ) .then((res) => { if (res.failureCount) { console.log('Failed', res.results[0].error); } else { console.log('Success'); } }) .catch((err) => { console.log('Error:', err); });
Hi,
We have the same anr problem in our project. Additionally, notifications are sent via "firebase-admin" as you mentioned.
This problem has increased a lot in the last 6-7 months and continues to cause a lot of anr. I am submitting the "Logs & Breadcrumbs" and "Stack trace" information I received from Firebase Crashlytics.
Number of anr received in the last 90 days (31K);
main (native):tid=1 systid=18662
#00 pc 0x86f8c libc.so (syscall + 28)
#01 pc 0x1b07a4 libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*) + 148)
#02 pc 0x3a544c libart.so (art::JNI<false>::CallObjectMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list) + 500)
#03 pc 0x4074 libnativehelper.so (_JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, ...) + 124)
#04 pc 0xed358 libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync(long, unsigned long, unsigned int) + 48)
#05 pc 0x93c28 libgui.so (android::DisplayEventDispatcher::handleEvent(int, int, void*) + 168)
#06 pc 0x1a064 libutils.so (android::Looper::pollInner(int) + 916)
#07 pc 0x19c68 libutils.so (android::Looper::pollOnce(int, int*, int*, void**) + 112)
#08 pc 0x118b3c libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int) + 44)
at android.os.MessageQueue.nativePollOnce(Native method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:8096)
at java.lang.reflect.Method.invoke(Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
@Cengizhanerturan Hi, I couldn't solve the problem. I switched to Onesignal. It's working fine now
@Cengizhanerturan Hi, I couldn't solve the problem. I switched to Onesignal. It's working fine now
@kdrgrgn Thanks for your answer.
https://github.com/firebase/flutterfire/issues/12832
I created a new issue here, I hope a solution is found.