ZBAR barcode scanning library not working when using target sdk version 23 in gradle
Asked Answered
J

3

9

I am using zbar scanner library in my project. After updating to sdk 23 Marshmallow scanner is not working. Following is the gradle file. Scanner is working if I set targetSdkVersion anything other than 23.

Following is the gradle file:

    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')
 }

Following is the only line I am getting exception log:

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

How to fix this any help? I want to use tareget sdk 23 for handling camera permissions as per new Marshmallow functionality.

Following are the lines used in code to load libraries:

static {
    System.loadLibrary("iconv");
}
Joyejoyful answered 15/10, 2015 at 15:44 Comment(6)
what does the stacktrace say was the errorSamaritan
10-15 21:10:20.617 6976-6976/? E/AndroidRuntime: FATAL EXCEPTION: mainJoyejoyful
is your lib uses native code or some so files ?? because in Android M this behaviour has been changedCowled
that cant be the full stacktraceSamaritan
updated question with stack traceJoyejoyful
@Cowled Zbar uses some native files thats trueJoyejoyful
O
3

Solution that worked for me is as @Arst has mention in comment of above answer, download jniLibs folder and put it in your application from here. I've also replaced zbar.jar.

Osgood answered 27/7, 2016 at 10:13 Comment(1)
This is the correct answer. I was searching a good solution for this error and THIS fix my issue. Thanks @OsgoodHomey
C
2

Your App is crashing because of following reason :

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html

This release updates the behavior of the dynamic linker. The dynamic linker now understands the difference between a library’s soname and its path ( public bug 6670), and search by soname is now implemented. Apps which previously worked that have bad DT_NEEDED entries (usually absolute paths on the build machine’s file system) may fail when loaded.

The dlopen(3) RTLD_LOCAL flag is now correctly implemented. Note that RTLD_LOCAL is the default, so calls to dlopen(3) that didn’t explicitly use RTLD_LOCAL will be affected (unless your app explicitly used RTLD_GLOBAL). With RTLD_LOCAL, symbols will not be made available to libraries loaded by later calls to dlopen(3) (as opposed to being referenced by DT_NEEDED entries).

On previous versions of Android, if your app requested the system to load a shared library with text relocations, the system displayed a warning but still allowed the library to be loaded. Beginning in this release, the system rejects this library if your app's target SDK version is 23 or higher. To help you detect if a library failed to load, your app should log the dlopen(3) failure, and include the problem description text that the dlerror(3) call returns. To learn more about handling text relocations, see this guide.

Solution: make a folder lib in your android project inside that make a folder named as armeabi-v7a, put your .so file inside it. then load it via system.load(context.nativeLibraryDir + File.separator + ) , if it fails then use system.loadLibrary().

Cowled answered 15/10, 2015 at 16:5 Comment(13)
What's the solution for it.Also can you share link for handling text relocationsJoyejoyful
can you please share your make file ? or how you are they are loading .soCowled
and .so files path is as follows "zBarScannerActivity\src\main\jniLibs"Joyejoyful
can you try to load library from path using system.load(then path of lib), if not then let the system load your lib and try and catch block also.Cowled
do you want me to copy all .so files to libs folder and load from there?Joyejoyful
I have found one update on it according to it library needs to be recompliled for marshmallow, compile libraries with "position independent code", e.g., the cflag -fPIC. I included this and now its working fine but now jniLibs contains three extra folders x86_64, mips and mips_64 and build size is increased don't whether this is right solution or not.Joyejoyful
oh great, that third party code itself taking care of putting lib into respective folder which package managers knowsCowled
But total size zbar taking is almost 6 mb is there any way to reduce itJoyejoyful
you mean to say .so size is 6 MB ?? how much it has been increased ?Cowled
Increased by 3mb almostJoyejoyful
@Joyejoyful I'm getting exception for marshallow target sdk version 23.can you share me the .so files link .Cracking
Having this issue. followed comments. But still not quite understand. Have we go the reliable solution now?Redmon
OK. Fixed the issue by just going to github.com/dm77/barcodescanner/tree/master/zbar/src/main/… downloaded the latest *. files.Redmon
V
0

try this QRCodeReader for android api 23 (6.0 Marshmallow) this works fine. Add Camera permission on request. https://github.com/dlazaro66/QRCodeReaderView

public class DecoderActivity extends Activity implements OnQRCodeReadListener {

private TextView myTextView;
private QRCodeReaderView mydecoderview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_decoder);

    mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
    mydecoderview.setOnQRCodeReadListener(this);

    myTextView = (TextView) findViewById(R.id.exampleTextView);
}


// Called when a QR is decoded
// "text" : the text encoded in QR
// "points" : points where QR control points are placed
@Override
public void onQRCodeRead(String text, PointF[] points) {
    myTextView.setText(text);
}


// Called when your device have no camera
@Override
public void cameraNotFound() {

}

// Called when there's no QR codes in the camera preview image
@Override
public void QRCodeNotFoundOnCamImage() {

}

@Override
protected void onResume() {
    super.onResume();
    mydecoderview.getCameraManager().startPreview();
}

@Override
protected void onPause() {
    super.onPause();
    mydecoderview.getCameraManager().stopPreview();
}

}

Vittle answered 12/5, 2016 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.