2

In my app, I'm using SqlCipher for Android downloaded from this link. and its working fine on devices with android version upto 4.4v. But app crashing on android 5.0v devices. Following is code snippet

public DBHelperCipher(Context context) {
    super(context, DB_PATH, null, DB_VERSION);
    db = getWritableDatabase("password");// crash occurs at this line
}

Im calling this DbHelperCipher class as shown below

public class ProcessDBCipherInitTask extends AsyncTask <Void, Void, Boolean>{

    private Context ctx;
    public ProcessDBCipherInitTask(Context ctx){
        this.ctx=ctx;
    }

    @Override
    protected Boolean doInBackground(Void... arg0) {
        SQLiteDatabase.loadLibs(ctx);
        dbHelper = new DBHelperCipher(ctx);
        return true;
    }
}

and crash log is

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
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 android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
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: attempt to write a readonly database
at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2096)
at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1962)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:881)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:913)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:99)
at PackageName.DBHelperCipher.<init>(DBHelperCipher.java:93)
at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:20)
at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
net.sqlcipher.database.SQLiteException: attempt to write a readonly database
at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
at net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2096)
at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1962)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:881)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:913)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:99)
at PackageName.DBHelperCipher.<init>(DBHelperCipher.java:93)
at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:20)
at PackageName.ProcessDBCipherInitTask.doInBackground(ProcessDBCipherInitTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
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)

I added jar files in project shown in below image

enter image description here

I searched for a solution for it but not able to find a working solution. Someone please help on this.

Thank you.

praveenb
  • 10,549
  • 14
  • 61
  • 83
  • 1
    Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare May 01 '15 at 14:40
  • Try uninstalling and reinstalling your app, or use the "Clear Data" button on your app's page in Settings. It feels like file permissions got messed up or something, and SQLCipher cannot get write access to your database file. – CommonsWare May 01 '15 at 18:06
  • @CommonsWare, please see this thread https://github.com/sqlcipher/android-database-sqlcipher/issues/161 – praveenb May 08 '15 at 13:28

1 Answers1

0

I know i'm responding to a thread created 6 years ago, but maybe it can helpful to somebody: I had the same error about a month ago, and in my case the problem was that the file didn't exists.

I was deleting it by mistake, I removed the deletion and everything worked fine! it's interesting to say that i had the same error

SQLiteException: attempt to write a readonly database

while the real problem was that the file was not there.

So.. be sure you don't do any delete operation in your code, and the database file is really there!