android – 在gradle中使用目标sdk版本23时,ZBAR条形码扫描库无法正常工作

我在我的项目中使用zbar扫描程序库.更新到sdk 23后,Marshmallow扫描仪无法正常工作.以下是gradle文件.如果我将targetSdkVersion设置为23以外的任何东西,扫描仪正在工作.

以下是gradle文件:

    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 15
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "net.sourceforge.zbar.android.CameraTest"
        minSdkVersion 9
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.txt'
        }
    }
  }

 dependencies {
    compile files('libs/zbar.jar')
 }

以下是我获得异常日志的唯一一行:

10-15 21:19:00.682 7719-7719/? E/AndroidRuntime: FATAL EXCEPTION: main
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime: Process: net.sourceforge.zbar.android.CameraTest, PID: 7719
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/net.sourceforge.zbar.android.CameraTest-2/lib/arm/libiconv.so: has text relocations
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at java.lang.Runtime.loadLibrary(Runtime.java:372)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at java.lang.System.loadLibrary(System.java:1076)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at net.sourceforge.zbar.android.CameraTest.CameraTestActivity.<clinit>(CameraTestActivity.java:54)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at java.lang.Class.newInstance(Native Method)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-15 21:19:00.682 7719-7719/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-15 21:19:00.688 804-6706/? W/ActivityManager:   Force finishing activity net.sourceforge.zbar.android.CameraTest/.CameraTestActivity
10-15 21:19:00.700 9581-9650/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0x9664a7f0

如何解决这个问题呢?我想根据新的Marshmallow功能使用tareget sdk 23来处理相机权限.

以下是代码中用于加载库的行:

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

解决方法:

对我有用的解决方案是@Arst在上述答案的评论中提到,下载jniLibs文件夹并将其从here放入您的应用程序.我也替换了zbar.jar.

上一篇:[常用工具] mermaid学习笔记


下一篇:好用的UML生成工具Mermaid