2

I'm currently following along with Mark Murphys SQLite android tutorials. I stumbled upon SQLCihper and it's ability to make data unreadable when it's pulled off of a device. I made my own sample application, and the DB and MainActivity work perfectly. I'm able to pull the database off the emulator and I'm able to read the contents of the database using SQLite browser. I then followed these "simple" instructions from another stackoverflow question but I am getting errors.

Here is my onCreate in my MainActivity in my sample app:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBHelper db = new DBHelper(this);
db.getReadableDatabase();

Again, the above code works fine.

Next I tried to integrate my sample app with SQLCipher:

  1. Copied the icudt46l.zip into /assets
  2. Copied three .so files into /armeabi
  3. Copied three .so files into /x86
  4. Copied three jars into /libs
  5. Changed my imports in my DBHelper class to use the API from SQLCipher
  6. Added a parameter to getReadableDatabase();

So now my MainActivity onCreate code looks like this:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBHelper db = new DBHelper(this);
db.getReadableDatabase("sekrit");

The logcat:

06-20 20:50:33.178: E/AndroidRuntime(24805): FATAL EXCEPTION: main
06-20 20:50:33.178: E/AndroidRuntime(24805): java.lang.UnsatisfiedLinkError: Native method not found: net.sqlcipher.database.SQLiteDatabase.dbopen:(Ljava/lang/String;I)V
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1950)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:900)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:943)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:107)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:173)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at com.example.testsqlcipher.MainActivity.onCreate(MainActivity.java:65)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.Activity.performCreate(Activity.java:5104)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.os.Looper.loop(Looper.java:137)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at android.app.ActivityThread.main(ActivityThread.java:5041)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-20 20:50:33.178: E/AndroidRuntime(24805):    at dalvik.system.NativeStart.main(Native Method)
Community
  • 1
  • 1
EGHDK
  • 17,818
  • 45
  • 129
  • 204
  • Just to be sure, if you're on Eclipse and R22, have you fixed the "Order & Export" portion of the build path? http://stackoverflow.com/questions/16596969/libraries-do-not-get-added-to-apk-anymore-after-upgrade-to-adt-22/16596990#16596990 Also, by `/armeabi`, don't you mean `libs/armeabi/`? (ditto for x86) – CommonsWare Jun 20 '13 at 20:59
  • Can you elaborate on "Order and Export"? And yes I do mean `/libs/armeabi`. I added the three jars and the .zip in Java Build Path. I then went into Order and Export and checked off those four files (3 .jars 1 .zip) and pressed ok. – EGHDK Jun 20 '13 at 21:03
  • The "Order & Export" stuff is what I covered at the SO answer I linked to above (http://stackoverflow.com/questions/16596969/libraries-do-not-get-added-to-apk-anymore-after-upgrade-to-adt-22/16596990#16596990). You can read more about it at: http://commonsware.com/blog/2013/05/23/do-not-manually-modify-eclipse-build-path-except-now-r22.html – CommonsWare Jun 20 '13 at 21:07
  • Rather than checking those files, check "Android Private Libraries" instead. – CommonsWare Jun 20 '13 at 21:08
  • I deselected the four files, and checked "Android Private Libraries". Still get an error `java.lang.UnsatisfiedLinkError: Native method not found: net.sqlcipher.database.SQLiteDatabase.dbopen` – EGHDK Jun 20 '13 at 21:11
  • Upload your project somewhere, and I'll take a peek at it. It's not finding your `.so` files for some reason. Either that, or you're running this on a MIPS emulator... :-) – CommonsWare Jun 20 '13 at 21:13
  • Hmm... could this be the problem? The github doesn't have all of the files I need I think. So I grabbed them from various projects. Like "notpadbot" the sample project on the sqlcipher github page. https://github.com/sqlcipher/android-database-sqlcipher – EGHDK Jun 20 '13 at 21:15
  • SQLCipher for Android's binary distribution is available by link from http://sqlcipher.net/downloads/. For example, 2.1.1 is at https://s3.amazonaws.com/sqlcipher/SQLCipher%20for%20Android%202.1.1.zip right now. That should contain everything that you need. – CommonsWare Jun 20 '13 at 21:18
  • Hmm... okay I just updated all of my files from that source, but it's still not working. Am I supposed to copy the .so files? – EGHDK Jun 20 '13 at 21:23
  • I would copy everything, so everything is synchronized. – CommonsWare Jun 20 '13 at 21:24
  • What do you mean "everything"? I just updated "everything". The .so, the jars, and the zip. – EGHDK Jun 20 '13 at 21:26
  • That would qualify as "everything". – CommonsWare Jun 20 '13 at 21:27
  • So where do I begin to troubleshoot this? – EGHDK Jun 20 '13 at 21:41
  • You're welcome to wait for other helpers. Or, you're welcome to post a question to the sqlcipher Google Group. Or, you're welcome to upload the app somewhere, and I'll take a look at it, as I offered earlier. Or, you're welcome to download one of my SQLCipher samples and poke at it a while. Beyond that, I have no advice, as when I have seen your error message, it meant that either the `.so` files are not in the correct place (and I can't confirm that without seeing the whole project), or I was on the wrong CPU architecture (e.g., an x86 emulator before we had x86 SQLCipher binaries). – CommonsWare Jun 20 '13 at 21:46
  • 1
    Got it to work. Just added `SQLiteDatabase.loadLibs(this);` in between my db initilization and my `db.getReadableDatabase("sekrit");` line. Thanks – EGHDK Jun 20 '13 at 21:58
  • Ah, I forgot that missing that statement would also trigger this error. My apologies for not remembering that. – CommonsWare Jun 20 '13 at 22:00
  • That's alright. You helped me figure out where to download SQLCipher from, and I think that also helped because I had the loadLibs in there before, but it still didn't work. Thanks for the step by step walkthrough. Perfect! – EGHDK Jun 21 '13 at 06:02

1 Answers1

0

Looks like you guys got it all sorted in the comments to the question, but for reference and anyone else, we do have an integration tutorial for SQLCipher and Android projects available here, which contains the loadLibs bit ;-)

http://sqlcipher.net/sqlcipher-for-android/

As @CommonsWare suggests, all are welcome to post questions to the SQLCipher users mailing list, too:

http://groups.google.com/group/sqlcipher

Billy Gray
  • 1,747
  • 4
  • 18
  • 23
  • Unfortunately it's not a Windows friendly tutorial. Also, I couldn't find where to download the files from exactly. The link on the page `http://sqlcipher.net/storage/android/downloads/SQLCipher%20for%20Android%202.1.1.zip` doesn't work. – EGHDK Jun 26 '13 at 21:55
  • Ah, that's an old link, we'll fix that. The current android binaries are here: https://s3.amazonaws.com/sqlcipher/SQLCipher+for+Android+2.2.0.zip but you can always find the latest link here: http://sqlcipher.net/downloads/ – Billy Gray Jul 03 '13 at 14:35
  • Eureka! I'm glad it wasn't entirely my fault. – EGHDK Jul 03 '13 at 20:33