Firestore Database Continues to Fail

I successfully migrated my application from RealtimeDB to Firestore, but after reconfiguring the application too often with the following error, how to fix it ?. I have never encountered this error when using RealtimeDB

Fatal Exception: java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).

   at com.google.android.gms.internal.zzejs.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:751)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6184)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:788)`

Caused by java.lang.RuntimeException: Failed to gain exclusive lock to the Firestore client offline persistence. 
This generally means you are using 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 Firestore in your Application class. 
If you are intentionally using Firestore from multiple processes, 
you can only enable offline persistence (i.e. call setPersistenceEnabled(true)) in one of them.

  `at com.google.android.gms.internal.zzefi.start(Unknown Source)
   at com.google.android.gms.internal.zzeca.zza(Unknown Source)
   at com.google.android.gms.internal.zzecc.run(Unknown Source)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
   at com.google.android.gms.internal.zzejp$zza.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:761)`
+4
source share
4 answers

If you try to access db from multiple threads, this problem will occur. Therefore, if you use RX, you need to create one background thread for all inserts. This is because Firestore blocks the database during recording.

val FIRESTORE_OPERATION_THREAD = Schedulers.single()
yourSingle.subscribeOn(FIRESTORE_OPERATION_THREAD)
. ...
+1
source

@Sandip Soni , (, ) Firebase, , , . , Firestore , Firestore db . , :

class Firestore {
    companion object {
       val instance: FirebaseFirestore by lazy {
           return@lazy synchronized(Firestore::class){
               FirebaseFirestore.getInstance().apply { lock() }
           }
       }

       private fun FirebaseFirestore.lock() {
          collection("config").document("db").update("locked", true)
       }
    }
}
0

Firestore . Android Application .

, :

  1. Avoid initializing Firestore in your Application class or module for Rxjava. Instead, initialize a new Firestore instance before each call to the firestore database as follows:

    val fireStore = FirebaseFirestore.getInstance()
    val settings = FirebaseFirestoreSettings.Builder()
            //offline persistence is enabled automatically in Android
            .setTimestampsInSnapshotsEnabled(true)
            .build()
    fireStore.firestoreSettings = settings
    //go ahead and call database using the Firestore instance
    

    This means that you will not use the same Firestore instance for multiple calls.

  2. Then clear the application cache .

0
source

Just clear Application cachethe settings. It works for me!

-2
source

Source: https://habr.com/ru/post/1688531/


All Articles