I am unable to obtain an instance of Firebase Firestore on Android.This line of code below fails repeatedly.
FirebaseFirestore db = FirebaseFirestore.getInstance();
It throws java.lang.IllegalArgumentException
with the error
FirebaseOptions.getProjectId() cannot be null
Caused by: java.lang.IllegalArgumentException: FirebaseOptions.getProjectId() cannot be null
at com.google.firebase.firestore.FirebaseFirestore.zze(Unknown Source)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(Unknown Source)
I have enabled Firestore on the console, I have used Firebase Assistant to ensure Android Studio project is synched up correctly with the console project. Other Firebase components that I am using such as Real-time Database, Authentication, Storage, etc works except Firestore.
I have added the dependency compile 'com.google.firebase:firebase-firestore:11.4.2'
What am I missing?
We will read all data from Firebase Firestore inside our app. Go to the activity_main.xml file add one more Button for showing the list of all added courses. Below is the code snippet and add the code at last.
By using the Firebase Android BoM , your app will always use compatible versions of the Firebase Android libraries. If you choose not to use the Firebase BoM, you must specify each Firebase library version in its dependency line.
You'll need to manually require both Firebase and Cloud Firestore. Follow the instructions to add Firebase to your Web app . The Cloud Firestore SDK is available as an npm package. You'll need to import both Firebase and Cloud Firestore. Looking for a compact Firestore library, and only need simple REST/CRUD capabilities?
Using the Firebase Android BoM , declare the dependency for the Cloud Firestore Android library in your module (app-level) Gradle file (usually app/build.gradle ). By using the Firebase Android BoM , your app will always use compatible versions of the Firebase Android libraries.
The project ID is read from the google-services.json
file.
Make sure you have a recent google-services.json
file and are using com.google.gms:google-services:3.1.0
or higher (not 3.0.0
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With