How can I use ORMLite with SQLCipher together in Android?

前端 未结 5 2163
轻奢々
轻奢々 2020-12-05 15:12

I would like to use OrmLite with SQLCipher in my Android project, but both libraries have their own abstract SQLiteOpenHelper class to implement. Java don\'t a

5条回答
  •  有刺的猬
    2020-12-05 15:44

    I have distilled the answer by Rejinderi into a patch for ORMLite 4.43 and compiled it into a JAR file. To integrate it in your Android project, do the following:

    1. Follow the SQLCipher for Android HOWTO to get SQLCipher into your project
    2. Add ORMLite to your project (see What is a good tutorial for using ORMLite with SQLite and Android)
    3. Replace libs/ormlite-android.jar with ormlite-android-sqlcipher.jar
    4. Add your secret database password to the appropriate DB opening methods

    However, you should not trust me to provide an unmanipulated JAR file and follow the build instructions in the patch instead.

    EDIT: With the patched library, the calls to getReadableDatabase(), getWritableDatabase() and the OrmLiteSqliteOpenHelper constructor need to be passed the password as additional parameter. If you are using a DB helper, extend it appropriately to pass the password to OrmLiteSqliteOpenHelper.

提交回复
热议问题