W / Environment:EXTERNAL_STORAGE undefined;回到默认状态
java.lang.UnsatisfiedLinkError: com.autonavi.amap.mapcore.MapCore.nativeNewInstance(Ljava/lang/String;)J
at com.autonavi.amap.mapcore.MapCore.nativeNewInstance(Native Method)
at com.autonavi.amap.mapcore.MapCore.runchild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runchild(RobolectricTestRunner.java:54)
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:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
我用的时候
try {
System.loadLibrary("libamapv304");
System.loadLibrary("libamapv304ex");
} catch (UnsatisfiedLinkError e) {
e.printstacktrace();
}
它会导致java.lang.UnsatisfiedLinkError:java.library.path中没有libamapv304
如何使用.so完成Roboletric的单元测试?
最佳答案
我会以某种受控方式加载本机库.为简单起见,假设它在应用程序中:
public class NativeLibApplication extends Application {
...
protected void loadNativeLibraries() {
try {
System.loadLibrary("libamapv304");
System.loadLibrary("libamapv304ex");
} catch (UnsatisfiedLinkError e) {
...
}
}
...
}
Robolectric让您可以在测试中调整您的应用程序.您应该在test文件夹下的同一个包中创建TestNativeLibApplication并禁止加载本机库:
public class TestNativeLibApplication extends NativeLibApplication {
...
@Override
protected void loadNativeLibraries() {
//do nothing
}
...
}