0
votes

I tried to set up a Firebase app in Android in kotlin , I have done this before and everything worked correctly before. This time though the problem was that i downloaded the google_services.json before creating a database.

After downloading the services.json file i created a realtime database and re downloaded the google_services.json file. But i cannot write to the database now

i tried to write this code

println(FirebaseApp.getInstance().options.toString())

the output of which is as follows

I/System.out: FirebaseOptions{applicationId=1:1015286121155:android:1cced0097502849b051876, apiKey=AIzaSyDznjwsm1NGIn0bIcZewDm0Addqu_QDK4I, databaseUrl=null, gcmSenderId=1015286121155, storageBucket=standup-slack.appspot.com, projectId=standup-slack}

Also tried to do the following,

database.getReference("test").child("askljalsd").setValue("Hello, World!").addOnCompleteListener {
            when{
                it.isCanceled-> println("it is isCanceled ")
                it.isSuccessful-> println("it is isSuccessful")
                it.isComplete-> println("it is isComplete")
            }
        }

None of the cases run when the above code is executed.

I am unable to debug why my firebase database url is null even when i have updated the google_services.json file

1
Did you modify the read/write rules? - Sam Chen
The Rules of the database are in test mode, i.e., { "rules": { ".read": "now < 1611945000000", // 2021-1-30 ".write": "now < 1611945000000", // 2021-1-30 } } - Neo Wakeup
Well, follow the official tutorial to see which step you missed: youtube.com/watch?v=lpFDFK44pX8. - Sam Chen
Are you sure you added the updated google-services.json file correctly to the app? The debug output you're showing seems to indicate otherwise, as it shows that databaseUrl is still null which shouldn't be the case for google-services.json that was downloaded after creating the database in the Firebase console.. - Frank van Puffelen
i am sure i added the correct google-services.json because when i open it in the editor i can see a key with databse_url in it and it points to the correct path - Neo Wakeup

1 Answers

2
votes

In the Android Studio Project, Deleting the app > build folder and clearing the gradle cache made it recognize the new google_services.json