我的应用程序已经发布 2 年了,我就是无法理解这个错误消息 我很少收到此错误消息,但从发布第一天起就一直稳定地出现。
它说“内部错误”,所以我什至不知道我是否能够用它做任何事情,或者这是一个 Firebase 错误。
我像这样使用 Firebase:
implementation platform('com.google.firebase:firebase-bom:32.7.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-appcheck-playintegrity'
implementation 'com.google.firebase:firebase-appcheck-debug'
Fatal Exception: java.lang.RuntimeException: Internal error in Cloud Firestore (24.10.0).
at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(AsyncQueue.java:545)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by java.lang.RuntimeException: android.database.CursorWindowAllocationException: Cursor window allocation of 2097152 bytes failed.
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:333)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:235)
at java.lang.Thread.run(Thread.java:784)
Caused by android.database.CursorWindowAllocationException: Cursor window allocation of 2097152 bytes failed.
at android.database.CursorWindow.<init>(CursorWindow.java:136)
at android.database.CursorWindow.<init>(CursorWindow.java:114)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:137)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:269)
at com.google.firebase.firestore.local.SQLitePersistence$Query.forEach(SQLitePersistence.java:493)
at com.google.firebase.firestore.local.SQLiteRemoteDocumentCache.getAll(SQLiteRemoteDocumentCache.java:143)
at com.google.firebase.firestore.local.LocalStore.lambda$writeLocally$2(LocalStore.java:248)
at com.google.firebase.firestore.local.SQLitePersistence.runTransaction(SQLitePersistence.java:228)
at com.google.firebase.firestore.local.LocalStore.writeLocally(LocalStore.java:240)
at com.google.firebase.firestore.core.SyncEngine.writeMutations(SyncEngine.java:286)
at com.google.firebase.firestore.core.FirestoreClient.lambda$write$12(FirestoreClient.java:233)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(AsyncQueue.java:444)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:330)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:235)
at java.lang.Thread.run(Thread.java:784)
错误“2097152 字节的游标窗口分配失败”表示 Firestore 的内部 SQLite 操作正在尝试分配较大的游标窗口,但由于内存限制而失败。出现此问题的原因是 Firestore 在底层使用 SQLite 在本地存储和管理数据(缓存)。
崩溃可能是由于:
大型查询结果:单个 Firestore 查询获取大型数据集。 内存使用限制:设备耗尽了用于此操作的可用内存。 Firestore 内部错误:Firestore 处理 SQLite 数据库中的本地数据的方式可能效率低下。
建议的解决方案: 优化查询: 确保 Firestore 查询得到充分优化,以限制获取的数据量。 对大型数据集使用分页:
FirebaseFirestore.getInstance().collection("yourCollection")
.orderBy("field")
.limit(50) // Fetch data in batches
.get()
禁用本地持久性(如果可行): 如果本地持久性对于您的应用程序并不重要,请考虑禁用它。这完全避免了 SQLite 操作:
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.build();
FirebaseFirestore.getInstance().setFirestoreSettings(settings);
这被视为一般准则,如果有其他信息,请向我们提供