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

  1. Using code as shown in snack
  2. Configure FCM as outlined in this guide - https://docs.expo.io/push-notifications/using-fcm/
  3. Build standalone android app

Expected Behavior vs Actual Behavior

“getExpoPushTokenAsync()” throws error rather than resolving ExpoPushToken object required to send android devices push notifications. Capture

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 30 (10 by maintainers)

Commits related to this issue

Most upvoted comments

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 in app.json last time the standalone app was built.
  • Fetching the token failed: FIS_AUTH_ERROR -> the credentials in google-services.json weren’t able to authenticate for Firebase Messaging; check the APIs are enabled and the key in client.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 the FIS_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).