Omar
Omar

Reputation: 11

No Firebase App [DEFAULT] has been created call Firebase App.initializeApp() (app/no-app)

I am building React Native Expo application and i already implemented server-side FCM push notification and I am trying to generate token at application device using react native firebase and followed instucations at documentation of https://docs.expo.dev/push-notifications/push-notifications-setup/.

here is what i did:

1- npx expo install expo-notifications expo-device expo-constants

2- in my app.js:

import * as Device from 'expo-device';
import * as Notifications from 'expo-notifications';
import Constants from "expo-constants";

Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: false,
    shouldSetBadge: false,
  }),
});


async function registerForPushNotificationsAsync() {
  let token;
  if (Device.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      alert('Failed to get push token for push notification!');
      return;
    }
    token = await Notifications.getExpoPushTokenAsync({
      projectId: Constants.expoConfig.extra.eas.projectId,
    });
    console.log(token);
  } else {
    alert('Must use physical device for Push Notifications');
  }


  useEffect(() => {
    registerForPushNotificationsAsync().then(token => setExpoPushToken(token));

    notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
      setNotification(notification);
    });

    responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
      console.log(response);
    });

    return () => {
      Notifications.removeNotificationSubscription(notificationListener.current);
      Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, []);

3- in my app.json:

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

and added the file at the root of my project.

4- I made sure that api_key is the same as cloud messaging api key.

5- my app.json:

"android": {
      "googleServicesFile": "./google-services.json",
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.omur00.SarahahExpo"
    },

6- added server key to my project at expo account.

7- when setup project at firebase i made sure to put the right package name of my application there.

8- i built then a development app and ran :npx expo start --dev-client and tested the app on a real device not emulator.

so the purpose of this implementation is to generate device token and upload it later to my server-side databse so i can use it to send firebase notification.

I have tried that 4 times but i keep getting same error :

Firebase: No Firebase App [DEFAULT] has been created call Firebase App.initializeApp() (app/no-app).

or Firebase is not initialized.

Expo should initialize it for me when i insert google service file at app.json. I dont think i missed any thing while following the documentation and i have read alot of threads where people have same problem but I couldnt find an answer.

Upvotes: 0

Views: 894

Answers (1)

OmAR HaMeD
OmAR HaMeD

Reputation: 13

it happend to me before maybe this work for u: -try to open the android folder from Android Studio

Upvotes: 0

Related Questions