Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Firestore GetInstance Failing on Android

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?

like image 787
Val Okafor Avatar asked Oct 13 '17 15:10

Val Okafor


People also ask

How to read all data from Firebase FireStore inside an app?

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.

What version of Firebase do I need for my Android app?

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.

How do I add Cloud Firestore to my Web App?

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?

How do I use the firebase Android Bom?

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.


1 Answers

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).

like image 186
Sam Stern Avatar answered Oct 17 '22 20:10

Sam Stern