expo: [SDK 38] getExpoPushTokenAsync() throws error in android production
đ Bug Report
Summary of Issue (just a few sentences)
When building to standalone android APK, the âgetExpoPushTokenAsync()â function from âexpo-notificationsâ throws an error relating to a Firebase token fetch issue despite google-services.json file being present and referenced in app.json setup.
Environment - output of expo diagnostics
& the platform(s) youâre targeting
Expo CLI 3.21.13 environment info: System: OS: Windows 10 10.0.18362 Binaries: Node: 12.16.0 - C:\Program Files\nodejs\node.EXE npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
Android standalone app running on android 9 security patch 1 Oct 2019 (OxygenOS 9.0.6)
Reproducible Demo
https://snack.expo.io/@jamies1211/expopushtoken-collection
Steps to Reproduce
- Using code as shown in snack
- Configure FCM as outlined in this guide - https://docs.expo.io/push-notifications/using-fcm/
- Build standalone android app
Expected Behavior vs Actual Behavior
âgetExpoPushTokenAsync()â throws error rather than resolving ExpoPushToken object required to send android devices push notifications.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 30 (10 by maintainers)
Commits related to this issue
- [docs] Instruct user to check Firebase API Key restrictions Added in an extra step in the 'Client Setup' step of the 'Using FCM for Push Notifications' doc. Firebase will sometimes reuse an existing... — committed to ShaneMcNamara/expo by ShaneMcNamara 3 years ago
- [docs] Instruct user to check Firebase API Key restrictions (#12253) * [docs] Instruct user to check Firebase API Key restrictions Added in an extra step in the 'Client Setup' step of the 'Using F... — committed to expo/expo by ShaneMcNamara 3 years ago
Just managed to track down the solution for my situation.
Prior to setting up push notifications, Iâd followed the steps for setting up MapView with the Google Maps API: https://docs.expo.io/versions/latest/sdk/map-view/ , which involves setting up a Google API key with some restrictions.
When I later enabled Firebase SDK, even though it creates a new unrestricted API key, the key it used in the generated
google-services.json
was the old restricted one.Removing these restrictions via Google Cloud Platform -> APIs & Services -> Credentials solved the problem (as Iâm sure switching to the auto generated Firebase key would have).
Thanks for looking into it @mczernek and sorry for not spotting the key mismatch sooner.
Might be worth making these errors more specific to what could be wrong in an Expo project, or a troubleshooting section in the docs, as nearly all the Google results for
FIS_AUTH_ERROR
were talking about library version problems. In Expo projects I suspect the situations would be:Fetching the token failed: Given String is empty or null
->google-services.json
was not correctly linked inapp.json
last time the standalone app was built.Fetching the token failed: FIS_AUTH_ERROR
-> the credentials ingoogle-services.json
werenât able to authenticate for Firebase Messaging; check the APIs are enabled and the key inclient.api_key.current_key
has permission to access them.@jamesisaac thank you so much worked a charm. Was starting to pull my hair out after trying everything mentioned here but we are all good now!
Thanks a lot for the update @jamesisaac! Thatâs a relief it works! Hopefully others will benefit from your findings!
Opened a somewhat similar issue #9347, which might not be directly related, but dropping it here in case someone with that issue ends up to this thread from Google for example
@mczernek Yup, this is with
"useNextNotificationsApi": true,
, and following all the instructions regarding the latest API.@cruzach Just created a new project with
expo init
on latest CLI, made sure I had the 3 app.json options you highlighted configured, and tested the code from the Snack. It works when running within Expo, but once published as a standalone app it no longer works, alerting about theFIS_AUTH_ERROR
/E_REGISTRATION_FAILED
. This is on Android 10.When you tested it, was that as a standalone app? Iâve not had any issues getting the token from within the Expo host⌠itâs only in standalone where things stop working (like @blackjacksme says too).