在将sqlcipher从3.5.4升级到4.2.0后,GreenDAO无法访问现有数据库

问题描述 投票:0回答:1

我正在将GreenDAO与SQLCipher结合使用。将SQLCipher从3.5.4升级到4.2.0后,我的应用无法访问旧的加密数据库。我已经在寻找解决方案,发现我需要在SQLiteDatabaseHook的postKey中运行PRAGMA cipher_migrate来迁移数据库。我尝试了以下操作,但没有解决问题:

SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
@Override
public void preKey(net.sqlcipher.database.SQLiteDatabase database) {}
@Override
public void postKey(net.sqlcipher.database.SQLiteDatabase database) {
                SQLiteDatabase.loadLibs(context);
                database.execSQL("PRAGMA key = '" + key + "';");
                database.execSQL("PRAGMA cipher_migrate;");
            }
        };
try {
            logger.d(TAG, "before openOrCreateDatabase");
            SQLiteDatabase sqLiteDatabase = net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase("DB.db", password, null, hook);
            logger.d(TAG, "before EncryptedDatabase");
            db = new EncryptedDatabase(sqLiteDatabase);
            logger.d(TAG, "DB session is encrypted");
            return new DaoMaster(db).newSession();
} catch (Exception e) {

我收到此错误:

No implementation found for void net.sqlcipher.database.SQLiteDatabase.dbopen(java.lang.String, int) (tried Java_net_sqlcipher_database_SQLiteDatabase_dbopen and Java_net_sqlcipher_database_SQLiteDatabase_dbopen__Ljava_lang_String_2I)
Could not dispatch event: class com.*.LoginResponse to subscribing class class com..LoginViewModel
java.lang.UnsatisfiedLinkError: No implementation found for void net.sqlcipher.database.SQLiteDatabase.dbopen(java.lang.String, int) (tried Java_net_sqlcipher_database_SQLiteDatabase_dbopen and Java_net_sqlcipher_database_SQLiteDatabase_dbopen__Ljava_lang_String_2I)
at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:3)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:10)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:7)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:5)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:3)
at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:3)
at com.elt.passsystem.infrastructure.di.modules.GreenDAOModule.provideDAO(GreenDAOModule.java:8)
at com.elt.passsystem.infrastructure.di.modules.GreenDAOModule_ProvideDAOFactory.get(GreenDAOModule_ProvideDAOFactory.java:3)
at com.elt.passsystem.infrastructure.di.modules.GreenDAOModule_ProvideDAOFactory.get(GreenDAOModule_ProvideDAOFactory.java:1)
android sqlite greendao sqlcipher
1个回答
0
投票

在尝试初始化数据库本身之前,请执行SQLiteDatabase.loadLibs(context);

© www.soinside.com 2019 - 2024. All rights reserved.