Reputation: 98
I can't write to Firebase. I use exactly as in the tutorial but it's not working.
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
myRef.setValue("aaa");
...
Also I have changed the rules to:
{
"rules": {
".read": "true",
".write": "true"
}
}
Also my google-services.json is just downloaded from the project.
Upvotes: 1
Views: 4106
Reputation: 137
In my case, as of March 2021, it seems the problem was the classpath
of Gradle
dependency that caused the issue.
In Project-Level build.gradle
:
I have changed:
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath 'com.google.gms:google-services:4.3.5'
}
to:
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.google.gms:google-services:4.3.5'
}
Upvotes: 3
Reputation: 317
You need to specify the reference branch in the database.getReference() like:
database.getReference("reference name")
You can't set the main branch value, you can only add references to it.
Upvotes: 1