1

こんにちは、データベース暗号化のために sqlcipher が組み込まれたアクティブなアンドロイドを使用しています。正常に動作しています。暗号化されたデータベースでアプリケーションを作成できます。現在、テストケースに robolectic を使用しています。そして、リンクエラーでエラーが発生しています。私はgradleのバージョンを更新しました。したがって、.so ファイルは含めません。その代わりに私は使用しています

 ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
    }

次のエラーが表示されます:

    java.lang.UnsatisfiedLinkError: no sqlcipher in java.library.path

    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:196)
    at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:189)
    at com.example.android.testing.unittesting.BasicSample.SampleApplication.onCreate(SampleApplication.java:20)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:141)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:171)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:137)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)


java.util.ServiceConfigurationError: org.robolectric.internal.ShadowProvider: Provider org.robolectric.shadows.multidex.Shadows not a subtype

    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.robolectric.internal.bytecode.InstrumentationConfiguration$Builder.build(InstrumentationConfiguration.java:151)
    at org.robolectric.RobolectricTestRunner.createClassLoaderConfig(RobolectricTestRunner.java:115)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:169)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:137)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

https://groups.google.com/forum/#!topic/sqlcipher/i_Gw-7d8DpU robolectic では、ケースのシミュレーションに JVM を使用しています。また、.so ファイルはサポートされません。これらのケースを解決するには、デバイスまたはエミュレーターで行う必要があります。この問題を解決するにはどうすればよいですか? 助けが要る。

4

2 に答える 2

1

いくつかのこと:

  1. .so ライブラリに依存するクラスをテストしたい場合 (それを と呼びましょうNativeClass) - それはうまくいきません。
  2. 依存するクラスをテストする場合は、直接NativeClass使用するinterface代わりにan を使用NativeClassしてから、そのインターフェイスをモックします。
于 2016-12-08T09:07:18.267 に答える
0

Android プロジェクトに sqlcipher を正しくインポートする必要があります。

1) Project\app\src\main の下にフォルダーjniLibsを作成します...Project\app\src\main\jniLibs\

2) sqlcipher.so ファイルを正しいフォルダー (これらのいずれか) に配置します。

Project\app\src\main\jniLibs\armeabi\sqlcipher.so
Project\app\src\main\jniLibs\armeabi-v7a\sqlcipher.so
Project\app\src\main\jniLibs\mips\sqlcipher.so
Project\app\src\main\jniLibs\x86\sqlcipher.so

3) 次に、使用するクラス内の任意の場所に、このライブラリに静的インポートを追加します。

static {
        try {
            //Libraryname without .so!!
            System.loadLibrary("sqlcipher");
        }
        catch(UnsatisfiedLinkError ex)
        {
           //Not found
        }
    }

プロジェクトをコンパイルします。多分プロジェクトもきれいです。これが役立つことを願っています!さらにサポートが必要な場合はお知らせください。

編集: libs\armeabi\ sqlcipher.soの下に .so ファイルを追加してみてください

于 2016-12-08T12:02:09.613 に答える