0

I've been trying to integrate my Android app with Firebase. In my first Firebase app (test-26ee4), I had set up the app incorrectly because I was denied permission...

After reading this (Firebase Database Permission denied with read/write permissions set to true), I deleted (test-26ee4) and created a new Firebase app (awesome-etc). However, I noticed that I was getting the same errors.

After placing a log inside MainActivity.java,

mDatabase = FirebaseDatabase.getInstance().getReference();
Log.d("testing", mDatabase.child("1").toString());

I found that the reference is still pointing to my OLD firebase app.

10-16 12:00:06.882 14428-14428/com.example.twu.line D/testing: https://test-26ee4.firebaseio.com/1

The google-services.json reflects that the url should be awesome-etc, but I don't know why my Android app is reading from the google-services.json incorrectly.

Community
  • 1
  • 1
theowu
  • 3
  • 1
  • 2

1 Answers1

1

Have you read what's within Google Services json? It specifies the android project's package name.

    {
  "project_info": {
    "project_number": "xxxxx",
    "firebase_url": "https://xx-zzzzz.firebaseio.com",
    "project_id": "nxjwjx-7f23b",
    "storage_bucket": "dkwncn-7f23b.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1jjsjwkd:xjdjejfb:sjwjsj",
        "android_client_info": {
          "package_name": "com.xxxxx.schwjxns"
        }
      },
      "oauth_client": [
        {
          "client_id": "xxxxxx.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.nixho.scheduled",
            "certificate_hash": "xxxx"
          }
        },
        {
          "client_id": "zxxxent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.blah",
            "certificate_hash": "xxxxx"
          }
        },
        {
          "client_id": "xxxx.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "xxxx"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 2,
          "other_platform_oauth_client": [
            {
              "client_id": "xxxx.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

I recommend replacing the json because it's specific to each project you create else you won't be able to have firebase working properly

EDIT

**public static DatabaseReference rootRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://myapp.firebaseio.com/"); // We'll have to utilize the new Firebase 3.0 APIs **

That's important

Nicholas
  • 1,883
  • 21
  • 39
  • Hey Nicolas, when I created a new Firebase app (awesome-etc), I removed the old google-services.json completely and added a new google-services.json into the app/ directory – theowu Oct 17 '16 at 03:52
  • Simply follow the new content I've added! Let me know if there's any problems again – Nicholas Oct 17 '16 at 03:56
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.twu.line/com.example.twu.line.MainActivity}: com.google.firebase.database.DatabaseException: Invalid URL (https://awesome-etc.firebaseio.com/) passed to getReference(). URL was expected to match configured Database URL: https://test-26ee4.firebaseio.com – theowu Oct 17 '16 at 04:26
  • Interesting... I feel like we are getting closer to the issue. – theowu Oct 17 '16 at 04:27
  • hace you added the correct packages on the gradle file – Nicholas Oct 17 '16 at 05:25
  • yep compile 'com.google.firebase:firebase-core:9.0.2' compile 'com.google.firebase:firebase-database:9.0.2' – theowu Oct 17 '16 at 07:48
  • Look for your old url in your project and replace it with the new one. – Nicholas Oct 17 '16 at 07:50
  • Ugh so I figured out that after deleting a module and resyncing, it worked fine... -___- sorry for all the trouble. – theowu Oct 17 '16 at 08:16
  • It's okay! At least you asked – Nicholas Oct 17 '16 at 10:16