Android-SQLCipher

标签 android sqlcipher

这是我的演示项目

public class SQLDemoActivity extends Activity {
    EventDataSQLHelper eventsData;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //you must set Context on SQLiteDatabase first
        SQLiteDatabase.loadLibs(this);
        String password = "foo123";
        eventsData = new EventDataSQLHelper(this);
        //then you can open the database using a password
        SQLiteDatabase db = eventsData.getWritableDatabase(password);
        for (int i = 1; i < 100; i++)
            addEvent("Hello Android Event: " + i, db);
        db.close();
        db = eventsData.getReadableDatabase(password);
        Cursor cursor = getEvents(db);
        showEvents(cursor);
        db.close();
    }
    @Override
    public void onDestroy() {
        eventsData.close();
    }
    private void addEvent(String title, SQLiteDatabase db) {
        ContentValues values = new ContentValues();
        values.put(EventDataSQLHelper.TIME, System.currentTimeMillis());
        values.put(EventDataSQLHelper.TITLE, title);
        db.insert(EventDataSQLHelper.TABLE, null, values);
    }
    private Cursor getEvents(SQLiteDatabase db) {
        Cursor cursor = db.query(EventDataSQLHelper.TABLE, null, null, null, null, null, null);
        startManagingCursor(cursor);
        return cursor;
    }
    private void showEvents(Cursor cursor) {
        StringBuilder ret = new StringBuilder("Saved Events:\n\n");
        while (cursor.moveToNext()) {
            long id = cursor.getLong(0);
            long time = cursor.getLong(1);
            String title = cursor.getString(2);
            ret.append(id + ": " + time + ": " + title + "\n");
        }
        Log.i("sqldemo",ret.toString());
    }
}

我在如何清除错误时收到以下错误。以下作为演示项目的链接是 https://github.com/sqlcipher/android-database-sqlcipher .

04-12 12:53:20.229: E/AndroidRuntime(7413): java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared: findLibrary returned null

04-12 12:53:20.229: E/AndroidRuntime(7413):     at java.lang.Runtime.loadLibrary(Runtime.java:429)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at java.lang.System.loadLibrary(System.java:554)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:142)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:137)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at example.SQLDemoActivity.onCreate(SQLDemoActivity.java:20)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.os.Handler.dispatchMessage(Handler.java:99)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.os.Looper.loop(Looper.java:123)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-12 12:53:20.229: E/AndroidRuntime(7413):     at java.lang.reflect.Method.invokeNative(Native Method)
04-12 12:53:20.229: E/AndroidRuntime(7413):     at java.lang.reflect.Method.invoke(Method.java:507)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

04-12 12:53:20.229: E/AndroidRuntime(7413):     at dalvik.system.NativeStart.main(Native Method)<

最佳答案

确保您的项目已正确设置 libs/ 目录内容。您不仅需要 JAR 文件,还需要您想要支持的每个 CPU 架构的带有 .so 文件的子目录,例如您在this sample project .

关于Android-SQLCipher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15965581/

相关文章:

android - 如何在 Android 上以编程方式截取屏幕截图?

android:imeOptions ="actionNext"在不指定 android:inputType 的情况下不起作用

ios - SQLCipher iOS OpenSSL 构建错误 : line 66: ./config:没有这样的文件或目录

ios - xcode 5 中的 Shell 脚本调用错误

android - 如何在 Android 中同时使用 ORMLite 和 SQLCipher?

java - Android - 需要 Activity 但不想要 Activity ?

javascript - 在 PhoneGap 2.9 中使用 jQuery/JavaScript 单击按钮事件不执行任何操作

java - Android Studio : Java or XML issue?

java - SQLiteOpenHelper 查询 - 如何显示 SQL 语句

android - 在 Android Studio 项目中集成 SQLCIPHER