Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use ORMLite with SQLCipher together in Android?

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?

like image 465
Bruno Nardini Avatar asked Feb 07 '12 13:02

Bruno Nardini


1 Answers

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.

like image 96
ge0rg Avatar answered Oct 22 '22 04:10

ge0rg