
Firstly, I double-checked that said database was actually 'corrupt': sudo sqlite3 path/to/database.sqlite 'PRAGMA integrity_check' The above error popping up randomly was annoying though, so I resolved to do something about it. Upon double-checking, it looked like the database was functioning (mostly) fine. This was a measure that did not affect the performance of the application, but that should be analyzed for each case.Recently I came across a rather worrying SQLite database error: Error: database disk image is malformed There was thus a strong reduction in the occurrences of the problem, however there were still occurrences.įinally, database access methods were synchronized to avoid concurrent access to SqliteOpenHelper. The solution was a general refactoring in persistence with the goal of only having SqliteOpenHelper for each database (in this case there were three). In the case of the application in question, there were multiple SqliteOpenHelper and multiple Threads.

This ensures that there are no collisions, concurrent access, to the database file. Even though the getWritableDatabase and getReadableDatabase methods make it appear that there are two different connections, it just does not happen: it's the same connection. A SqliteOpenHelper has only one connection. Īfter some research and testing I have seen the following points:įor each database, only one SqliteOpenHelper should exist.Īs it may seem, there are no multiple connections to the database. That here was linked to access by multiple Threads to SQLite. This led me to conclude that the problem was competition. I also saw that this error occurred in particular with newer devices that have more processing cores and higher clock and that in older devices less powerful and especially with only one core this error occurred very little or simply did not occur. I observed that this problem also existed from a certain period until then. During the investigation of the problem, it was clear that the error was due to some corruption in the SQLite file.
#Database disk image is malformed sqlite android code
This procedure is done on thousands of devices, mostly everything is fine, but it has started to become a frequent case.ĮRROR: : Unable to start activity ComponentInfo: : error code 11: database disk image is malformedĪt (ActivityThread.java:1970)Īt (ActivityThread.java:1995)Īt $600(ActivityThread.java:128)Īt $H.handleMessage(ActivityThread.java:1161)Īt android.os.Handler.dispatchMessage(Handler.java:99)Īt android.os.Looper.loop(Looper.java:137)Īt (ActivityThread.java:4514)Īt .invokeNative(Native Method)Īt .invoke(Method.java:511)Īt .ZygoteInit$n(ZygoteInit.java:790)Īt .ZygoteInit.main(ZygoteInit.java:557)Īt (Native Method)Ĭaused by: : error code 11: database disk image is malformedĪt .native_1x1_long(Native Method)Īt .simpleQueryForLong(SQLiteStatement.java:138)Īt (DatabaseUtils.java:791)Īt (DatabaseUtils.java:779)Īt br.reloadQuantidadeTotal(MensagemDAO.java:144)Īt br.getQuantidadeTotal(MensagemDAO.java:149)Īt br.onCreate(MainActivity.java:85)Īt (Activity.java:4465)Īt (Instrumentation.java:1053)Īt (ActivityThread.java:1934)Ī few months ago we started getting many reports of users complaining about crashes in one of our apps.

copies required data (such as favorite messages).copies the user database to a temporary file.I know that I do a little risky operations according to the SQLite staff themselves.

I have a version of the Application in production, where it is allowed to mark a message as a favorite, but this totally random error happens causing database corruption and resulting in application failure.
