flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [Firebase Messaging] enabling backgroundMessages causes hot reload/restart to break

Open Chris1234567899 opened this issue 5 years ago • 8 comments

Bug report

In order to enable background messaging, I created a file Application.kt and referenced it. Since the docs are outdated and not in Kotlin, I went with this, as suggested in stackoverflow :

class Application : FlutterApplication(), PluginRegistrantCallback {

    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    override fun registerWith(registry: PluginRegistry?) {
       
       //GeneratedPluginRegistrant.registerWith(registry); // according to the docs, but this causes an error
       
    io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));


    }
}

This works well for receiving background messages.

I also can start the app, however after 2-3 hot reloads all further hot reloads or restarts get stuck. I don't receive any error messages, just the hot reload process never finishes. I have to completely stop the run process and start it again with F5 (using VS Code).

If I comment out the registration of the Plugin in the Application.kt, hot reload works normally so it is definately due to firebase_messaging.

Either the docs are wrong (they need an update either way) or this seems to be a bug.

Expected behavior

Having background messages and making use of the flutter hot reload functionality normally ;-)


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
flutter doctor -v
[√] Flutter (Channel master, 1.25.0-5.0.pre.53, on Microsoft Windows [Version 10.0.18363.1198], locale de-DE)
    • Flutter version 1.25.0-5.0.pre.53 at C:\flutter
    • Framework revision 20ca6997b8 (4 hours ago), 2020-12-04 01:23:04 +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\Cri\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.0.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code (version 1.51.1)
    • VS Code at C:\Users\Cri\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.16.0

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 87.0.4280.88
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 86.0.622.56

• No issues found!

Flutter dependencies

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

Click To Expand
flutter pub deps -- --style=compact
Dart SDK 2.12.0-76.0.dev
Flutter SDK 1.25.0-5.0.pre.53
micomida 1.0.0+1

dependencies:
- cupertino_icons 1.0.0
- device_info 0.4.2+9 [flutter device_info_platform_interface]
- dio 3.0.10 [http_parser path]
- dio_http_cache 0.2.11 [flutter quiver json_serializable json_annotation dio sqflite path crypto]
- easy_debounce 1.0.2 [flutter]
- email_validator 1.0.6
- enum_to_string 1.0.13
- firebase_messaging 7.0.3 [meta flutter firebase_core]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_cupertino_localizations 1.0.1 [flutter flutter_localizations]
- flutter_dotenv 2.1.0 [flutter meta]
- flutter_linkify 4.0.2 [flutter linkify]
- flutter_local_notifications 3.0.1+6 [flutter platform flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math]
- flutter_map 0.10.1+1 [flutter tuple latlong positioned_tap_detector transparent_image async flutter_image cached_network_image sqflite path_provider vector_math proj4dart meta]
- get_it 5.0.1 [async meta]
- image_picker 0.6.7+12 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- infinite_scroll_pagination 2.2.2 [flutter sliver_tools]
- intl_phone_number_input 0.5.2+2 [flutter meta libphonenumber equatable]
- location 3.1.0 [flutter meta location_platform_interface location_web]
- multi_image_picker 4.7.14 [flutter meta]
- permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface]
- progress_dialog 1.2.4 [flutter]
- shared_preferences 0.5.12+2 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- sms_autofill 1.2.6 [pin_input_text_field flutter]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- 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:
- _fe_analyzer_shared 11.0.0 [meta]
- analyzer 0.40.4 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- ansicolor 1.0.5
- args 1.6.0
- async 2.5.0-nullsafety.3 [collection]
- boolean_selector 2.1.0-nullsafety.3 [source_span string_scanner]
- build 1.5.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- cached_network_image 2.3.3 [flutter flutter_cache_manager octo_image]
- characters 1.1.0-nullsafety.5
- charcode 1.2.0-nullsafety.3
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety.3
- collection 1.15.0-nullsafety.5
- console_log_handler 1.1.6 [logging intl ansicolor]
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- dart_style 1.3.8 [analyzer args path source_span]
- device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- equatable 1.2.5 [collection meta]
- fake_async 1.2.0-nullsafety.3 [clock collection]
- ffi 0.1.3
- file 6.0.0-nullsafety.4 [meta path]
- firebase_core 0.5.2 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- flutter_blurhash 0.5.0 [flutter meta]
- flutter_cache_manager 2.0.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
- flutter_image 3.0.0 [flutter]
- flutter_local_notifications_platform_interface 2.0.0+1 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- http 0.12.2 [http_parser path pedantic]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface]
- intl 0.17.0-nullsafety.2 [clock path]
- js 0.6.3-nullsafety.3
- json_annotation 3.1.0
- json_serializable 3.5.0 [analyzer build build_config json_annotation meta path source_gen]
- latlong 0.6.1 [logging console_log_handler validate intl]
- libphonenumber 1.0.2 [flutter meta]
- linkify 3.0.0
- lists 0.1.6
- location_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- location_web 1.0.0 [flutter flutter_web_plugins location_platform_interface http_parser meta js]
- logging 0.11.4
- matcher 0.12.10-nullsafety.3 [stack_trace]
- meta 1.3.0-nullsafety.6
- mgrs_dart 1.0.1 [unicode]
- node_interop 1.1.1 [js]
- node_io 1.1.1 [node_interop path]
- octo_image 0.3.0 [flutter flutter_blurhash]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.3
- path_provider 1.6.21 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+4 [flutter]
- path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+1 [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]
- pin_input_text_field 3.1.1 [flutter]
- platform 3.0.0-nullsafety.4
- plugin_platform_interface 1.0.3 [meta]
- positioned_tap_detector 1.0.3 [flutter]
- process 4.0.0-nullsafety.4 [file path platform]
- proj4dart 1.0.5 [mgrs_dart wkt_parser meta]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.3 [matcher meta]
- rxdart 0.24.1
- shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.1+1 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- sky_engine 0.0.99
- sliver_tools 0.1.9 [flutter]
- source_gen 0.9.7+1 [analyzer async build dart_style glob meta path pedantic source_span]
- source_span 1.8.0-nullsafety.4 [charcode collection path term_glyph]
- sqflite 1.3.1+2 [flutter sqflite_common path]
- sqflite_common 1.0.2+1 [synchronized path meta]
- stack_trace 1.10.0-nullsafety.6 [path]
- stream_channel 2.1.0-nullsafety.3 [async]
- string_scanner 1.1.0-nullsafety.3 [charcode source_span]
- synchronized 2.2.0+2
- term_glyph 1.2.0-nullsafety.3
- test_api 0.2.19-nullsafety.6 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.5.9 [path]
- transparent_image 1.0.0
- tuple 1.0.3 [quiver]
- typed_data 1.3.0-nullsafety.5 [collection]
- unicode 0.2.4 [lists]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- validate 1.7.0
- vector_math 2.1.0-nullsafety.5
- watcher 0.9.7+15 [async path pedantic]
- win32 1.7.3 [ffi]
- wkt_parser 1.0.7
- xdg_directories 0.1.2 [meta path process]
- yaml 2.2.1 [charcode collection string_scanner source_span]

Chris1234567899 avatar Dec 03 '20 21:12 Chris1234567899

I can reproduce this on the latest master 1.25.0-5.0.pre.65 with firebase_messaging 7.0.3.

flutter doctor -v
[√] Flutter (Channel master, 1.25.0-5.0.pre.65, on Microsoft Windows [Version 10.0.19041.630], locale et-EE)
    • Flutter version 1.25.0-5.0.pre.65 at C:\Development\flutter_master
    • Framework revision 8f3a12f144 (2 hours ago), 2020-12-04 08:42:30 +0100
    • 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)

[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
    • IntelliJ at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\203.5981.155
    • 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

[√] Connected device (5 available)
    • SM G950F (mobile)           • ce12171c51cc001c03 • android-arm64  • Android 9 (API 28)
    • sdk gphone x86 arm (mobile) • emulator-5554      • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)           • windows            • windows-x64    • Microsoft Windows [Version 10.0.19041.630]
    • 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!

However, it's worth mentioning that this is already fixed on the dev version and the Application.kt hack is no longer even necessary there. Eventually, the dev version will become stable and this issue will become obsolete.

markusaksli-nc avatar Dec 04 '20 10:12 markusaksli-nc

Any news on this, or when the fixes from the dev branch will be released?

Chris1234567899 avatar Dec 13 '20 17:12 Chris1234567899

I still have this issue. Solved it now by commenting FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

[√] Flutter (Channel unknown, 1.25.0-8.2.pre, on Microsoft Windows [Version 10.0.18363.1316], locale de-DE) • Flutter version 1.25.0-8.2.pre at C:_Dev\Flutter • Framework revision b0a2299859 (5 weeks ago), 2021-01-05 12:34:13 -0800 • Engine revision 92ae191c17 • Dart version 2.12.0 (build 2.12.0-133.2.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at C:_Dev\AndroidSDK • Platform android-30, build-tools 30.0.1 • ANDROID_HOME = C:_Dev\AndroidSDK • Java binary at: C:_Dev\AndroidStudio\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 (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0) • Android Studio at C:_Dev\AndroidStudio • Flutter plugin version 51.0.1 • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (4 available) • SM G920F (mobile) • 03157df3a85b0632 • android-arm64 • Android 7.0 (API 24) • AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator) • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.150 • Edge (web) • edge • web-javascript • Microsoft Edge 87.0.664.75

• No issues found!

rainerlonau avatar Feb 10 '21 11:02 rainerlonau

i have this same problem in flutter 2.0.3 When I start firebase the hot reaload hangs

miguelflores1993 avatar Apr 23 '21 02:04 miguelflores1993

Still happening on firebase_messaging 10.0.2.

I notice the first hot reload is always working, but the hot reload after that is no longer working. Tested it on vscode and notice there are also two main call stacks if i called FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

Is it related?

tijanirf avatar Jun 25 '21 23:06 tijanirf

same problem with flutter version : 2.0.3 i think the problem is caused by WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); FirebaseMessaging.onBackgroundMessage(_firebaseMessaginOnBackground); in the main method

dfourcfive avatar Aug 13 '21 18:08 dfourcfive

Hey @Chris1234567899, just to be sure - Have you made the background handler the following as stated in the documentation:

  1. It must not be an anonymous function.
  2. It must be a top-level function (e.g. not a class method which requires initialization).

I'd also recommend updating to the latest firebase_messaging version 11.2.4 so we're on the same page. Thanks.

russellwheatley avatar Dec 23 '21 11:12 russellwheatley

Closing out due to lack of activity. Thanks.

russellwheatley avatar Mar 10 '22 15:03 russellwheatley