tariq101
tariq101

Reputation: 157

Firebase Database points to wrong database URL

I am working on an Android app and trying to use Firebase Database. I tried to write data to the Database but nothing was showing up (checked via Firebase console). I have Firebase libraries in the build:

implementation platform('com.google.firebase:firebase-bom:26.2.0')
implementation 'com.google.firebase:firebase-database'

My Firebase Database URL as per Firebease console is :

    https://xxxxxxxx-xxxxxxx-default-rtdb.europe-west1.firebasedatabase.app/

whereas when I get a reference to it from the code:

    private DatabaseReference mDatabase;

    mDatabase = FirebaseDatabase.getInstance().getReference();
    Log.i(TAG," Reference is: "+mDatabase.toString());

The logcat shows below response:

    I/Tag:  Reference is: https://xxxxxxxx-xxxxxxx-default-rtdb.firebaseio.com

I also have the google-services.json file in the project which points to the same database URL shown in the Firebase console. It appears to me that Firebase has misconfigured my database somewhere which I can't see / configure.

Is there anything I am missing?

Upvotes: 2

Views: 4740

Answers (3)

Shubham Rohila
Shubham Rohila

Reputation: 411

I had a similar problem, what helped me in Android Studio was

Build->Clean Project

and then

Build->Rebuild Project

Before this make sure that the firebase url in your google.json file is correct and you have the latest google.json file.

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 598740

I just tested this on a new project of my own with the exact same BoM version as you, and it works fine with just the google-services.json file and this code:

final DatabaseReference ref =  FirebaseDatabase.getInstance().getReference();
Log.i("firebase", ref.toString());
ref.child("from Android").push().setValue(ServerValue.TIMESTAMP);

And this runs without problems. The Log.i writes out:

I/firebase: https://realtime-database-in-brussels-default-rtdb.europe-west1.firebasedatabase.app

Which is indeed the correct URL for my database, and should be a URL pretty similar to yours.


I'm not sure why that doesn't work for you, but you can work around it by passing the correct URL into getInstance() explicitly. So:

mDatabase = FirebaseDatabase.getInstance("https://xxxxxxxx-xxxxxxx-default-rtdb.europe-west1.firebasedatabase.app/").getReference();

Upvotes: 2

Neo Wakeup
Neo Wakeup

Reputation: 363

I recently faced a similar issue, Firebase URL is null even after updating google_services.json, I got it working by deleting the build folder of my app and rebuilding the project again

Upvotes: 5

Related Questions