728x90
반응형

 

플러터로 개발중에 sdk 를 3.3.0 으로 버전업을 한 뒤로 firebase_messging을 사용하는 Android에서 BackgroundHandler함수 호출을 못하는 문제점이 생겼어요.

 

 

문제발생

당황스러운건 Debug 모드에서는 정상적으로 호출이 되다가 Release 모드에서만 갑자기 동작을 안해서 오류가 있는지도 몰랐다는 것이었죠.

 

release 모드로 빌드를 한다음 해당 오류가 발생하는것을 알게되었습니다.

flutter run --release
E/flutter (12708): [ERROR:flutter/lib/ui/dart_runtime_hooks.cc(38)] Dart Error: Unhandled exception:
E/flutter (12708): NoSuchMethodError: No top-level getter '_firebaseMessagingBackgroundHandler' declared.
E/flutter (12708): Receiver: top-level
E/flutter (12708): Tried calling: _firebaseMessagingBackgroundHandler
E/flutter (12708): #0      NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:225)
E/flutter (12708): #1      FfiTrampoline___getCallbackFromHandle$Method$FfiNative$Ptr (dart:ffi)
E/flutter (12708): #2      _getCallbackFromHandle (dart:ui/natives.dart:141)
E/flutter (12708): #3      PluginUtilities.getCallbackFromHandle.<anonymous closure> (dart:ui/plugins.dart:81)
E/flutter (12708): #4      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:524)
E/flutter (12708): #5      PluginUtilities.getCallbackFromHandle (dart:ui/plugins.dart:80)
E/flutter (12708): #6      _firebaseMessagingCallbackDispatcher.<anonymous closure> (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:40)
E/flutter (12708): #7      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:555)
E/flutter (12708): #8      MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:548)
E/flutter (12708): #9      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:393)
E/flutter (12708): #10     _invoke2 (dart:ui/hooks.dart:183)
E/flutter (12708): #11     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:40)
E/flutter (12708): #12     _Channel.push (dart:ui/channel_buffers.dart:130)
E/flutter (12708): #13     ChannelBuffers.push (dart:ui/channel_buffers.dart:326)
E/flutter (12708): #14     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:664)
E/flutter (12708): #15     _dispatchPlatformMessage (dart:ui/hooks.dart:86)

 

 

 

이슈확인

NoSuchMethodError: No top-level getter '_firebaseMessagingBackgroundHandler' declared. 오류로 고통받는 개발자가 많이 생길것이라고 봅니다.

 

문제점 해결은 github 링크를 참고했습니다.

 

https://github.com/firebase/flutterfire/issues/9446#issuecomment-1240554285

 

🐛 [firebase_messaging] `onBackgroundMessage` is never called when using Flutter 3.3.0 in release mode on Android · Issue #94

Bug report When an app using firebase_messaging is built using Flutter 3.3.0, onBackgroundMessage is not being called at all on Android. When using Flutter 3.0.5, the app receives notifications in ...

github.com

 

 

 

해결

backgroundHandler에 @pragma 애노테이션을 작성하고 다시 Release 모드로 시작하면 문제가 사라진것을 알 수 있습니다.

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  ...
}

 

https://api.dart.dev/stable/2.1.0/dart-core/pragma-class.html

 

pragma class - dart:core library - Dart API

pragma class A hint to tools. Tools that work with Dart programs may accept hints to guide their behavior as pragma annotations on declarations. Each tool decides which hints it accepts, what they mean, and whether and how they apply to sub-parts of the an

api.dart.dev

 

 

 

 

firease_messaging Release모드에서 백그라운드 알림 수신을 하지 않는다는것은 정말 치명적이네요.

 

firebase_messaging을 사용하시는 분들에게 문제점 해결에 도움이 되었으면 합니다.

 

728x90
반응형

+ Recent posts