Help! My app crashed when I write database.--net.sqlcipher.database.SQLiteException: database is locked: BEGIN EXCLUSIVE;


#1

My code have include a synchronization mechanism when it read/write database in multi-threaded environment.

gradle version:3.4
Android studio version:2.3

The key info of build.gradle file is as follows:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary ‘org.apache.http.legacy’

defaultConfig {
    //dex 65535
    multiDexEnabled true
}

The crash log is as follows:

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
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:818)
Caused by: net.sqlcipher.database.SQLiteException: database is locked: BEGIN EXCLUSIVE;
at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2265)
at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:706)
at net.sqlcipher.database.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:658)
at com.pos.xwpos.db.DBFactory.saveroleRightGroup(DBFactory.java:4959)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:133)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
… 3 more
net.sqlcipher.database.SQLiteException: database is locked: BEGIN EXCLUSIVE;
at net.sqlcipher.database.SQLiteDatabase.native_execSQL(Native Method)
at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2265)
at net.sqlcipher.database.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:706)
at net.sqlcipher.database.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:658)
at com.pos.xwpos.db.DBFactory.saveroleRightGroup(DBFactory.java:4959)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:133)
at com.pos.xwpos.task.GetMerrightsetsTask.doInBackground(GetMerrightsetsTask.java:36)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
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:818)


#2

Hello @majinliang

I believe I replied to your posting on GitHub as well. In case that was not you, I have a few follow up questions:

  • What are the specific devices you receive the error on?
  • Does the error occur immediately following opening the database with a key?
  • Are you able to reproduce the behavior easily outside of your application (i.e., the SQLCipher for Android test suite)?

#3

Hello @developernotes

  1. It’s only happened on Android 5.1.1 devices.
  2. No.
  3. No,the SQLCipher for Android test suite works well.

In addition,we do not close database everytime, because we found that open database cost too much time(about 900ms ),so we close database when exit my app.


#4

Hello @majinliang

Would you be interested in trying a beta build of SQLCipher for Android? If so, would you write us at support@zetetic.net? Thanks!


#5

Hello Nick Parker

I want to have a try to the new version of SQLCipher for Android 3.5.7
Where can I find the download link for android-database-sqlcipher:3.5.7@aar?
I didn’t find it at https://www.zetetic.net/sqlcipher/sqlcipher-for-android/

Thanks!


#6

Hi @majinliang

If you are using the community edition (AAR format), you will need to follow the instructions found here. You do not directly download the AAR package, your Gradle script will handle that once you have added the appropriate reference to your project.