Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase/Android - Regularly losing database connection

I followed the docs for Firebase Auth and Database.

Everything works fine after a fresh install:

The user can register or log in, the data is retrieved like it should, written like it should, super fast, super clean. yay.

And then, after a few restarts via android Studio, the database stuff does not work anymore. The amount of restarts varies, I could not find a rule or such. If I uninstall and reinstall the apk (still via Android Studio) it works again.

I'm monitoring the auth state, the user stays logged in, there are also no firebase error at all.

I get a ton of E/DynamiteModule: Failed to load module descriptor class: but apparently this is not an error (just mentioning it because I get 20+ consecutive lines of that "error".

Any idea where I should start looking?

app.gradle

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        ...
        minSdkVersion 15
        targetSdkVersion 23
        ...
    }
    ...
}
...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.firebase:firebase-core:9.0.1'
    compile 'com.google.firebase:firebase-database:9.0.1'
    compile 'com.google.firebase:firebase-storage:9.0.1'
    compile 'com.google.firebase:firebase-auth:9.0.1'
    compile 'com.google.firebase:firebase-messaging:9.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
    compile 'cn.pedant.sweetalert:library:1.3'
    testCompile 'junit:junit:4.12'
}

Firebase database rules

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}
like image 330
Barthy Avatar asked Oct 31 '22 02:10

Barthy


1 Answers

It sounds like you may be experiencing a known problem caused with auth token refresh failure discussed here. Try enabling debug level logging using FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG) and compare the output with the samples included in the discussion linked above. In particular, look for "Error fetching token: An internal error has occured. [ Internal error. ]". If you see that, follow the instructions provided here to fix your google-services.json file.

like image 69
Bob Snyder Avatar answered Nov 08 '22 04:11

Bob Snyder