Skip to content

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

Closed
@praveenb

Description

@praveenb

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.

Activity

developernotes

developernotes commented on May 4, 2015

@developernotes
Member

Hello @praveenb

Are you able to replicate the crash on your 5.0 device when running the SQLCipher for Android test suite?

praveenb

praveenb commented on May 5, 2015

@praveenb
Author

@developernotes Thank you so much for your kind reply,
I run the test suite on Android 5.0 device, Though I see a crash at some other test condition, I do not see a crash resulting error log given above. i.e I'm not able to replicate above crash.

Not sure where im doing mistake in my code. I think i need to investigate further in test suite to handle the issue in my project.

But, I just like to ask,.. you have any other suggestions or guidelines for me on this.

Thank you.

developernotes

developernotes commented on May 5, 2015

@developernotes
Member

Hello @praveenb

Do you have a specific test case that is failing consistently in the test suite?

With regard to your specific scenario though, does the database file exist right before you initialize the DBHelperCipher instance?

praveenb

praveenb commented on May 8, 2015

@praveenb
Author

@developernotes,

there is no database file exist before initialize the class...
Just for clarification, I published app to Play Store, I see app crashes, When I do a fresh install from play store, on a android 5.0v device.

I debugged the android-database-sqlcipher project, by giving external path, as shown below
public EventDataSQLHelper(Context context, String name, CursorFactory factory, int version) {
super(context, DB_PATH+DATABASE_NAME, null, DATABASE_VERSION);
}
**here DB_PATH constant refers to external path.

And I see the issue is occurring only when created db file on external storage,
see the issue occurring at this line
setLocale(Locale.getDefault()); in SQLiteDatabase file

Please let me any idea on this.

Thankyou

developernotes

developernotes commented on May 8, 2015

@developernotes
Member

Hello @praveenb

I am wondering if there is an issue within the internals of getWritableDatabase(). As an experiment, could you try invoking SQLiteDatabase.openOrCreateDatabase(…); before you initialize your EventDataSQLHelper only when the database file does not exist before hand? Could you let us know your results? Thanks!

praveenb

praveenb commented on May 12, 2015

@praveenb
Author

Im getting the same error, invoking SQLiteDatabase.openOrCreateDatabase(…); method

Thanks

developernotes

developernotes commented on May 12, 2015

@developernotes
Member

Hello @praveenb

If you can prepare a test within the test suite, I would be glad to take a look at it on a Lollipop device.

praveenb

praveenb commented on May 13, 2015

@praveenb
Author

Hi @developernotes ,

Please see this link https://github.com/praveenb/sqlcipher-android-tests, I added test class to test suite. Please see committed code changes.

Hi Nick, You are able to see issue on your side. or You see any issue in committed changes. Please reply on this.

FYI, I see this issue on Lenovo A7000, Lollipop device. Please help on this.

Thank you.

chetan1011

chetan1011 commented on May 27, 2015

@chetan1011

Hi @developernotes ,

I am getting the same error,error code 8: attempt to write a read only database

When I am write(Insert) record in database at this time I am getting this error in my lolipop device.

please help me ...

FYI, I see this issue on Lenovo A7000-a, Lollipop device. Please help on this.

developernotes

developernotes commented on May 27, 2015

@developernotes
Member

Hello @chetan1011

Can you verify whether the database file exists before you attempt to write to it?

praveenb

praveenb commented on May 28, 2015

@praveenb
Author

Hi @developernotes ,

You are able to look at the test suit changes that i made at this link https://github.com/praveenb/sqlcipher-android-tests.

Please let me know if you need any other details

Thank you.

chetan1011

chetan1011 commented on May 28, 2015

@chetan1011

Hello @developernotes ,

The database file was store in sdcard(External_storage)...
and i take permission in android manifest "android.permission.WRITE_EXTERNAL_STORAGE"

developernotes

developernotes commented on May 28, 2015

@developernotes
Member

Hello @chetan1011

Can you verify whether the database file exists on the SD card prior to any attempts to interact with it via the SQLCipher API? Thanks!

BenPope

BenPope commented on May 28, 2015

@BenPope

I'm having a similar problem on Android 5.0.2 with native (c++) sqlcipher 3.3.0.

ls -al /storage/emulated/0/Android/data/com.app.name/files/data.db
-rw-rw---- u0_a165  sdcard_r    38912 2015-05-28 21:31 data.db

I get an exception "attempt to write a readonly database".

It's weird. The app manages to write the database on startup.

It also fails miserably if I try to put it into EXCLUSIVE locking mode, could it somehow be trying to lock the file more than once?

65 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @developernotes@sjlombardo@atultiwari@praveenb@linsmalldragon

        Issue actions

          attempt to write a readonly database, crashes on android 5.0v devices while using SqlCipher · Issue #161 · sqlcipher/android-database-sqlcipher