【问题标题】:Android - SQLCipher安卓 - SQLCipher
【发布时间】:2013-04-12 07:32:52
【问题描述】:

这是我的演示项目

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)<

【问题讨论】:

    标签: android sqlcipher


    【解决方案1】:

    确保您的项目正确设置了libs/ 目录内容。您不仅需要 JAR 文件,还需要包含 .so 文件的子目录,用于您打算支持的每个 CPU 架构,例如您在 this sample projectlibs/ 目录中看到的。

    【讨论】:

    • 我有同样的错误,我做了你的解决方案,但它一直抛出上述异常,注意我使用的是 AndroidStudio 0.5.1 并使用 Emulator kitkat。
    【解决方案2】:

    我有同样的错误。这是对我有用的解决方案。

    在您的 java 文件夹附近创建一个名为 jniLibs 的文件夹,并将所有目录(或您打算支持的体系结构的目录)与 *.so 文件一起放置在那里。

    一定是这样的。

    如果它适合你,你不需要在你的 libs 文件夹中有这个文件夹。

    附:我使用 Android Studio。

    【讨论】:

      【解决方案3】:

      在您的应用程序中,在您的 build.gradle 文件中确保您有以下几行:

      dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile files('libs/sqlcipher-javadoc.jar')
      compile files('libs/sqlcipher.jar')
      

      }

      还可以右键单击您的项目,打开模块设置并选择依赖项选项卡。确保列出了 sqlcipher-javadoc.jar 和 sqlcipher.jar。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-24
        • 2017-12-05
        • 2012-04-08
        • 2012-10-09
        • 2014-06-09
        相关资源
        最近更新 更多