Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Android firebase notification doesn't work in release mode

We have two apps the first app sends a request to Backend(Laravel) then the backend sends the notification to firebase(we receive the correct response from firebase) and the second app should receive a notification, everything works fine in the debug mode(when my phone is connected to Android Studio) once I release it on Google play it doesn't work, the second app doesn't receive any Notification.

I added the SHA1 for each app in firebase, each app has 2 SHA1

1- App signing key certificate

2- local SHA1

also the "Android key (auto created by Firebase)" is restricted with the SHA1 keys for the apps

The issue only happens in release mode

I did download a new version of google-services.json after adding the keys and uploaded the bundle to play console

What I'm missing here? Thanks

like image 630
hkmbkjkj Avatar asked Sep 03 '25 09:09

hkmbkjkj


1 Answers

Found the answer in this flutterfire issue.

You have to prepend the following line to your background message handler:

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

It will prevent the handler from being removed during tree shaking when building for release mode.

like image 88
Ari Avatar answered Sep 04 '25 23:09

Ari