Setup expo notification with FCM

When using expo push notification, we can retrieve the device token while running the app inside Expo go app.

But the problem comes when we build a standalone app for publishing to PlayStore, the token cannot be retrieved without proper setup to the FCM.

Standalone app on ANDROID:

"Encountered with an exception while calling native method Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager. Default FirebaseApp is not initialized in this process com.algotradingapp. Make seure to call FirebaaseApp initializeApp(Context) first.

Steps:

1. Register your app on Firebase Project

Register your your android app on your firebase project. This will only work on android. On the other hand, ios builds will setup the notification settings for you as mentioned in : https://docs.expo.dev/push-notifications/using-fcm/#uploading-server-credentials

Make sure the package name mathces the android package name found in app.js

2. Download google-services.json

After filling out the android package name and app name, download google-services.json and place it in your project.

3. Open app.json, add this line:

Put the path to google-services.json file in the app.json

{
  ...
  "android": {
    "googleServicesFile": "./google-services.json",
    ...
  }
}

4. Open google-services.json

{
  ...
  "client": [
    {
      "api_key": [
        {
          "current_key" "<your Google Cloud Platform API key>",
        }
      ],
    }

5. Open Google cloud console on your project

Make sure the current key in app.json matches the api key in google cloud console, and do not restrict the key.

6. Head over to Expo.dev

Open Expo.dev, open your built android application. Click "Credentials" from the sidebar menu:

App > Configure > Credentials > Add an FCM Server key

This time the standalone app should be able to get the token.

Last updated

Was this helpful?