Describe the bug
The FCM payload contains both NOTIFICATION + DATA
Have integrated Firebase messaging background service as:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
void main() {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(...)
}
Following is the error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 5849
java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.embedding.engine.loader.FlutterApplicationInfo.flutterAssetsDir' on a null object reference
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4158)
at android.app.ActivityThread.access$1600(ActivityThread.java:233)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2014)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7582)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.embedding.engine.loader.FlutterApplicationInfo.flutterAssetsDir' on a null object reference
at io.flutter.embedding.engine.loader.FlutterLoader.findAppBundlePath(FlutterLoader.java:324)
at io.flutter.view.FlutterMain.findAppBundlePath(FlutterMain.java:97)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.startBackgroundIsolate(FlutterFirebaseMessagingBackgroundExecutor.java:165)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.startBackgroundIsolate(FlutterFirebaseMessagingBackgroundExecutor.java:133)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService.onCreate(FlutterFirebaseMessagingBackgroundService.java:120)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4146)
Steps to reproduce the behavior:
After sending the notification it should appear in the notification system tray. On clicking the notification the app should open and route to the specific screen. The notification behaviour is normal in app foreground and background state.
Android 10
The app is upgraded to embedding v2 following the migration guide on GitHub.
Run flutter doctor and paste the output below:
Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[โ] Flutter (Channel stable, 1.22.3, on Linux, locale en_IN)
[โ] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[โ] Android Studio (version 3.5)
[โ] VS Code (version 1.42.1)
[โ] Connected device (1 available)
โข No issues found!
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
Dart SDK 2.10.3
Flutter SDK 1.22.3
spock 1.4.0+48
dependencies:
- battery 1.0.7 [flutter meta battery_platform_interface]
- cached_network_image 2.3.3 [flutter flutter_cache_manager octo_image]
- charts_flutter 0.9.0 [charts_common collection flutter intl logging meta]
- connectivity 0.4.9+5 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- country_icons 1.1.1
- cupertino_icons 1.0.0
- curved_navigation_bar 0.3.4 [flutter meta]
- date_range_picker 1.0.6 [flutter]
- device_info 1.0.0 [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]
- firebase_analytics 6.1.0 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
- firebase_core 0.5.1 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.2.2 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface]
- firebase_dynamic_links 0.6.1 [flutter firebase_core]
- firebase_messaging 8.0.0-dev.5 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface]
- firebase_performance 0.4.1 [flutter firebase_core]
- firebase_remote_config 0.4.1 [flutter firebase_core]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_appavailability 0.0.21 [flutter]
- flutter_auth_buttons 0.10.0 [flutter]
- flutter_cache_manager 2.0.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
- flutter_emoji 2.2.1+1 [flutter]
- flutter_facebook_auth 0.3.3 [flutter]
- flutter_linkify 3.1.3 [flutter linkify]
- flutter_native_timezone 1.0.4 [flutter]
- flutter_offline 0.3.0 [flutter connectivity]
- flutter_secure_storage 3.3.5 [meta flutter]
- flutter_spinkit 4.1.2+1 [flutter]
- flutter_staggered_grid_view 0.3.2 [flutter]
- flutter_svg 0.19.1 [flutter meta path_drawing vector_math xml]
- flutter_xlider 3.4.0 [flutter]
- font_awesome_flutter 8.10.0 [flutter]
- get_it 5.0.1 [async meta]
- get_time_ago 0.0.6 [flutter intl]
- http 0.12.2 [http_parser path pedantic]
- humanize 0.3.0 [flutter]
- image_cropper 1.3.1 [flutter]
- image_picker 0.6.7+12 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- jiffy 3.0.1 [intl]
- json_annotation 3.1.0
- launch_review 2.0.0 [flutter]
- line_icons 0.2.0 [flutter]
- logger 0.9.4
- modal_progress_hud 0.1.3 [flutter]
- package_info 0.4.3 [flutter]
- path_provider 1.6.22 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- photo_view 0.10.2 [flutter]
- provider 4.3.2+2 [flutter nested collection]
- pull_to_refresh 1.6.2 [flutter]
- rate_my_app 0.7.2 [shared_preferences smooth_star_rating pedantic flutter]
- recase 3.0.0
- sembast 2.4.8 [meta path synchronized]
- sentry 3.0.1 [http meta stack_trace usage pedantic]
- share 0.6.5+3 [meta mime 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]
- shimmer 1.1.2 [flutter]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- webview_flutter 1.0.5 [flutter]
dev dependencies:
- build_runner 1.10.2 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- flutter_driver 0.0.0 [file json_rpc_2 meta path web_socket_channel vm_service_client webdriver flutter flutter_test fuchsia_remote_debug_protocol archive args async boolean_selector characters charcode clock collection convert crypto fake_async matcher platform process pub_semver source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math]
- 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]
- json_serializable 3.5.0 [analyzer build build_config json_annotation meta path source_gen]
- mockito 4.1.2 [analyzer build code_builder collection dart_style matcher meta source_gen test_api]
- test 1.16.0-nullsafety.5 [analyzer async boolean_selector coverage http http_multi_server io js node_preamble package_config path pedantic pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core]
transitive dependencies:
- _fe_analyzer_shared 7.0.0 [meta]
- analyzer 0.39.17 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob html meta package_config path pub_semver source_span watcher yaml]
- archive 2.0.13 [crypto args path]
- args 1.6.0
- async 2.5.0-nullsafety.1 [collection]
- battery_platform_interface 1.0.0 [flutter meta plugin_platform_interface]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- build 1.3.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 1.3.11 [analyzer build crypto graphs logging path package_config pub_semver]
- build_runner_core 6.0.1 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 4.3.2 [collection quiver]
- built_value 7.1.0 [built_collection collection fixnum quiver]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- charts_common 0.9.0 [collection intl logging meta vector_math]
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety.1
- code_builder 3.5.0 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.3
- connectivity_for_web 0.3.1+2 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.1.0+5 [flutter]
- connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface]
- convert 2.1.1 [charcode typed_data]
- coverage 0.14.1 [args logging package_config path source_maps stack_trace vm_service]
- crypto 2.1.5 [collection convert typed_data]
- csslib 0.16.2 [source_span]
- dart_style 1.3.6 [analyzer args path source_span]
- 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 6.0.0-nullsafety.2 [meta path]
- firebase 7.3.2 [http http_parser js]
- firebase_analytics_platform_interface 1.0.3 [flutter meta]
- firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_crashlytics_platform_interface 1.1.2 [flutter meta collection firebase_core plugin_platform_interface]
- firebase_messaging_platform_interface 1.0.0-dev.3 [flutter meta firebase_core plugin_platform_interface]
- fixnum 0.10.11
- flutter_blurhash 0.5.0 [flutter meta]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- fuchsia_remote_debug_protocol 0.0.0 [json_rpc_2 process web_socket_channel flutter_test flutter_driver archive args async boolean_selector charcode clock collection convert crypto fake_async file matcher meta path platform pub_semver source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math vm_service_client webdriver]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- graphs 0.2.0
- html 0.14.0+4 [csslib source_span]
- http_multi_server 2.2.0 [async]
- 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.16.1 [path]
- io 0.3.4 [charcode meta path string_scanner]
- js 0.6.3-nullsafety.1
- json_rpc_2 2.2.2 [stack_trace stream_channel]
- linkify 2.1.0
- logging 0.11.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- mime 0.9.7
- nested 0.0.4 [flutter]
- node_interop 1.1.1 [js]
- node_io 1.1.1 [node_interop path]
- node_preamble 1.4.12
- octo_image 0.3.0 [flutter flutter_blurhash]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.1
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- 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.10.0-nullsafety.1
- petitparser 3.1.0 [meta]
- platform 3.0.0-nullsafety.2
- plugin_platform_interface 1.0.3 [meta]
- pool 1.5.0-nullsafety.1 [async stack_trace]
- process 4.0.0-nullsafety.2 [file path platform]
- 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]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 2.0.0 [path shelf shelf_static]
- shelf_static 0.2.8 [convert http_parser mime path shelf]
- shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
- sky_engine 0.0.99
- smooth_star_rating 1.1.1 [flutter]
- source_gen 0.9.7+1 [analyzer async build dart_style glob meta path pedantic source_span]
- source_map_stack_trace 2.1.0-nullsafety.2 [path stack_trace source_maps]
- source_maps 0.10.10-nullsafety.1 [source_span]
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- sqflite 1.3.1+1 [flutter sqflite_common path]
- sqflite_common 1.0.2+1 [synchronized path meta]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- sync_http 0.2.0
- synchronized 2.2.0+2
- 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]
- test_core 0.3.12-nullsafety.5 [analyzer async args boolean_selector collection coverage glob io meta package_config path pedantic pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api]
- timing 0.1.1+2 [json_annotation]
- typed_data 1.3.0-nullsafety.3 [collection]
- url_launcher_linux 0.0.1+1 [flutter]
- url_launcher_macos 0.0.1+8 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+1 [flutter]
- usage 3.4.2 [path]
- uuid 2.2.2 [crypto convert]
- vector_math 2.1.0-nullsafety.3
- vm_service 5.2.0 [meta]
- vm_service_client 0.2.6+2 [async collection json_rpc_2 pub_semver source_span stack_trace stream_channel web_socket_channel]
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.1.0 [async crypto stream_channel]
- webdriver 2.1.2 [archive matcher path stack_trace sync_http]
- webkit_inspection_protocol 0.7.3 [logging]
- win32 1.7.3 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]
Thanks, are you able to post your android manifest xml and main activity files for reference?
Since there is nothing in the MainActivity.kt in am using io.flutter.embedding.android.FlutterActivity in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:fullBackupContent="false">
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specify that the launch screen should continue being displayed -->
<!-- until Flutter renders its first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
@Salakar Hi Mike, I have added the AndroidManifest.xml. Please let me know how I can debug the issue.
Please can you try 8.0.0-dev.6? Thanks
@Salakar I am still encountering this issue in 8.0.0-dev.6 too.
@Salakar I am still encountering this issue in
8.0.0-dev.6too.
Still app crashes
any solution
Well I'm struggling to reproduce this unfortunately ๐
Is everyone getting the same error; Unable to create service io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.embedding.engine.loader.FlutterApplicationInfo.flutterAssetsDir' on a null object reference?
Let me know how I can help you? Do you need any more information?
App crashes with receiving notification
@beauty-queen please check your Logcat and confirm if you are getting the same error.
Is everyone getting the same error; Unable to create service io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.embedding.engine.loader.FlutterApplicationInfo.flutterAssetsDir' on a null object reference?
@5hirish, @rushikeshnarwade are you able to try a potential fix (I still can't reproduce so I have no way of testing) I pushed up: https://github.com/FirebaseExtended/flutterfire/commit/33e5e35ec8fbabd06de7fa660c27bb13a6df03e9
You can use that branch as a dependency in your project by doing:
dependencies:
firebase_messaging:
git:
url: git://github.com/FirebaseExtended/flutterfire.git
path: packages/firebase_messaging/firebase_messaging
ref: "@salakar/android-background-crash"
then running pub get, flutter clean and then testing it out.
OK. Now I am getting the following error:
Unable to create service io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
So, I tried this too...but not fruitful.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
@5hirish could you try my branch again as above, I've pushed another commit
@Salakar I also found this same issue so I have tested on your branch. @salakar/android-background-crash
It seems like everything works fine; No crashes found when receive push notification in terminate state.
Thanks.
@gabf3st thanks for confirming, super helpful! If you could confirm also @5hirish then I'll get another dev release shipped.
@Salakar I am unfortunately still struggling with the java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization issue.
@5hirish can you make sure you've fetched the latest changes from my branch, it may be cached, or alternatively I've cloned that branch and called it @salakar/testing which you can switch to to avoid caching
Hi, @Salakar tested the @salakar/testing branch it is working!
Great, thanks for confirming, will ship a new dev release shortly.
Fix published in 8.0.0-dev.8 - thanks
Most helpful comment
Fix published in
8.0.0-dev.8- thanks