1

When I try and sign-up in my app, the progress bar just runs endlessly because my app isn't able access the database. I've tried a few solutions on getting an updated googles-services.json file and changing the URL in my code but nothing seems to work.

The error that comes up:

W/PersistentConnection: pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL


        progressBar.setVisibility(View.VISIBLE);
        mAuth.createUserWithEmailAndPassword(email,mobile)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        if(task.isSuccessful()){
                            RegData user = new RegData(name, email, mobile);

                            FirebaseDatabase.getInstance("https://bioapps-customer-services-default-rtdb.asia-southeast1.firebasedatabase.app/");
                            FirebaseDatabase.getInstance().getReference().child("RegData")
                                    .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                    .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {

                                    if(task.isSuccessful()){
                                        Toast.makeText(SignUpActivity.this, "Registration Successful",Toast.LENGTH_LONG).show();
                                        progressBar.setVisibility(View.GONE);
                                    }else{
                                        Toast.makeText(SignUpActivity.this, "Registration Failed, Please Try Again",Toast.LENGTH_LONG).show();
                                        progressBar.setVisibility(View.GONE);
                                    }
                                }
                            });
                        }else{
                            Toast.makeText(SignUpActivity.this, "Registration Failed, Please Try Again",Toast.LENGTH_LONG).show();
                            progressBar.setVisibility(View.GONE);
                        }

                    }
                });
    }
}

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
nano_9
  • 13
  • 5

3 Answers3

1

Want to add to @Frank's answer.


Even after downloading an updated google-services.json file, or changing the url manually, it might not work.

In that case, we'll have to delete the build and .dart_tool folders in our project folder, and recompile the app again after stopping.

Because even after changing the google-services.json file, the changes don't take place (like it happened in my case.).

Madhav Kumar
  • 856
  • 8
  • 19
0

You need to pass the URL every time you call FirebaseDatabase.getInstance(), not just the first one.

So:

FirebaseDatabase db = FirebaseDatabase.getInstance("https://bioapps-customer-services-default-rtdb.asia-southeast1.firebasedatabase.app/");
db.getReference().child("RegData")

Alternatively, you can also download an up to date google-services.json and drop that into your app. If the correct URL is in there, the SDK will read it from there when you call FirebaseDatabase.getInstance() without arguments.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you very much good sir, worked perfectly, hope this helps anyone facing the same issue – nano_9 Sep 01 '21 at 06:19
0

After downloading the new google-services.json you need to run flutter clean hopefully it might works

mochadwi
  • 1,190
  • 9
  • 32
  • 87