我目前正在使用 Android Studio 3 (Canary) 在 Kotlin 中构建原生 Android 应用。我也在使用 Firebase 实时数据库和 Firebase Auth。这是我的 gradle 依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.firebase:firebase-auth:11.0.4'
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.2'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.firebaseui:firebase-ui-database:2.0.1'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
一切正常,直到与我的 Firebase 数据库的通信停止完成。我没有收到任何错误,但我注册的所有听众都不再被触发。例如:
val ref = FirebaseDatabase.getInstance().reference.child("message")
ref.setValue("Test", object: DatabaseReference.CompletionListener {
override fun onComplete(p0: DatabaseError?, p1: DatabaseReference?) {
println("IT WORKED!")
}
})
永远不会到达println
语句。
这是一些 Logger 输出,我认为它是相关的。在我看来,所有 WebSocket 连接尝试都超时,因此会重试。此输出一遍又一遍地重复:
08-05 15:11:25.899 10820-10909/... D/Connection: conn_12 - Opening a connection
08-05 15:11:55.899 10820-10909/... D/WebSocket: ws_12 - timed out on connect
08-05 15:11:55.899 10820-10909/... D/WebSocket: ws_12 - closed
08-05 15:11:55.899 10820-10909/... D/WebSocket: ws_12 - closing itself
08-05 15:11:55.899 10820-10909/... D/Connection: conn_12 - Realtime connection failed
08-05 15:11:55.899 10820-10909/... D/Connection: conn_12 - closing realtime connection
08-05 15:11:55.899 10820-10909/... D/PersistentConnection: pc_0 - Got on disconnect due to OTHER
08-05 15:11:55.899 10820-10909/... D/PersistentConnection: pc_0 - Scheduling connection attempt
08-05 15:11:55.899 10820-10909/... D/ConnectionRetryHelper: Scheduling retry in 9844ms
08-05 15:12:05.739 10820-10909/... D/PersistentConnection: pc_0 - Trying to fetch auth token
08-05 15:12:05.739 10820-10909/... D/PersistentConnection: pc_0 - Successfully fetched token, opening
connection
08-05 15:12:05.739 10820-10909/... D/Connection: conn_13 - Opening a connection
但如果我是对的,是什么导致了这个问题?我没有发现任何类似的问题谷歌搜索。
我在物理设备和模拟器中都运行了代码。我有一个网络客户端连接到同一个数据库,但它仍在工作,所以我想这不是服务器端问题。
最糟糕的是,我将我的项目重置为它曾经可以工作的点,但这没有帮助。
我知道这不是很多信息,但我不知道如何进一步分析问题。
最佳答案
这是一个已知问题。 Firebase 客户端尝试使用多种方法与 Firebase 服务器建立实时连接。如果其中一个方法在 Websocket 之前成功,我们将取消 Websocket,您会看到该警告。您可以安全地忽略该错误。
关于android - Android 上的 Firebase 请求永远不会完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45522684/