Android P - 'SQLite: No Such Table Error' after copying database from assets
Was having a similar issue, and solved this adding this to my SQLiteOpenHelper
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); db.disableWriteAheadLogging(); }
Apparently Android P sets the PRAGMA Log thing different. Still no idea if will have side effects, but seems to be working!
My issues with Android P got solved by adding 'this.close()' after this.getReadableDatabase() in createDataBase() method as below.
private void createDataBase() throws IOException { this.getReadableDatabase(); this.close(); try { copyDataBase(); } catch (IOException e) { throw new RuntimeException(e); }}
This issue seems to lead to a crash much more often on Android P than on previous versions, but it's not a bug on Android P itself.
The problem is that your line where you assign the value to your String filePath
opens a connection to the database that remains open when you copy the file from assets.
To fix the problem, replace the line
String filePath = mContext.getDatabasePath(Utils.getDatabaseName()).getAbsolutePath();
with code to get the file path value and then close the database:
MySQLiteOpenHelper helper = new MySQLiteOpenHelper();SQLiteDatabase database = helper.getReadableDatabase();String filePath = database.getPath();database.close();
And also add an inner helper class:
class MySQLiteOpenHelper extends SQLiteOpenHelper { MySQLiteOpenHelper(Context context, String databaseName) { super(context, databaseName, null, 2); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }}