sqlcipher / android-database-sqlcipher

Android SQLite API based on SQLCipher
https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Other
2.76k stars 567 forks source link

attempt to write a readonly database, crashes on android 5.0v devices while using SqlCipher #161

Closed praveenb closed 7 years ago

praveenb commented 9 years ago

Im getting following log on app crash, on android 5.0v devices

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.(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.(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)

I've submitted a question on StackOverflow, http://stackoverflow.com/q/29988933/341443. Can you please help on this.

Thank you.

developernotes commented 8 years ago

Hi @atultiwari, @YuriZheng,

We will look into making the adjustment to the NDK API 21 within the android-n-preview soon.

developernotes commented 8 years ago

Hi @atultiwari, @YuriZheng,

We have made some changes in the android-n-preview branch which include adjusting the target platform used within the Android NDK. Please feel free to try the android-n-preview to see if it addresses the issue you are seeing. Thanks!

atultiwari commented 8 years ago

@developernotes thank you for your reply. I will try it in the evening and get back to you. It's 2 a.m. here, feeling very sleepy. But, on a quick look. I am unable to figure out how to use android-n-preview? I mean previously I was using aar in Android studio, like - compile 'net.zetetic:android-database-sqlcipher:3.4.0@aar'

But it seems, for android-n-preview I might have to compile sqlcipher myself, about which I have no idea.

developernotes commented 8 years ago

Hello @atultiwari,

Yes, the android-n-preview branch is distributed in source only format. If you are interested in a zip build please feel free to email us at support@zetetic.net with your Discuss account.

YuriZheng commented 8 years ago

Hello @developernotes : I download the source and build it myself. But it has this issue, I'm a java developer, so i'm poor of c and c++. If you solved this probrem, please let me know! I'm very worried. Thank you very much !!!

idumesh commented 8 years ago

@developernotes I too am facing this issue only on 5.0 devices.

05-24 15:46:30.494: I/Database(11744): sqlite returned: error code = 28, msg = file renamed while open: /storage/sdcard0/dummy1/db 05-24 15:46:30.503: I/Database(11744): sqlite returned: error code = 1032, msg = statement aborts at 8: [CREATE TABLE IF NOT EXISTS dummy_table1 ..... 05-24 15:46:30.503: E/Database(11744): Failure 8 (attempt to write a readonly database) on 0xabb15250 when executing 'CREATE TABLE IF NOT EXISTS dummy_table2(rowid integer default -1, did integer

developernotes commented 8 years ago

Hello @YuriZheng

If you are interested in our android-n-preview branch, we have instructions available here for accessing it.

heutschibogdan commented 7 years ago

Hi @developernotes ,

I am facing this problem using the latest version 3.5.4 on a sony device with android 5.0. net.sqlcipher.database.SQLiteException: error code 8: attempt to write a readonly database. Do you have any suggestions what I could try?

developernotes commented 7 years ago

Hi @heutschibogdan

Are you able to create a small reproducible test case within the SQLCipher for Android test suite? If so, we would be happy to look into that further. Thanks!

heutschibogdan commented 7 years ago

Hi @developernotes

I've added a test case for this. It seems the problem is not really related to the sony device, as I've reproduced it on multiple android versions which have x86_64 system image. It seems there is a problem when using an external storage in this cases.

gautamshrm3 commented 7 years ago

Hi Team,

We are facing the below issue may be the similar as previous

net.sqlcipher.database.SQLiteException: error code 8: attempt to write a readonly database

This issue we have only got in MI devices.

Please us ASAP.

umesh0492 commented 7 years ago

Hi Team,

We are facing the below issue may be the similar as previous

net.sqlcipher.database.SQLiteException: error code 8: attempt to write a readonly database

Happens when app having multiple processes.

sjlombardo commented 7 years ago

@umesh0492 are you saying that the application works if there is only a single process, but fails when there are multiple processes, even if the database location is the same?

ArikYa commented 7 years ago

I'm having the same issue, also seems to be related to multi-processes application. Any update on this?

developernotes commented 7 years ago

Hi @ArikYa

What version of SQLCipher for Android are you currently using?

ArikYa commented 7 years ago

I use it through Requery, which uses 3.5.4

developernotes commented 7 years ago

Hello @ArikYa

Please try the latest version of SQLCipher for Android, which is 3.5.7 and let us know your results. Thanks!

dotw commented 6 years ago

Hello guys, I'm facing the same issue. I'm using the latest version 3.5.7 now.

11-20 17:48:54.719 12073-12218/com.hzqi.sango W/System.err: net.sqlcipher.database.SQLiteException: error code 8: attempt to write a readonly database
11-20 17:48:54.719 12073-12218/com.hzqi.sango W/System.err:     at net.sqlcipher.database.SQLiteStatement.native_execute(Native Method)
11-20 17:48:54.719 12073-12218/com.hzqi.sango W/System.err:     at net.sqlcipher.database.SQLiteStatement.execute(SQLiteStatement.java:58)
11-20 17:48:54.719 12073-12218/com.hzqi.sango W/System.err:     at net.sqlcipher.database.SQLiteDatabase.execSQL(SQLiteDatabase.java:2319)
dotw commented 6 years ago

Struggling several hours then I found the issue is the database path. I changed the path from context.getApplicationInfo().dataDir + "/databases/" + DATABASE_NAME to context.getDatabasePath(DATABASE_NAME).getPath() then, the exception is gone.

developernotes commented 6 years ago

Hi @dotw

We are glad to hear you were able to resolve the issue. Thanks!