expo: getDevicePushTokenAsync failing on Android build
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
- Add expo-notifications and getDevicePushTokenAsync to a managed expo project
- Build and deploy Android
- getDevicePushTokenAsync returns an error
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 29 (2 by maintainers)
For anyone still looking for a solution with EAS Build, I had to do this (using Expo SDK 46) In my root level build.gradle, I added this under dependencies
classpath("com.google.gms:google-services:4.3.2")In app/build.gradle, add this at the end of the fileapply plugin: 'com.google.gms.google-services'based on this s/o answer https://stackoverflow.com/questions/40081539/default-firebaseapp-is-not-initialized
@classiebit We ended up doing the Firebase setup, which fixed things.
In the
expo-notificationspackagegetExpoPushTokenAsyncactually needs adevicePushToken(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
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).Finally found the spot in the docs where they mention it explicitly, too: https://docs.expo.io/push-notifications/push-notifications-setup/
No idea why this wasn’t flagged as a breaking change, unless we missed something previously and should have had this configured previously.
We’re seeing this behaviour on an app that has been using Expo’s push service.
We only use the
Notifications.getExpoPushTokenAsync()function from theexpo-notificationspackage, and yet we’re getting this error aboutgetDevicePushTokenand Firebase projects.Nothing in the migration guide for
expo-notificationsmentioned that the Expo push service would require a Firebase project, so we’re a little bit lost as to why thegetDevicePushTokenmethod even gets called.These errors started showing up around the same time over the past few days. Did anyone get any further with this?
Same for me
With expo 45 was working but expo 46 not
WARN [expo-notifications] Error encountered while updating server registration with latest device push token. [Error: Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.] LOG [Error: Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.]I just hit my head on this as well going from Expo SDK 44 -> 45.
I have a MANAGED project and I run it in the Expo GO app only. Therefore according to documentation I do not need configure anything in Firebase, yet I still get this error when running the app on Android: [Unhandled promise rejection: Error: Fetching the token failed: Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.] at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:106:50 in promiseMethodWrapper at node_modules/expo-modules-core/build/NativeModulesProxy.native.js:21:23 in moduleName.methodInfo.name at node_modules/expo-notifications/build/getDevicePushTokenAsync.js:15:29 in getDevicePushTokenAsync at http://172.16.11.83:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _getDevicePushTokenAsync at http://172.16.11.83:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in getDevicePushTokenAsync at node_modules/expo-notifications/build/getExpoPushTokenAsync.js:9:62 in getExpoPushTokenAsync at http://172.16.11.83:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _getExpoPushTokenAsync at http://172.16.11.83:19000/index.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in getExpoPushTokenAsync at managers/notificationsManager.ts:53:29 in registerForPushNotificationsAsync
In order to try and fix this I run “expo start -c --android” to make the android folder appear then opened a project in Firebase (with the exact same package name as in app.json) and followed the setup firebase required for android. Of course I added the google-services file at the root of my file. Added the path to it under “android” in app.json as well. I made sure the auto-generated key in my cloud console is the same as the key in the google-services file.
All my code is taken directly from the expo documentation of expo notifications. What am I doing wrong? How can I solve this? SDK 46
implementation ‘com.google.firebase:firebase-iid:17.0.2’ in your app build.gradle works.
The version 2.25.2 fixed it
👍 Didn’t even upgrade. Still on 44, and did not update any packages. Managed workflow and running in Expo Go.