我正在尝试导入opencv和zbar并在同一个项目中使用我导入opencv noramlly并且它工作我将.so文件复制到jniLibs然后我打开了相机它工作正常然后我导入zbar通过将libs和.so文件中的.jar文件从每个文件夹复制到具有opencv .so文件的同一文件夹,例如我将2个zbar .so文件从x86复制到jniLibs x86与其他.so的opencv这是错误我得到了
10-25 18:54:09.336 1447-1447/com.example.amgad.medikar E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.example.amgad.medikar.MainActivity.onCreate(MainActivity.java:71)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 785 could not load needed library 'libiconv.so' for 'libzbarjni.so' (load_library[1091]: Library 'libiconv.so' not found)
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at net.sourceforge.zbar.ImageScanner.<clinit>(Unknown Source)
at com.example.amgad.medikar.MainActivity.onCreate(MainActivity.java:71)
该行
scanner = new ImageScanner();
所以我试图手动加载库
static{
System.loadLibrary("libiconv");
System.loadLibrary("libzbarjni");
}
然后我收到了这个错误
10-25 19:15:33.295 1495-1495/com.example.amgad.medikar E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libiconv: findLibrary returned null
答案 0 :(得分:1)
使用:
static {
System.loadLibrary( "iconv" );
}
有关更多信息,请查看ZBarAndroidSDK-0.2中的包样本。
答案 1 :(得分:0)
就我而言,我的项目中也有其他.so库。
我做的是:
System.loadLibrary( "iconv" );
将此行添加到构建
dependencies {
compile fileTree(dir: 'libs', include: '*.jar') }
希望这有帮助