16

I am trying to build a simple login user authentication Android application that uses Firebases Realtime Database but I am getting the error:

[Firebase Database connection was forcefully killed by the server. Will not attempt to reconnect. Reason: The database lives in a different region. Please change your database URL to https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app]

I am currently using the Singapore(asia-southeast1) server since I live in the Philippines. Is this wrong? or Should I be using the US one? How do I change my Database URL?

Richard Wilson
  • 297
  • 4
  • 17
Alfonso Lima
  • 165
  • 1
  • 1
  • 6

9 Answers9

64

It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created. In such cases the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.

There are two possible solutions:

  1. Download an updated google-services.json from the Firebase console, and add that to your Android app.
  2. Specify the database URL in your code instead, like this: FirebaseDatabase.getInstance("https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app")...

Both have the same result, so pick whichever one seems easiest to you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
14

It cat still not work after the accepted answer (as in my case). If so, try:

  • Clean Project
  • Rebuild Project
  • Invalidate Caches & Restarte

and run it again.

2

If you are a New Flutter User who followed the new firebase doc, run this command in the terminal. It will automatically update the firebase_options.dart file.

flutterfire configure
0

I faced the same problem and that's because when you set up the app, the google-service.json doesn't contain the firebase_url.

These problems faced you when configuring your set up manually, You can fix all that problems by using flutterfire, it will help you a lot and set up your app in a few steps. see docs firebase

0

It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created. In such cases, the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.

You can fix it either way.

  1. After configuring the database service setup you have to download the new "GoogleService-Info.plist" file and replace the previous one.

or

  1. You can manually set the key in your "GoogleService-Info.plist" file

<key>DATABASE_URL</key> <string>https://<app-instance-default-rtdb>.asia-southeast1.firebasedatabase.app</string> '

enter image description here

aksBD
  • 189
  • 1
  • 6
0

I got the same error and when exploring why this is happening,

The issue is: I don't create a real-time database in Firebase Console and did not initialize the rules of the database.

So, I initialize it and throw the error out.

57 Abbas
  • 39
  • 2
  • I also ran into this problem, The solution work for me is Firstly to enable REAL-TIME DATABASE IN your FIREBASE and then Again Download GOOGLE SERVICE JSON File. – INDIAN GAMER Apr 26 '23 at 10:05
0

Your Singapore(asia-southeast1) server is correct.

Maybe you have downloaded the google-services.json before creating the database.

  1. You could either re-download the json & replace your existing one with it.

or

  1. Update the existing json as follows.

    "project_info": {
      "project_number": "123456789",
      "firebase_url": "https://<somename>firebasedatabase.app",
      "project_id": "---",
      "storage_bucket": "---"
    },
    

Then clean and rebuild the project.

Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45
0

Use FirebaseDatabase.instanceFor() as below, which works.

 DatabaseReference ref = FirebaseDatabase.instanceFor(
          app: Firebase.app(),
          databaseURL:
              'https://kunukk-906b2-default-rtdb.asia-southeast1.firebasedatabase.app')
      .ref("users/123");
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
MattPrash
  • 67
  • 5
-1

Add inside () Url your database:

val ref = FirebaseDatabase.getInstance("YOUR LINK")
General Grievance
  • 4,555
  • 31
  • 31
  • 45
WojtRR
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '23 at 06:31