2

这是我的演示项目

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

3 回答 3

2

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

于 2013-04-12T12:07:10.810 回答
1

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

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

它必须看起来像这样。

在此处输入图像描述

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

PS我使用Android Studio。

于 2015-08-01T01:51:07.687 回答
0

在您的应用程序中,在您的 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。

于 2015-02-22T20:35:55.120 回答