2017-08-12 392 views
9

我越來越對少數設備此崩潰,但僅適用於Android 4火力地堡數據庫崩潰SQLiteDatabaseLockedException

我在火力地堡的Android SDK 10.2.1 11.0.2。推遲更新到最新版本,因爲它也會強制更新Google Play服務,並且許多用戶仍然保留舊版GPS版本。

是否有人看到這個問題?

更新:這是工作更早。崩潰開始,我從火力地堡SDK 9.4.0升級到10.2.1之後,並compileSdkVersion 23至25只崩潰發生在Android 4.4(奇巧19)

更新例外:

Fatal Exception: java.lang.RuntimeException 
     at com.google.android.gms.internal.mz.run(Unknown Source) 
     at android.os.Handler.handleCallback(Handler.java:808) 
     at android.os.Handler.dispatchMessage(Handler.java:103) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5292) 
     at java.lang.reflect.Method.invokeNative(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
     at dalvik.system.NativeStart.main(NativeStart.java) 
Caused by o.kD: Failed to gain exclusive lock to Firebase Database's offline persistence. This generally means you are using Firebase Database 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 FirebaseDatabase in your Application class. If you are intentionally using Firebase Database from multiple processes, you can only enable offline persistence (i.e. call setPersistenceEnabled(true)) in one of them. 
     at com.google.android.gms.internal.nb.zzN(Unknown Source) 
     at com.google.android.gms.internal.nb.(Unknown Source) 
     at com.google.android.gms.internal.mx.zza(Unknown Source) 
     at com.google.android.gms.internal.qd.zzgQ(Unknown Source) 
     at com.google.android.gms.internal.qu.zzHg(Unknown Source) 
     at com.google.android.gms.internal.qu.zza(Unknown Source) 
     at com.google.android.gms.internal.qv.run(Unknown Source) 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 
Caused by android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode 
     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java) 
     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893) 
     at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:638) 
     at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320) 
     at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294) 
     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215) 
     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193) 
     at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463) 
     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185) 
     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177) 
     at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:829) 
     at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:814) 
     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:709) 
     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1039) 
     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:256) 
     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224) 
     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) 
     at com.google.android.gms.internal.nb.zzN(Unknown Source) 
     at com.google.android.gms.internal.nb.(Unknown Source) 
     at com.google.android.gms.internal.mx.zza(Unknown Source) 
     at com.google.android.gms.internal.qd.zzgQ(Unknown Source) 
     at com.google.android.gms.internal.qu.zzHg(Unknown Source) 
     at com.google.android.gms.internal.qu.zza(Unknown Source) 
     at com.google.android.gms.internal.qv.run(Unknown Source) 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 

我做在應用程序中有多個進程,但使用以下代碼來中止子進程的Application.onCreate。

@Override 
public void onCreate() { 
    super.onCreate(); 

    if (FirebaseApp.getApps(this).isEmpty()) { 
     // No firebase apps; we are in a non-main process 
     return; 
    } 

    // Firebase init and other custom logic 
    FirebaseDatabase.getInstance().setPersistenceEnabled(true); 
} 
+0

啓用'multidex' –

+0

@IntelliJAmiya你能解釋一下爲什麼multidex是這裏的問題?這次崩潰對我來說是不可重複的,我唯一的選擇是在生產中進行測試。 –

回答

4

Firebase中沒有SQLiteDatabaseLockedException。當您在Android上使用SQLite數據庫並且數據庫引擎無法獲取需要完成其工作的數據庫鎖時,將引發此SQLiteDatabaseLockedException

如果語句是[COMMIT]或發生在顯式事務之外,那麼您可以重試該語句。如果語句不是[COMMIT]並且發生在顯式事務中,那麼在繼續之前應該回滾事務。

編輯:有了您的詳細堆棧跟蹤信息的新的編輯,我看到的是什麼錯誤。當您設置setPersistenceEnabled(true)時,發生錯誤。這個必須在你做任何其他的事情之前完成,你的firebaseDatabase對象。所以,我recomand您使用下面的代碼:

public class HelperClass { 
    private static FirebaseDatabase firebaseDatabase; 
    public static FirebaseDatabase getDatabase() { 
     if (firebaseDatabase == null) { 
      firebaseDatabase = FirebaseDatabase.getInstance(); 
      firebaseDatabase.setPersistenceEnabled(true); 
     } 
     return firebaseDatabase; 
    } 
} 
+0

該崩潰確實來自Firebase數據庫。得到了更詳細的堆棧跟蹤,在我的問題中更新。 –

+0

請看我更新的答案。 –

+0

現在我知道這是一個確認的Firebase數據庫問題,我有更多的線索。這是一段代碼,當我從Firebase SDK 9.4.0升級到10.2.1後,崩潰開始了。將Firebase升級到11.0.2後繼續崩潰。 Google Play服務現在也在11.0.2。 –