我正在使用greendao ORM。我试图使用SQLCipher加密我的数据库。Greendao自动支持sqlcipher。所以我编写了以下代码进行加密。
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "encrypted-db",null);
Database db = helper.getEncryptedWritableDb("mySecretPassword");
DaoSession session = new DaoMaster(db).newSession();
return session;
然而,每当我使用这个会话执行任何数据库操作时,它都会出现错误。
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/greenrobot/greendao/database/DatabaseOpenHelper$EncryptedHelper;
at org.greenrobot.greendao.database.DatabaseOpenHelper.checkEncryptedHelper(DatabaseOpenHelper.java:121)
at org.greenrobot.greendao.database.DatabaseOpenHelper.getEncryptedWritableDb(DatabaseOpenHelper.java:133)
我的Gradle依赖关系如下:
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.google.code.gson:gson:2.8.0'
我的Proguard规则如下:
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
# If you do not use Rx:
-dontwarn rx.**
那么如何使用GreenDAO和SQLCipher加密我的数据库呢?
PS:Database db = helper.getEncryptedWritableDb("mySecretPassword");
这行代码会在执行任何数据库操作时出现错误。
Database db = helper.getEncryptedWritableDb("mySecretPassword");
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
- maxoumime