getDevicePushTokenAsync failing on Android build

See original GitHub issue

Summary

Getting the following error when trying to get expo push notification token on Android build. It is working fine on iOS.

Encountered an exception while calling native method: Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager: Please set your project ID. A valid Firebase project ID is required to communicate with Firebase server APIs: It identifies your project with Google.

I am not using firebase anywhere in my app. I have followed expo documentation for setting up notifications on the managed workflow (I got the registerForPushNotificationsAsync function in my code straight out of expo docs).

app.json :

"android": {
      "softwareKeyboardLayoutMode": "pan",
      "useNextNotificationsApi": true,
      "versionCode": 400020160,
      "package": "com.package.name",
      "playStoreUrl": "https://play.google.com/store/apps/...",
      "icon": "assets/images/icon.png",
      "adaptiveIcon": {
        "foregroundImage": "assets/images/....png",
        "backgroundColor": "#FFF"
      },
      "config": {
        "branch": {
          "apiKey": "ewfewfwe"
        },
        "googleMaps": {
          "apiKey": "wefweewr"
        }
      }
}

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

SDK Version (managed workflow only)

40

Environment

Expo CLI 4.1.6 environment info: System: OS: macOS 11.2.1 Shell: 5.8 - /bin/zsh Binaries: Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.3 - /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.0 AI-193.6911.18.40.6626763 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ^40.0.0 => 40.0.0 react: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 react-navigation: ^3.13.0 => 3.13.0 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

  1. Add expo-notifications and getDevicePushTokenAsync to a managed expo project
  2. Build and deploy Android
  3. getDevicePushTokenAsync returns an error

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:27 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
danprincecommented, May 20, 2021

@classiebit We ended up doing the Firebase setup, which fixed things.

In the expo-notifications package getExpoPushTokenAsync actually needs a devicePushToken (the one you get from Apple/Google) to work. If you don’t pass one explicitly, it fetches it automatically.

https://github.com/expo/expo/blob/5e0a6bc252aa05e5fa5ea371169d01902ba6bb1a/packages/expo-notifications/src/getExpoPushTokenAsync.ts#L28-L30

devicePushToken (DevicePushToken) – The device push token with which to register at the backend. Defaults to a token fetched with getDevicePushTokenAsync().

The SDK upgrades didn’t mention needing to configure a Firebase project to upgrade from the legacy notifications module, to expo-notifications, but the current docs for FCM Push make it clear that all Expo apps need it unless they are running in Expo Go (which is why we couldn’t repro the error in development).

Firebase Cloud Messaging is required for all managed and bare workflow Android apps made with Expo, unless you’re still running your app in the Expo Go app.

Finally found the spot in the docs where they mention it explicitly, too: https://docs.expo.io/push-notifications/push-notifications-setup/

For Android, both managed and bare workflow users need to follow our FCM setup guide, it should only take about 5 minutes.

No idea why this wasn’t flagged as a breaking change, unless we missed something previously and should have had this configured previously.

6reactions
Larzackcommented, Feb 13, 2021

Same for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception occurred while executing exported method ...
I upgraded my expo push notifications and whenever I run it on Android, I get the below error:.
Read more >
Push Notifications Troubleshooting & FAQ
This is a collection of FAQs and common issues when setting up push ... The getDevicePushTokenAsync method from expo-notifications allows you to get...
Read more >
Troubleshooting React-Native - OneSignal Documentation
Troubleshooting Steps. Check this page first for common issues based on React Native Setup. For Android and/or iOS Platform issues see: Android ......
Read more >
First-class push notifications for Expo apps | by Carles Capellas
getDevicePushTokenAsync : This method returns the device native push ... Rebuild the app for Android, expo build:android , for the changes to ...
Read more >
expo-notifications - npm
create, update, delete Android notification channels. API documentation. The following methods are exported by the expo-notifications module:.
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