Skip to content

Database SDK should warn when it builds databaseUrl from projectId #2337

Open
@samtstern

Description

@samtstern

[READ] Step 1: Are you in the right place?

Yep

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: all
  • Firebase Component: Database
  • Component version: 19.6.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

  1. Create a new project
  2. Add an Android app
  3. Download google-services.json
  4. Create the default RTDB instance on the project, choose Europe location

Because (3) precedes (4) the json file will not contain the firebase_url key and therefore the RTDB SDK will try and make up the database URL:

  public static FirebaseDatabase getInstance(@NonNull FirebaseApp app) {
    String databaseUrl = app.getOptions().getDatabaseUrl();
    if (databaseUrl == null) {
      if (app.getOptions().getProjectId() == null) {
        throw new DatabaseException(
            "Failed to get FirebaseDatabase instance: Can't determine Firebase Database URL. "
                + "Be sure to include a Project ID in your configuration.");
      }
      databaseUrl = "https://" + app.getOptions().getProjectId() + "-default-rtdb.firebaseio.com";
    }
    return getInstance(app, databaseUrl);
  }

However it doesn't print any warning when it does this, and for anyone who chooses Europe this is the wrong URL. See developer pain here:
firebase/codelab-friendlychat-android#137

Relevant Code:

See above

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions