The Additional Android Steps for Expo Notifications

Sending Push Notifications with Expo Notifications is pretty easy with the power of device tokens. However, there are some gotchas, especially for Android.

Getting Started

If you're up and running already with your dev builds, you can install Expo Notifications, ask the user for permissions, and aquire the device's token to later send push notifications to.

Use the following to install Expo Notifications. The example in the documentation uses some other packages, too, so it's worth a read. You'll need to generate new, non-emulator dev builds after you install the packages.

npx expo install expo-notifications
import * as Notifications from "expo-notifications";

The next time you run a build with the EAS CLI it will prompt you to setup iOS push notifications. You just login with your app store credentials. Easy!

Android Gotchas

Expo Notifications uses Firebase Cloud Messaging (FCM) to send push notifications to Android devices. This requires a Google service account and the corresponding credentials.

You can get your FCM V1 service account key from Firebase. If you haven't already made a Firebase project, make one now. And if you haven't already created an Android App from the project dashboard, click "Add app" and select the Android Logo. Enter the package name, which is usually in your app.json file. Run through the rest of the prompts and be sure to download the google-services.json file, add it to the root of your project, and commit it to version control. You'll need this later. Now you can download your private key which you will upload to Expo. Just go the settings for your new Android app in Firebase. It should be a cog icon. Click "Service accounts" and the button that says, "Generate new private key." This should download your key automatically as a JSON file.

Now you need to upload your private key JSON file to Expo. Login to your Expo dashboard and select your project. Click "Credentials" from the left then select your Android application identifier. You can upload the JSON file you download under the "FCM V1 service account key" section.

Lastly we'll tell Expo where to fine that google-services.json file. Head over to your app.json file and add the following under the Android section. It should looks something like this:

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

Troubleshooting

You may need to add FCM permissions to your Firebase service account from the IAM section in Google Cloud. I think Firebase does this for you, though.