Firebase database permission denied with read and write permissions set to true

I'm having trouble writing to the Firebase database in my simple Android application. I set my database rules to be public:

{ "rules": { ".read": true, ".write": true } } 

Created a simple Message class:

 import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; public class Message { FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference dbRef = database.getReference(); public String sender; public String message; public Message(){} public Message(String sender, String message) { this.sender = sender; this.message = message; } } 

And set the button to execute the onClick writeNewMessage method, since they are important lines of code:

 int counter = 0; public void writeNewMessage(View view) { counter += 1; Message messageToWrite = new Message("John", "Simple message: " + counter); String messageId = String.valueOf(counter); dbRef.child("users").child(messageId).setValue(messageToWrite); } 

When I start, I get an error message:

 W/RepoOperation: setValue at /users/1 failed: DatabaseError: Permission denied 

I know this question seems simple and probably repeated, but I have yet to find any question that poses this problem, preventing their error from being included in authentication or some other component. The simplicity of the problem is what confuses me more.

EDIT: I also found this error:

 Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" 
+5
source share
4 answers

This seems like a problem with your google-services.json.

Make sure the application name and client ID are the same as in the firebase console.

If you are not sure, re-download google-services.json from the project console and add it to your project.

+14
source

Complete solution 1). First go to the "Authentication" tab and select SIGN-IN-METHOD . 2). Then go to the Database tab and write Rule { "rules": { ".read": true, ".write": true }} 3). Thirdly, go to the "Storage" tab and write the following rule

 service firebase.storage { match /b/myapplicationname-f2266.appspot.com/o { match /{allPaths=**} { allow read, write; }}} 

Note This solution is for testing only, with the subsequent steps that you grant public permission to read and write your database.

+11
source

I'm not quite sure what the problem is, but I just deleted my project from Firebase and recreated it by uninstalling and installing the new google-services.json, and it worked fine the second time.

Fortunately, this is a test application and my database is empty, but if you are in this situation and have valuable information stored in your account, I would recommend exporting it before trying this solution.

+3
source

Internet permission

add internet permission to AndroidManifest.xml

 <uses-permission android:name="android.permission.INTERNET"/> 
-7
source

All Articles