我正在使用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'
我的计划规则是
-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");
答案 0 :(得分:1)
您还需要添加SQLCipher
的依赖项。将此行添加到Gradle依赖项:
compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'