Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_messaging]: android.os.MessageQueue.nativePollOnce (Native method) #12684

Open
1 task done
kdrgrgn opened this issue Apr 22, 2024 · 5 comments
Open
1 task done
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: messaging type: bug Something isn't working

Comments

@kdrgrgn
Copy link

kdrgrgn commented Apr 22, 2024

Is there an existing issue for this?

  • 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

Ekran Resmi 2024-04-22 16 30 48

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

@kdrgrgn kdrgrgn added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Apr 22, 2024
@TarekkMA TarekkMA added plugin: messaging platform: android Issues / PRs which are specifically for Android. labels Apr 23, 2024
@TarekkMA
Copy link
Contributor

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!

@TarekkMA TarekkMA added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Apr 23, 2024
@kdrgrgn
Copy link
Author

kdrgrgn commented Apr 30, 2024

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.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Apr 30, 2024
@TarekkMA
Copy link
Contributor

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 TarekkMA added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Apr 30, 2024
@kdrgrgn
Copy link
Author

kdrgrgn commented May 6, 2024

@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
Ekran Resmi 2024-05-06 12 20 46
Ekran Resmi 2024-05-06 12 20 58

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels May 6, 2024
@TarekkMA
Copy link
Contributor

TarekkMA commented May 7, 2024

@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);
  });

@TarekkMA TarekkMA added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: android Issues / PRs which are specifically for Android. plugin: messaging type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants