Firebase.initializeApp(); and FirebaseMessaging.instance.getToken() throws android native exceptions

Viewed 151

I'm using FlutterFire Cli to configure my firebase project it was working and i hadn't change any single line of code and i have an online version of the application on google play

then the deployed version is stopped working and after debugging it start showing at any time the app is trying to initialize firebase project or getToken Failed to get FIS auth token

E/FirebaseMessaging(31532):     at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@18.0.1:5)
E/FirebaseMessaging(31532):     at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@18.0.1:8)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.GmsRpc.setDefaultAttributesToBundle(GmsRpc.java:260)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.GmsRpc.startRpc(GmsRpc.java:222)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.GmsRpc.getToken(GmsRpc.java:180)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.FirebaseMessaging.lambda$blockingGetToken$10$FirebaseMessaging(FirebaseMessaging.java:610)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.-$$Lambda$FirebaseMessaging$1AYfBMlbEOJoTvXNS_TEZqpK2SY.start(Unknown Source:6)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(RequestDeduplicator.java:67)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(FirebaseMessaging.java:606)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.FirebaseMessaging.lambda$getToken$4$FirebaseMessaging(FirebaseMessaging.java:392)
E/FirebaseMessaging(31532):     at com.google.firebase.messaging.-$$Lambda$FirebaseMessaging$m5Uvt0n8P9zrx-ecASLTQKzoABQ.run(Unknown Source:4)
E/FirebaseMessaging(31532):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
E/FirebaseMessaging(31532):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/FirebaseMessaging(31532):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
E/FirebaseMessaging(31532):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/FirebaseMessaging(31532):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/FirebaseMessaging(31532):     at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.0.0:2)
E/FirebaseMessaging(31532):     at java.lang.Thread.run(Thread.java:919)
E/FirebaseMessaging(31532): Caused by: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
E/FirebaseMessaging(31532):     at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:153)
E/FirebaseMessaging(31532):     at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:530)
E/FirebaseMessaging(31532):     at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:385)
E/FirebaseMessaging(31532):     at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$2$FirebaseInstallations(FirebaseInstallations.java:374)
E/FirebaseMessaging(31532):     at com.google.firebase.installations.-$$Lambda$FirebaseInstallations$VZq1h0TBcWNH8Y5yY86ujrFFyLo.run(Unknown Source:4)
E/FirebaseMessaging(31532):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/FirebaseMessaging(31532):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/FirebaseMessaging(31532):     ... 1 more
Lost connection to device 

I'm using

firebase_core: ^1.20.0 firebase_messaging: ^12.0.1

After Doing Flutter Clean and Deleting Build Folder it shows

error when communicating with firebase installation , server api , Http response [ 403 forbidden: 

Although im not using any vpn

I've tried many solutions like creating new firebase project via flutterfire and still showing me the same errors

Any Solutions ? and thanks

3 Answers

I found the issue. I’m living in Syria, and it has become forbidden to call getToken for the first time without a VPN, at least for Android devices.

This occurs when one of the dependancies of firebase is out of date. You Should update all the firebase packages to their newest version in the pubspec.yaml . (If you do not need to use a specific version for deployment). You can check out the newest versions on pub.dev

Firebase SDKs depend on a new internal infrastructure service, called FIS (the Firebase Installations Service) since February 27 2020 and it's now required to connect to this API to register client's device and get a token. So, Firebase will request something like this (https://firebaseinstallations.googleapis.com/v1/projects/$project_identifier/installations/?key=$api_key) to do so. After investigating you can see that this process it done by google-play-services and called from Firebase-Plugin as shown here :

https://github.com/firebase/firebase-android-sdk/blob/c6cc8c5d4a00518033a6f281486c9610b821e1c4/firebase-messaging/src/main/java/com/google/firebase/messaging/GmsRpc.java#L260

So, I Think if you can edit the plugin to send the requests to a proxy server then to the FIS API you can go around this issue.

Unfortunately,I can confirm that the FIS API now gives 403 error in Syria.

Hope google resolve this issue soon...

Related