greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

GreenDAO cannot access existing database after upgrading sqlcipher from 3.5.4 to 4.2.0 #972

Open mreid-projects opened 5 years ago

mreid-projects commented 5 years ago

I am trying to migrate from sqlcipher 3.5.4 to 4.2.0 and have added the following:

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) {

but I get this error:

 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)
mreid-projects commented 5 years ago

I've contacted SQLCipher and here's their reply https://github.com/sqlcipher/android-database-sqlcipher/issues/446#issuecomment-502692765 The same error message is returned when Proguard is switched off, so that suggests it's the integration with GreenDao. Please would you help to find a solution to this?

greenrobot-team commented 5 years ago

The stack trace clearly suggests otherwise (no implementation for a native method found within the net.sqlcipher package). Can you check that the native SQLCipher matches their Java API?

Otherwise not much I can help you with here as this touches no greenDAO APIs. -Uwe