[Android] [expo-notifications] Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager: Default FirebaseApp is not initialized in this process

Summary
Push notifications on Android aren’t working. I’ve followed all the steps.

I initialize the firebase app:

import { FirebaseOptions, initializeApp } from ‘firebase/app’
import googleServicesConfig from ‘./google-services.json’

const firebaseConfig: FirebaseOptions = {
apiKey: googleServicesConfig.client[0].api_key[0].current_key,
// authDomain: ‘project-id.firebaseapp.com’,
projectId: googleServicesConfig.project_info.project_id,
// storageBucket: ‘project-id.appspot.com’,
messagingSenderId: ‘REMOVED’,
appId: googleServicesConfig.client[0].client_info.mobilesdk_app_id,
// measurementId: ‘G-measurement-id’,
}

export const firebaseApp = initializeApp(firebaseConfig)
console.log(‘Initialized Firebase app’, firebaseApp)
And the following works on iOS, but not on Android:

if (IS_ANDROID) {
await Notifications.setNotificationChannelAsync(‘default’, {
name: ‘default’,
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: COLORS.primary[500],
})
}

let permissions = await Notifications.getPermissionsAsync()
let finalStatus = permissions.status
console.log(‘Received notification permissions’, permissions)
if (finalStatus !== ‘granted’) {
console.log(‘Requesting notification permissions’)
permissions = await Notifications.requestPermissionsAsync()
finalStatus = permissions.status
console.log(‘Finished requesting permissions’, permissions)
}
if (finalStatus !== ‘granted’) {
console.log(‘Failed to get push token for push notification’, permissions)
return null
}

let token
try {
token = (
await Notifications.getExpoPushTokenAsync({
experienceId: ‘REMOVED’,
})
).data
} catch (err) {
console.error(‘Error getting Expo push token’)
return null
}

console.log(‘Received Expo push token %s’, token, { permissions })

return token
}
Here’s the full error:

ExceptionsManager.js:151 Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager: Default FirebaseApp is not initialized in this process com.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.
What platform(s) does this occur on?
Android

Environment
expo-env-info 1.0.5 environment info:
System:
OS: macOS 12.4
Shell: 3.0.2 - /usr/local/bin/fish
Binaries:
Node: 16.18.1 - /usr/local/bin/node
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 8.19.2 - /usr/local/bin/npm
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 30, 31, 32, 33
Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 33.0.0
System Images: android-30 | Google Play Intel x86 Atom, android-33 | Google APIs Intel x86 Atom_64
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Expo Workflow: bare

Minimal reproducible example
Set up an Expo v47 bare Android app with firebase and notifications and attempt running the code above.

Create Firebase app with same package id (eg. com.myapp)
Enable Cloud Messaging API (Legacy):

Firebase Cloud Messaging API (V1)Enabled
Recommended for most use cases. Learn more

Sender ID Service Account
REMOVED Manage Service Accounts
Cloud Messaging API (Legacy)Enabled
If you are newly integrating messaging into your app, use the latest Firebase Cloud Messaging API (V1). If you are an existing user of Cloud Messaging API (Legacy), consider migrating to the latest Firebase Cloud Messaging API (V1). Learn more

Key Token
Server key REMOVED
Sender ID
REMOVED
Set FCM Server Key Snippet
Download google-services.json and put in root and android/app folders
Specify googleServicesFile: ‘./google-services.json’ in app.config.ts

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.