question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to authenticate with the FCM server [ANDROID] EAS build

See original GitHub issue

Summary

Hey guys i’m trying to integrate expo notifications in my managed app. I created a custom client since we are using libraries with native code. I installed expo notifications. followed the Using FCM for Push Notifications instructions manually uploaded my API key from the Credentials Tab to Android (EAS) on expo.dev made sure my API key is not restricted, and made sure i’m using the same one thats in my google-services.json file

but every time I try to send a notification I get the following error on Android

` “data”: Object { “details”: Object { “error”: “InvalidCredentials”, “fault”: “developer”, “fcm”: Object { “httpStatus”: 401, “response”: "<HTML>

<HEAD> <TITLE>INVALID_KEY_TYPE</TITLE> </HEAD> <BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">

INVALID_KEY_TYPE

Error 401

</BODY> </HTML> ", }, }, "id": "f575fde5-db1f-418f-9e00-a6a6bc6c2e10", "message": "Failed to authenticate with the FCM server. Ensure the FCM server key you uploaded is correct.", "status": "error", }, }`

Package version : “expo-notifications”: “~0.12.3”,

app.json { “expo”: { “name”: “EventShare”, “slug”: “EventShare”, “version”: “0.1.0”, “orientation”: “portrait”, “icon”: “./assets/1024.png”, “splash”: { “image”: “./assets/splash.png”, “resizeMode”: “contain”, “backgroundColor”: “#ffffff” }, “androidStatusBar”: { “backgroundColor”: “#ffffff”, “translucent”: true }, “updates”: { “fallbackToCacheTimeout”: 0 }, “assetBundlePatterns”: [“**/*”], “ios”: { “supportsTablet”: true, “userInterfaceStyle”: “dark”, “infoPlist”: { “NSCameraUsageDescription”: “This app uses the camera to take pictures, videos and scan barcodes on from other users.” }, “bundleIdentifier”: “com.simplyrem.GalleryShare”, “buildNumber”: “1.0.8”, “icon”: “./assets/1024.png” }, “android”: { “jsEngine”: “hermes”, “googleServicesFile”: “./google-services.json”, “adaptiveIcon”: { “foregroundImage”: “./assets/adaptive-icon.png”, “backgroundColor”: “#FFFFFF” },

        "userInterfaceStyle": "dark",
        "package": "com.simplyrem.GalleryShare"
    },
    "web": {
        "favicon": "./assets/favicon.png"
    }
}

}

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android, iOS

SDK Version (managed workflow only)

42

Environment

Expo CLI 4.7.3 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.15.1 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.8.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.1 AI-201.8743.12.41.6858069 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ^42.0.0 => 42.0.0 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.7.3 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

  1. create a custom client
  2. install expo-notifications
  3. create Firebase Cloud Messaging file
  4. drop it in your projects root directory
  5. add “android”: { “googleServicesFile”: “./google-services.json”, … }
  6. rebuild custom client using eas build --profile development --platform android
  7. Run code to get expo notification token.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
haibertcommented, Jul 28, 2021

HERE IS THE FULL SOLUTION

For android you have to do the Firebase Cloud Messaging steps. For iOS you need to make sure you choose your credentials. Both tasks are explained below. Unless you’re still running your project in the Expo Go app, Firebase Cloud Messaging is required for all managed and bare workflow Android apps made with Expo. Full Instructions Here is my version of the FULL instructions on getting notifications working on both platforms after expo install expo-notifications if you are using a custom client and EAS. Youtube video showing how to add firebase to your project. Start watching from 4:00 minutes https://www.youtube.com/watch?v=dRYnm_k3w1w

  1. Create a new android project
  2. In your project main page click on the Android Icon
  3. Add the projects package name from your app.jason
  4. Add nickname for your project
  5. Click “Register your app”
  6. Download the google-services.json file and place it in your Expo app’s root directory.
  7. Go to your app.json and the following line and save it { “android”: { “googleServicesFile”: “./google-services.json”, } }
  8. Go to Firebase project, Settings -> ProjectSettings -> Cloud Messaging -> copy the Server key. Run this command to add your FCM SERVER key to your project. expo push:android:upload --api-key AAAACq0C1Mg:APA91bHMt-e2TAR67C-W2pg0At8Jmuamfs29vZK9dsrjXfTRpue4FHfCymMGNhBZwOwspJ8ydbAnNtbddZTrAD1J2nu6cUqcaFjDHIVg-F5CAwUmH70bkYye18rPqY8y48 (note that doing this step on expo.dev from the GUI does not take effect! …must be taken care of by expo, also the command says --api-key which is confusing because you are uploading the Server key in this step.)
  9. Run eas credentials choose Android, then choose Push Notifications: Manage your FCM Api Key, then paste your long ass API key here as well.
  10. Set up your iOS push notification credentials by running run expo credentials:manager -p ios , then select Use existing Push Notifications Key in current project or use a new one…
  11. Run the command to build your app eas build --profile development --platform both 12.Make sure to include the experience id in your getExpoPushTokenAsync call. The experience id is @username/appSlug. ex: @haibert/EventShareApp token = await Notifications.getExpoPushTokenAsync({ experienceId: '@username/projectSlug, })
  12. To make sure your API key is unrestricted make sure you’re on the correct project when going on the following link Cloud Platform API Credentials console. Then click on the pencil icon on the api for android. It was unrestricted by default but just checked incase.
1reaction
haibertcommented, May 18, 2022

@AlexanderLindkjaer Anytime my man! Ive told Evan before… i’ve said it many times and i’ll say it again. Very detailed documentation is awesome but nothing beats a quick easy to follow / dummy proof list that gets you up and running. So glad it helped someone 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expo Notification 401 Error "Project not permitted" #16215
Yesterday I have create the project and I have the same issue. Never seen this issue before. An error occurred when trying to...
Read more >
Error while trying to send push notifications - Stack Overflow
I've tested with android. After old server key failed I tried creating new server key and uploading it to expo server
Read more >
Using FCM for Push Notifications - Expo Documentation
To set up your Expo Android app to get push notifications using your own FCM credentials, follow this guide closely. Note that FCM...
Read more >
Sending Notifications with APNs & FCM - Expo Documentation
Communicating directly with APNs and FCM is much more complicated than sending notifications through Expo's push notification service, so you should only use ......
Read more >
Latest Expo SDK topics - Forums
Topic Replies Views Activity React Native Web Error 1 61 May 11, 2022 Expo updates doesn't work correctly · updates 1 101 May 8, 2022 readable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found