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.
它无法加载.so文件.
我用的时候
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
}
...
}