I’m new in react native, and I’m creating a simple test app. I followed the firebase documentation and inserted the dependencies and the google-services.json file. The problem is that now I would like to read the data from my realtime database, and following the documentation I did something like this:
...
import { firebase } from '@react-native-firebase/app';
const Categories = () => {
const reference = firebase
.app()
.database('https://testapp-app-default-rtdb.euorpe-west1.firebasedatabase.app/')
.ref('/categories');
...
But if I running the command from the terminal: npx expo start
to test the application on my Android phone, the console gives me this error:
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.
How can i solve this to test my app with db?
2
Answers
For Anwer, this is my updated dependencies:
And this is my app.json:
I also inserted the "google-services.json" file in my Android/app folder and the other part in build.gradle, app/build.gradle and the import in MainApplication.kt
According to the documentation of React Native Firebase you are importing the the firebase module from
@react-native-firebase/app
instead of@react-native-firebase/database
So you have to install the Realtime-Database module to read data. Install the module using the command
npm install @react-native-firebase/database
rebuild the app.Then simply import the database:
If the database is not ‘us-central1’, that is your case, you can import it as below: