'React Native firebase connection not working properly

I have fallowed the steps and watch several videos on how to connect react-native app to a firebase. But still I'm getting this error:

Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app().

Ensure you have:

1) imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file.

2) Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.

See http://invertase.link/android for full setup instructions.
▶ 4 stack frames were collapsed.
App
C:/Users/saadb/Desktop/Smart-Mirror-App/App.js:8
   5 | 
   6 | export default function App() {
   7 | 
>  8 |   const users = firestore()
   9 |     .collection('Users')
  10 |     .get();

so, I tried to fix the error and added this to my MainApplication

 import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
 import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;

 @Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
  packages.add(new RNFirebaseMessagingPackage());
  packages.add(new RNFirebaseNotificationsPackage());
  return packages;
}

And here is my App.js file

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import firestore from '@react-native-firebase/firestore';

export default function App() {

  const users = firestore()
    .collection('Users')
    .get();

  // console.log(users);

  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I also, added all the dependencies and packages and the google.json file like the instructions. Can someone please help me to solve this problem.



Solution 1:[1]

i think if you used the firestore module directly, and not the react-native-firebase/firestore module, this should work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Imraj Singh