Firebase Firestore GetInstance Failing on Android

2019-07-13 08:18发布

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?

4条回答
地球回转人心会变
2楼-- · 2019-07-13 08:35

Copy project_id from google-services.json to string.xml then it works fine.

查看更多
相关推荐>>
3楼-- · 2019-07-13 08:37
changing the project gradle google services worked for me thanks

just by adding in the project gradle, under dependencies

dependencies {

    classpath 'com.google.gms:google-services:4.2.0'

}
查看更多
走好不送
4楼-- · 2019-07-13 08:43

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

查看更多
女痞
5楼-- · 2019-07-13 08:55

Try updating your implementation 'com.google.firebase:firebase-firestore:17.0.2'
That's that latest currently. Please check your firebase console for the most recent version

查看更多
登录 后发表回答