首页 > 解决方案 > Flutter Firebase,无法连接到 Firestore,App 崩溃

问题描述

我刚刚重构了我的项目以使用最新的FlutterFiresdk > 0.14.1,突然在以前工作的项目中,我得到了这些日志

[OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore( 4617):
W/Firestore( 4617): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

我可以验证我的设备是否具有非常稳定的 Internet 连接。

在几次热重启后,应用程序因这些日志而崩溃

Failed to open database '/data/user/0/in.topbrain.quizzie/databases/firestore.%5BDEFAULT%5D.proto-3b7e0.%28default%29'.
E/SQLiteDatabase( 5755): android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY[5]): , while compiling: PRAGMA journal_mode

FATAL EXCEPTION: main
E/AndroidRuntime( 4617): Process: in.topbrain.quizzie, PID: 4617
E/AndroidRuntime( 4617): java.lang.RuntimeException: Internal error in Cloud Firestore (21.4.3)

Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Failed to gain exclusive lock to the Cloud Firestore clients offline persistence. 
This generally means you are using Cloud Firestore from multiple processes in your app. 
Keep in mind that multi-process Android apps execute the code in your Application class in all processes, so you may need to avoid initializing Cloud Firestore in your Application class.
 If you are intentionally using Cloud Firestore from multiple processes, you can only enable offline persistence (that is, call setPersistenceEnabled(true)) in one of them.

我还可以确认 myfirestore是公开的并且没有被firestore rules.

标签: firebasefluttergoogle-cloud-firestoreflutter-dependencies

解决方案


事实证明,这是因为网络。我连接到中继器而不是路由器,尽管它们在技术上是相同的网络。此重构版本不起作用。该应用程序的所有其他版本都在工作,这确实是一种特殊的行为,但是,一旦我连接到主路由器,我的应用程序就可以正常工作。当应用程序处于调试状态时,也许我的路由器不允许网络上的流量?没有把握。

如果网络专家可以解释这一点,那就太好了。


推荐阅读