我正在将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)
答案 0 :(得分:0)
在尝试初始化数据库本身之前先做SQLiteDatabase.loadLibs(context);
答案 1 :(得分:0)
看看这里的例子:
并添加 SQLiteDatabase.loadLibs(getApplicationContext());在您的应用程序类中。