How can I use ORMLite with SQLCipher together in Android?

Bruno Nardini picture Bruno Nardini · Feb 7, 2012 · Viewed 7.9k times · Source

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 allow a class to extend two classes and if I implement separately, they will not communicate with each other.

How can I work with both together? How do I resolve the SQLiteOpenHelper implementation problem?

Answer

ge0rg picture ge0rg · Feb 8, 2013

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.