본문 바로가기

Programming/android

Android sqlCipher Proguard 오류시...

SQLCIPHER

 

In Android development, you probably want to encrypt the database (*.sdf) so that user (especially with rooted device) can't read the database without the application; for example, using SQLite Database Browser (http://sqlitebrowser.sourceforge.net). Fortunately, you can useSQLCipher (http://sqlcipher.net) to complete the task. Here are the implementation steps:

  • Download the latest SQLCipher library from their website. I recommend you download the binaries (*.zip).
  • Extract the file. It should contains libs and assets folder.
  • Copy (and replace) these 2 folders into your project.
  • Add these new libraries into your project classpath. For example if you are using Eclipse IDE (http://www.eclipse.org), you can resolve by click menu Project > Properties. ChoseJava Build Path tab, and then Libraries on the next tab. Click Add JARs, chose all *.zipand *.jar files from SQLCipher libraries. Click OK.
  • Change all packages import statements from android.database.sqlite.* intoinfo.guardianproject.database.sqlcipher.*. But the original android.database.Cursorcan still be used.
  • Add these lines at onCreate method in first activity class. pragmaKey is a key you defined (String).

         SQLiteDatabase.LoadLibs(this);

         SQLiteOpenHelper.getWritableDatabase(pragmaKey); 

  • Run the application.
  • Pull the database (*.sdf). It should be unrecognized as a database when you open it withSQLite Database Browser.

 

PROGUARD

 

With ProGuard (http://proguard.sourceforge.net) you can shrink, optimize, and obfuscate your code so that your exported (*.apk) file become smaller in size and more difficult to reverse by another engineer. Here are the implementation steps:

  • In your project, add this line into default.properties file. It shows that your proguard configuration is based on proguard.cfg file.

         proguard.config=proguard.cfg 

  • You can fix errors while exporting your project or running your application by adding –keepline in proguard.cfg file. For example like:

         -keep public class * extends android.app.Activity

 

 

INTEGRATION

 

When I develop this integration, it seems ProGuard hasn't tested with SQLCipher yet. So I have to exclude SQLCipher libraries in ProGuard configuration.

 

     -keep public class info.guardianproject.database.** {

         *;

     }

 

     -libraryjars libs/commons-codec.jar

     -libraryjars libs/guava-r09.jar

     -libraryjars libs/jsr305-1.3.9.jar

     -libraryjars libs/sqlcipher.jar

     -libraryjars assets/icudt46l.zip

 

If you find errors similar with insertWithOnConflict or Verifier rejected class from SQLCipherpackage, you should upgrade your ProGuard libraries in your android-sdk.


출처 : http://www.facebook.com/notes/hendrick-prasdito/how-to-integrating-sqlcipher-and-proguard-in-android-development/10150980582279008


 추가자료 : 

1. https://groups.google.com/forum/?fromgroups#!searchin/sqlcipher/proguard/sqlcipher/-odd0jrXH-I/jwdQAfwPwegJ

2. http://proguard.sourceforge.net/#manual/usage.html


외국 아이들은 참 친절한듯...