I want to link an Android App to Firebase to use Firestore database, Analytics, and crashlytics. I am attempting to use FirebaseApp.initializeApp()
to set the credentials.
Setting the credentials directly in the code allows for the possibility of obfuscating the credentials instead of leaving them in google-services.json.
I found the following article on medium which addresses this: https://medium.com/nerd-for-tech/secure-your-firebases-google-services-json-file-in-android-16680f8e5fb4
However, trying to implement calling FirebaseApp.initializeApp()
results in the app crashing with no apparent errors or exceptions in logcat. I'm doing the following (credentials X'ed out for obvious reasons)
FirebaseApp.initializeApp(context, new FirebaseOptions.Builder()
.setApplicationId( "XXXXXXXXX")
.setGcmSenderId("XXXXXXXXX")
.setApiKey("XXXXXXXXX")
.setStorageBucket("XXXXXXXXX")
.setProjectId("XXXXXXXXX")
.build());
db = FirebaseFirestore.getInstance();
The value in
setApplicationId()
is set to the mobilesdk_app_id in google-services.jsonThe value in
setGcmSenderId()
is set to the project_number in google-services.jsonThe value in
setApiKey()
is set to the current_key inside the api_key object in google-services.jsonThe value in
setStorageBucket()
is set to the storage_bucket in google-services.jsonThe value in
setProjectId()
is set to project_id in google-services.json.
Note that the medium article includes one more function call .setDatabaseUrl()
. This was a problem as there is apparent database URL in google-services.json file, I've been told I can get the database URL from the Realtime Database section of the Firebase console, but I'm not using the realtime database, I'm using Firestore database, so I don't include it.
With the call to FirebaseApp.initializeApp()
the app crashes, commenting out the call and the app runs.
I also tried FirebaseApp.initializeApp(context);
as I was told that that would initialize using the google-services.json file, it doesn't crash but the data still goes to the old Firebase project.
I also tried storing the return value of the FirebaseApp.initializeApp()
call in a FirebaseApp variable and passing it to the FirebaseFirestore.getInstance(app)
call, but it still crashes with no errors in logcat.
Any guidance would be greatly appreciated!