android studio 785中的zbar无法加载所需的库' libiconv.so'为' libzbarjni.so'

时间:2014-10-25 17:16:25

标签: android opencv zbar

我正在尝试导入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

2 个答案:

答案 0 :(得分:1)

使用:

static {
    System.loadLibrary( "iconv" );
}

有关更多信息,请查看ZBarAndroidSDK-0.2中的包样本。

答案 1 :(得分:0)

就我而言,我的项目中也有其他.so库。

我做的是:

  1. 将每个.so文件放在正确的cpu类型下(正如您已经做过的)
  2. 将所有cpu文件夹放在名为&#34; lib&#34;的另一个文件夹中。
  3. zip lib文件夹并将其重命名为lib.jar
  4. 将lib.jar放在app libs文件夹
  5. 按照上面的建议添加System.loadLibrary( "iconv" );
  6. 将此行添加到构建

    dependencies {
     compile fileTree(dir: 'libs', include: '*.jar') }
    
  7. 希望这有帮助