Android push problem: Unable to retrieve the FCM server key for the recipient's app

Hello,

I’m running an expo app in the bare workflow and am currently trying to get push messages to work on Android.

I can retrieve the ExpoPushToken strings from the phones perfectly fine, but when I try to actually send a push message I get the following error: “Unable to retrieve the FCM server key for the recipient’s app. Make sure you have provided a server key as directed by the Expo FCM documentation.”

I looked through the related threads, but none of the tips there seemed to help.

Things I already tried and checked:

  • The google-services.json file is downloaded to **./android/app/google-services.json". The expo.android.googleServicesFile key in app.json points there.
  • $ expo push:android:show returns the correct FCM API key
  • I tried to clear this and re-upload the key. I get a success message for storing the key, but still fail to push a message.
  • I tried to set the key through credentials manager. The upload works, the error message does not change.
  • I created an new server key in Firebase Console and tried that, but it also did not work
  • The package name in the Firebase console matches the key android.defaultConfig.applicationId in android/app/build.gradle and android.package in app.json
  • In the Google Cloud Console, I have enabled the Cloud Messaging, Firebase Cloud Messaging API, Firebase Installations API and FCM Registration API
  • I tried setting the “owner” property in app.json - it did not have any effect, I’m not on a paid plan but was desperate for ideas :wink:
  • I removed the app from the Firebase project and added it again.
  • I removed the whole Firebase project and re-created it. Still, same error message.
  • I tried sending the message through expo’s push notification tool at Push Notification Tool — Expo - same error

Any suggestions and hints are greatly appreciated. I have completely run out of ideas :frowning_face:

Thanks,
Bernhard

Hi! sorry this is giving you so much trouble, it looks like you’ve really done everything we recommend doing to solve this :thinking:

What value are you passing for experienceId to getExpoPushTokenAsync?

Charlie, thank you for your reply!
I’m passing “default” as experienceId. I just tried some random string, but still got the same result. :frowning:

When you run expo push:android:show, it should print out something like:

Accessing credentials for <your username> in project <your project slug>

this combination of @username/projectSlug is what’s known as your “experience ID”, which is used both in expo-updates for OTA updates, and expo-notifications, and that’s what you should pass to getExpoPushTokenAsync

Thank you, Charlie! That was indeed the problem. The notifications work now.

Having this piece of information now, I notice that this is explained in the code sample of Notifications - Expo Documentation . But it was not obvious to me before.
Does it maybe make sense to extend the description of the experienceId parameter, which is currently “You may need to define it in bare workflow, where expo-constants doesn’t expose the manifest.”? Maybe it could say right there that it needs to be @username/project-slug.

definitely, I’ll update that today!

updated here - [docs] must pass `experienceId` to getExpoPushTokenAsync in bare by cruzach · Pull Request #10782 · expo/expo · GitHub

1 Like

I’m running into the same issue with my project, but I am just calling getExpoPushTokenAsync() with no additional arguments. Is the experienceId only necessary in the bare workflow (I am using the managed workflow)? I tried similar things as above, and everything is uploaded correctly and works most of the time, but I get this as an intermittent failure. Are those tokens invalid or is this indicative of a bigger problem? Any insight here would be helpful.

For example, for one user, I only get this notification on 1 of his 3 expo tokens. Is there something wrong with that token? Should I delete tokens that return this error?

Cheers,
Julian

For example, for one user, I only get this notification on 1 of his 3 expo tokens. Is there something wrong with that token? Should I delete tokens that return this error?

not sure I understand- if you receive this error, then you are not receiving a push token.

I understood the issue and resolved it.

I built a beta version of my app under a different expo account, not associated with the same FCM. So then that expo push token generated with the beta build was invalid.

Thanks

This worked for me, thank you! I added the experienceId to getExpoPushTokenAsync and it works great! :slight_smile:

› Expo SDK: 40.0.0
› Workflow: Bare