Guides
Plan-enterprise-icon
Expo Application Services
API Reference

Using FCM for Push Notifications

Firebase Cloud Messaging is required for all Android apps using Expo SDK, unless you're still running your app in the Expo Go app. To set up your Expo Android app to get push notifications using your own FCM credentials, follow this guide closely.
Warning-icon
Note that FCM is not currently available for expo-notifications on iOS.

Client Setup

  1. If you have not already created a Firebase project for your app, do so now by clicking on Add project in the Firebase Console.
  2. In your new project console, click Add Firebase to your Android app and follow the setup steps. Make sure that the Android package name you enter is the same as the value of android.package in your app.json.
  3. Download the google-services.json file and place it in your app's root directory.
    Info-icon
    The google-services.json file contains unique and non-secret identifiers of your Firebase project. For more information, see Understand Firebase Projects.
  4. In your app.json, add an android.googleServicesFile field with the relative path to the google-services.json file you just downloaded. If you placed it in the root directory, this will probably look like
    {
      ...
      "android": {
        "googleServicesFile": "./google-services.json",
        ...
      }
    }
    
  5. Confirm that your API key in google-services.json has the correct "API restrictions" in the Google Cloud Platform API Credentials console. For push notifications to work correctly, Firebase requires the API key to either be unrestricted (the key can call any API), or have access to both Firebase Cloud Messaging API and Firebase Installations API. The API key can be found under the client.api_key.current_key field in google-services.json.
    {
      ...
      "client": [
        {
          "api_key": [
            {
              "current_key" "<your Google Cloud Platform API key>",
            }
          ],
        }
      ]
    }
    
    Info-icon
    Firebase will create an API key in the Google Cloud Platform console with a name like Android key (auto created by Firebase). This is not always the same key as the one found in google-services.json. Always confirm your key and associated restrictions in the Google Cloud Platform console.
    Info-icon
    Firebase projects with multiple Android apps might contain duplicated data under the client array in the downloaded google-services.json. This can cause issues when the app is fetching the push notification token. Make sure to only have one client object with the correct keys and metadata in google-services.json.
  6. Finally, make a new build of your app by running eas build --platform android (or expo build:android if you're using the classic build system).

Bare projects

If you do the above setup before ejecting to bare, your FCM notifications will continue to work properly without any extra steps after ejecting. However, if your project is already ejected to bare and you want to set up FCM retroactively, you'll need to:

Uploading Server Credentials

In order for Expo to send notifications from our servers using your credentials, you'll need to upload your secret server key. You can find this key in the Firebase Console for your project:
  1. At the top of the sidebar, click the gear icon to the right of Project Overview to go to your project settings.
  2. Click on the Cloud Messaging tab in the Settings pane.
  3. Copy the token listed next to Server key.
    Info-icon
    Server Key is only available in Cloud Messaging API (Legacy), which may be disabled by default.
    Enable it by clicking the 3-dot menu > Manage API in Google Cloud Console and follow the flow there. Once the legacy messaging API is enabled, you should see Server Key in that section.
  4. In your Expo account's dashboard, select your project, and click on Credentials in the navigation menu. Then, click on your Application Identifier that follows the pattern:com.company.app.
    Info-icon
    For Legacy Application Identifiers, run expo push:android:upload --api-key <your-token-here>, replacing <your-token-here> with the string you just copied. We'll store your token securely on our servers, where it will only be accessed when you send a push notification.
  5. Check that all of your Service Credentials are filled correctly. If the FCM Server Key is empty, then you can add the copied Server key from Step 3. If the FCM Server Key is populated, verify that the last characters match the Server Key from Step 3.
    Warning-icon
    Having Service Credentials in both Legacy and non-legacy Application Identifiers can prevent push notifications from working on android devices. If you have a Legacy Application Identifier, you might need to remove all of its Service Credentials.
Users who run this new version of the app will now receive notifications through FCM using your project's credentials. You can now send push notifications normally. For more information, see Sending Notifications. We'll take care of choosing the correct service to send the notification.

See also

  • Message-iconAsk a question on the forums
  • Edit-iconEdit this page

Was this doc helpful?