Error migrating from version 3x to 4x

Hello everyone.
After updating net.zetetic:android-database-sqlcipher:3.5.9@aar to net.zetetic:sqlcipher-android:4.5.6@aar in android project I have a problem.
My helper class:

public class DBHelperKey extends SQLiteOpenHelper {
        private static DBHelperKey instance;
        SQLiteDatabase db;
    
        public DBHelperKey(Context context) {
            super(context, "base.db", null, 1);
        }
    
        static public synchronized DBHelperKey getInstance(Context context) {
            if (instance == null) {
                instance = new DBHelperKey(context);
            }
            return instance;
        }
    
        @Override
        public void onCreate(SQLiteDatabase sqLiteDatabase) {
            sqLiteDatabase.execSQL("Create table mysettings (id TEXT PRIMARY KEY,myvalue TEXT)");
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
            onCreate(sqLiteDatabase);
            sqLiteDatabase.execSQL("DROP table if exists mysettings");
        }
    
        public void set(String mykey, String myvalue) {
            if (!exist(mykey)) {
                db.execSQL("insert into mysettings(id,myvalue) values('" + mykey + "','" + myvalue + "')");
            } else {
                db.execSQL("update mysettings set myvalue='" + myvalue + "' where id='" + mykey + "'");
            }
        }
    
        public void remove(String mykey) {
            db.execSQL("delete from mysettings where id='" + mykey + "'");
        }
    
        public String get(String mykey) {
            String res = null;
            Cursor cursor = db.rawQuery("select myvalue from mysettings where id = '" + mykey + "'", null);
            cursor.moveToLast();
            try {
                res = cursor.getString(cursor.getColumnIndex("myvalue"));
            } catch (Exception ignored) {
            }
            cursor.close();
            cursor.deactivate();
            //db.close();
            return res;
        }
    
        public Boolean exist(String mykey) {
            boolean res = false;
            Cursor cursor = db.rawQuery("select count(myvalue)as cnt from mysettings where id = '" + mykey + "'", null);
            cursor.moveToLast();
            if (Integer.parseInt(cursor.getString(cursor.getColumnIndex("cnt"))) > 0) {
                res = true;
            }
            cursor.close();
            cursor.deactivate();
            return res;
        }
    
        public void openDB() {
            Boolean res = false;
            try {
                db = instance.getWritableDatabase();
            } catch (Exception ex) {
                Log.e("openDB_ex", ex.toString());
            }
        }
    }  

Log message (openDB_ex) - openDB() - android.database.sqlite.SQLiteException: file is not a database (code 26): , while compiling: PRAGMA journal_mode .

Current db without password.

Please help me solve this problem

I am facing the same issue. Please help to resolve this

Hello @ITService_Developer, @Venkat,

When upgrading from SQLCipher version 3.x to 4.x, the 4.x library will not open a 3.x database file by default. There are a few options available to address this, please review the upgrade notes here to determine how you would prefer to proceed:

Hi All, Found the solution by going through the documentation. The key is to set the current DB version in post key before doing migration. Example code below

String path = context.getDatabasePath(databaseName).getPath();
final Boolean migrationOccurred = {false};
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
@Override
public void preKey(SQLiteDatabase database) {
}
@Override
public void postKey(SQLiteDatabase database) {
database.rawExecSQL(“PRAGMA cipher_page_size = 1024;”);
database.rawExecSQL(“PRAGMA kdf_iter = 64000;”);
database.rawExecSQL(“PRAGMA cipher_hmac_algorithm = HMAC_SHA1;”);
database.rawExecSQL(“PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;”);

            Cursor c = database.rawQuery("PRAGMA cipher_migrate", null);
            if (c.getCount() == 1) {
                c.moveToFirst();
                String selection = c.getString(0);
                migrationOccurred[0] = selection.equals("0");
            }
            c.close();
        }
    };
    try {
        SQLiteDatabase database = SQLiteDatabase.openDatabase(path,
                password, null,
                SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY, hook);
        if(database != null){
            database.close();
        }
    }
    catch (Exception e) {
        Log.e("Error", e.getMessage());
    }

After migration same password (Used in SQLCipher 3) is working here for 4 as well without loosing any data.