我目前正在关注 Mark Murphys SQLite android 教程。我偶然发现了 SQLCihper,它能够在从设备中取出数据时使数据不可读。我制作了自己的示例应用程序,并且 DB 和 MainActivity 完美运行。我能够从模拟器中拉出数据库,并且能够使用SQLite browser读取数据库的内容。然后,我按照另一个stackoverflow问题中的这些“简单”说明进行操作,但出现错误。
这是我的示例应用程序的 MainActivity 中的 onCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBHelper db = new DBHelper(this);
db.getReadableDatabase();
同样,上面的代码工作正常。
接下来我尝试将我的示例应用程序与 SQLCipher 集成:
- 将 icudt46l.zip 复制到 /assets
- 将三个 .so 文件复制到 /armeabi
- 将三个 .so 文件复制到 /x86
- 将三个 jar 复制到 /libs
- 更改了我在 DBHelper 类中的导入以使用 SQLCipher 中的 API
- 为 getReadableDatabase() 添加了一个参数;
所以现在我的 MainActivity onCreate 代码如下所示:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBHelper db = new DBHelper(this);
db.getReadableDatabase("sekrit");
日志猫:
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)