【问题标题】:UnsatisfiedLinkError for sqlcipher with robolectricUnsatisfiedLinkError for sqlcipher with robolectric
【发布时间】:2016-12-08 07:59:25
【问题描述】:

您好,我正在使用带有 sqlcipher 的活动 android 进行数据库加密。它工作正常。我能够使用加密数据库创建应用程序。现在我将 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 文件。要取消这些情况,需要在设备或模拟器上进行。如何解决这个问题?需要一些帮助。

【问题讨论】:

  • 您的问题解决了吗?我面临着类似的问题。

标签: android robolectric activeandroid sqlcipher-android


【解决方案1】:

几件事:

  1. 如果您想测试依赖于 .so 库的类(我们称之为 NativeClass) - 那是行不通的。
  2. 如果您想测试依赖 NativeClass 的类 - 使用 interface 而不是直接使用 NativeClass,然后模拟该接口。

【讨论】:

    【解决方案2】:

    您必须将 sqlcipher 正确导入到您的 android 项目中。

    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-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多