0

I'm using the standard way to connect to firebase realtime database, using 16.1.0 version of the SDK.

Problem:

The connection is setup perfectly fine for devices below Android 9, but for devices running android 9 on mobile network, the firebase connection fails.

It appears to be a WebSocketException while connecting to the firebase backend, and followed by an SSL handshake exception, logs:

D/WebSocket: ws_16 - WebSocket error. com.google.firebase.database.tubesock.WebSocketException: error while creating secure socket to ...

and:

Caused by: java.net.ConnectException: failed to connect to s-usc1c-nss-243.firebaseio.com/ (port 443) from /:: (port 42580): connect failed: ETIMEDOUT (Connection timed out)

verbose logs:

D/PersistentConnection: pc_0 - Trying to fetch auth token D/PersistentConnection: pc_0 - Successfully fetched token, opening connection D/Connection: conn_19 - Opening a connection D/WebSocket: ws_19 - timed out on connect D/WebSocket: ws_19 - closed D/WebSocket: ws_19 - closing itself D/Connection: conn_19 - Realtime connection failed D/Connection: conn_19 - closing realtime connection D/PersistentConnection: pc_0 - Got on disconnect due to OTHER D/PersistentConnection: pc_0 - Scheduling connection attempt D/ConnectionRetryHelper: Scheduling retry in 2357ms D/WebSocket: ws_19 - WebSocket error.

The SSL certificate behaviour was changed for Android 9, link, hence i believe it could be an issue which firebase can be resolved from the firebase's end, but not sure.

GitHub issue for the same, link

Is anyone else facing this issue? Is there a possible hack to this?

PS: The thing works perfectly fine when switched to WiFi, it simply fails at the connection level for P.

Edit 1:

app build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'

// other standard default config code
dependencies{
    implementation deps.firebase.core
    implementation deps.firebase.auth
    implementation deps.firebase.config
    implementation deps.firebase.firestore
    implementation deps.firebase.performance
    implementation deps.firebase.messaging
    implementation deps.firebase.database
}
apply plugin: 'com.google.gms.google-services'

Root build.gradle:

buildscript {
    ext.kotlin_version = '1.3.21'
    ext.realm_version = '5.8.0'
    ext.versions = [
   'firebaseCore'           : '16.0.8',
            'firebaseAuth'           : '16.2.0',
            'firebaseConfig'         : '16.4.0',
            'firebasePerf'           : '16.2.4',
            'firestore'              : '18.1.0',
            'firebaseMessaging'      : '17.4.0',
            'firebaseDatabase'       : '16.1.0',
          ]

    ext.deps = [
    'firebase'               : [
                    'core'       : "com.google.firebase:firebase-core:${versions.firebaseCore}",
                    'auth'       : "com.google.firebase:firebase-auth:${versions.firebaseAuth}",
                    'config'     : "com.google.firebase:firebase-config:${versions.firebaseConfig}",
                    'firestore'  : "com.google.firebase:firebase-firestore:${versions.firestore}",
                    'performance': "com.google.firebase:firebase-perf:${versions.firebasePerf}",
                    'messaging'  : "com.google.firebase:firebase-messaging:${versions.firebaseMessaging}",
                    'database'   : "com.google.firebase:firebase-database:${versions.firebaseDatabase}",
            ]
        ]
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "http://storage.googleapis.com/r8-releases/raw" }
        maven { url "https://jitpack.io" }
        maven { url "https://kotlin.bintray.com/kotlinx/" }
    }
    dependencies {
        // r8 tools deps is for CT.
        classpath 'com.android.tools:r8:1.3.52'
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:$realm_version"
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.27.1'
        classpath 'com.google.android.gms:oss-licenses-plugin:0.9.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com/' }
        maven { url "https://jitpack.io" }
    }
}

MadScientist
  • 2,134
  • 14
  • 27

0 Answers0