您好我正在使用活动的android与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文件。要解决这些问题需要在设备或模拟器上进行。如何解决这个问题?需要一些帮助。
答案 0 :(得分:0)
你必须正确地将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文件