0

Background

I have an older app that still runs properly and is based on an old version of Firebase using the Real-time database functionality.

It runs on my emulator that does not have Google Services available.

Attempting To Upgrade To New Firebase

Now, I'm attempting to upgrade that code and I'm running on an emulator image that does not have Google Play services available.

Installed Firebase Via Android Studio Tools...Firebase...

I did the installation via the built-in tools from Android Studio (following the latest docs from Firebase).

The Problem

Every time the new code based on the latest version of Firebase attempts to call the following line of code I get an error (follows):

FirebaseDatabase fbd = FirebaseDatabase.getInstance();

Error Message

I get the following error:

Default FirebaseApp is not initialized in this process . Make sure to call FirebaseApp.initializeApp(Context) first.

I'm Already Making That Call

However, I am successfully making the call to FirebaseApp.initializeApp(Context) previous to that line of code -- I've stepped thru via debugger.

Unsure About Google Services

I've seen that some say you have to add a reference to the Google Services but I'm not sure why the Firebase docs don't mention that and the built-in Android Studio tool didn't add it.

Can you point me to a definitive place in the docs where it says you need Google Services? Has anyone experienced this? Does anyone know for sure if Google Services are required?

raddevus
  • 8,142
  • 7
  • 66
  • 87
  • 1
    Realtime Database currently doesn't require Play Services. The source is open, you can examine it for yourself. – Doug Stevenson Feb 20 '19 at 23:57
  • @DougStevenson Thanks for the information. Now, I just wonder why it is crashing on that line with that specific error about not being initialized when I am making the initialization call? I also wonder why the docs are so misleading by showing that Also Google Play Services line. Well, that's docs for you. :) – raddevus Feb 21 '19 at 12:45
  • I discovered why it continually failed and wrote up the resolution (https://stackoverflow.com/questions/40081539/default-firebaseapp-is-not-initialized/54810066#54810066) It seems there is a bit of a problem when including the classpath 'com.google.gms:google-services:4.1.0' version. If you don't have a google-services.json it won't warn you. However, I changed it to 4.0.1 and I got a warning that led me down the correct path and was able to resolve it. – raddevus Feb 21 '19 at 15:14

1 Answers1

0

Ok, I looked more closely at the Firebase docs (https://firebase.google.com/docs/reference/android/com/google/firebase/database/FirebaseDatabase.html#getInstance(java.lang.String))

Here's a snapshot of the info:

also google play services

I'm adding that because of that odd Also: Google Play Services item. It's a link that does nothing. It isn't very helpful, but

I'm assuming it means that you do indeed need Google Play Services to be available.

This situation is odd for another reason also, and that is because the call to FirebaseApp.initializeApp(this); succeeds without error even though you can basically do nothing after that, since you will have a dependency upon Google Services for the core functionality.

raddevus
  • 8,142
  • 7
  • 66
  • 87
  • The realtime database in firebase doesn't need google play services - even though the documents are somewhat misleading. The real issue here is detailed at my answer at: https://stackoverflow.com/questions/40081539/default-firebaseapp-is-not-initialized/54810066#54810066 – raddevus Feb 21 '19 at 18:43