Skip to content

🐛 [firebase_messaging] Strangest bug on Android 8.0.0 dev  #4301

Closed

Description

@diegogarciar

Bug report

Describe the bug
This bug took me 1 day to find as I was looking elsewhere. And I can't explain it without the context.

I have two Apps that connect each other, I'm on my dev branch with messaging dev versions on them. The apps have chat functionality and I decided to add voice messages, so I added the package Sounds to record and play messages. When I finished with one app everything was working fine. Then I copied the new voice-messaging files into the other app and voila, voice messaging between my apps. I then went testing mode, and found out that while playing a sound on one of my apps, the play progress was not updating, which was weird as my other app was working fine.

More strange both apps were working fine on iOS, so it didn't seem like a bug in the plugin. I compared line by line both android projects, then decided to debug flutter itself and found out that I was not receiving invoked methods from android which were in charge of updating the play progress. Gave up and deleted the whole android project as I had no idea what was the problem. I gave up again and later decided to go back in time with my commits.

After finding the breaking commit, I reverted packages and then into reverting code. So the guilty was (by the title of the issue) onBackgroundMessage which was only used on the breaking app. It's a very deep bug, it deserved a big context.

So I don't know what's happening but it's blocking android->flutter communication between the Sounds package, and God only knows what else.

As I navigated trough my repo history, this bug was present on dev9 and dev8, which is when I added onBackgroundMessage

Steps to reproduce

Good news its "easy" to reproduce the behavior:

  1. Download Sounds example then add firebase_messaging and update main.dart.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {}
void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp();

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  runApp(MyApp());
}

  1. Run on Android,
  2. Play asset file
  3. See progress not updating
  4. Run app again (no reload) commenting out onBackgroundMessage, see how it works again
  5. Compare with iOS if needed

Expected behavior

I should receive android platform messages from other packages


I'll provide this data from the sounds example

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel stable, 1.22.4, on macOS 11.0.1 20B29 darwin-x64, locale en-MX)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.51.1)
[✓] Connected device (1 available)
    ! Error: Diego's iPhone Xs is not connected. Xcode will continue when Diego's iPhone Xs is connected. (code -13)

• No issues found!

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.10.4
Flutter SDK 1.22.4
sounds_demo 1.0.0+1

dependencies:
- cupertino_icons 0.1.3
- firebase_core 0.5.2+1 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_messaging 8.0.0-dev.9 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- intl 0.16.1 [path]
- path 1.8.0-nullsafety.1
- path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface]
- sounds 0.9.3 [device_info flutter_spinkit meta path path_provider provider sounds_common uuid flutter]
- uuid 2.2.2 [crypto convert]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.5.0-nullsafety.1 [collection]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- clock 1.1.0-nullsafety.1
- collection 1.15.0-nullsafety.3
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- device_info 1.0.0 [flutter device_info_platform_interface]
- device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase_core_platform_interface 2.1.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1+1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_messaging_platform_interface 1.0.0-dev.6 [flutter meta firebase_core plugin_platform_interface]
- flutter_spinkit 4.1.2+1 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- js 0.6.2
- logger 0.9.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- nested 0.0.4 [flutter]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+6 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- permission_handler_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- process 3.0.13 [file intl meta path platform]
- provider 4.3.2+2 [flutter nested collection]
- quiver 2.1.5 [matcher meta]
- sky_engine 0.0.99
- sounds_common 1.0.8 [intl logger meta path pedantic uuid flutter]
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0-nullsafety.3 [collection]
- vector_math 2.1.0-nullsafety.3
- win32 1.7.4 [ffi]
- xdg_directories 0.1.2 [meta path process]

Activity

  1. added
    Needs Attention
    type: bug
    on Dec 3, 2020
  2. markusaksli-nc commented on Dec 3, 2020

    @markusaksli-nc
    Contributor

    I was able to reproduce this. Not sure compatibility with a third-party package is relevant here but this could affect more than just sounds.

    flutter doctor -v
    [√] Flutter (Channel master, 1.25.0-5.0.pre.45, on Microsoft Windows [Version 10.0.19041.630], locale et-EE)
        • Flutter version 1.25.0-5.0.pre.45 at C:\Development\flutter_master
        • Framework revision 81e1f7d1ed (5 hours ago), 2020-12-02 17:19:57 -0800
        • Engine revision 20caf54969
        • Dart version 2.12.0 (build 2.12.0-76.0.dev)
    
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at C:\Users\marku\AppData\Local\Android\sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.7.30621.155
        • Windows 10 SDK version 10.0.18362.0
    
    [√] Android Studio (version 4.1.0)
        • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283
        • 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 1.8.0_242-release-1644-b01)
    
    [√] Connected device (4 available)
        • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19041.630]
        • Web Server (web)  • web-server • web-javascript • Flutter Tools
        • Chrome (web)      • chrome     • web-javascript • Google Chrome 87.0.4280.88
        • Edge (web)        • edge       • web-javascript • Microsoft Edge 87.0.664.47
    
    • No issues found!
    
      firebase_core: ^0.5.2+1
      firebase_messaging: ^8.0.0-dev.9
      sounds: ^0.9.3
    
      intl: ^0.16.0
      path_provider: ^1.6.1
      path: ^1.6.4
      permission_handler: ">=5.0.0 <6.0.0"
      uuid: ^2.0.4
    
  3. added and removed
    Needs Attention
    on Dec 3, 2020
  4. diegogarciar commented on Dec 3, 2020

    @diegogarciar
    ContributorAuthor

    Agree,
    Did you tried with their example App on Android? Here is a screenshot comparing the issue with and without onBackgroundMessage set. But if you did, the only difference I see is the flutter version.

    Bug

  5. self-assigned this
    on Dec 3, 2020
  6. Salakar commented on Dec 3, 2020

    @Salakar
    Contributor

    Could you provide a ready to clone example of the bug on a github repo if possible - would save me a lot of time and I could then dive straight into debugging it. Would be super helpful

  7. markusaksli-nc commented on Dec 4, 2020

    @markusaksli-nc
    Contributor
  8. diegogarciar commented on Jan 14, 2021

    @diegogarciar
    ContributorAuthor

    Hello, I debugged a little to see if I could find something useful and I got to discover the line after which the issue is happening.

    https://github.com/FirebaseExtended/flutterfire/blob/891e5d762f79b5f6ac77fced227257d21bbf21c5/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingBackgroundExecutor.java#L183-L185

    It seems that creating a new FlutterEngine is what's causing the issue... Maybe the sounds plugin is mistaking the original with this one or something.

    Hope this helps.

  9. Salakar commented on Sep 9, 2022

    @Salakar
    Contributor
  10. locked and limited conversation to collaborators on Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

plugin: messagingtype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions