ZBar - QR Code Scanner, crashing in Android Studio
Asked Answered
D

4

9

I have downloaded from git latest zBar QR Code Scanner (SDK 0.2). I am trying to implement it in my application. I work on Android Studio.

What have I done:

  1. I have copied zBar.jar to libs folder of my Project.
  2. I have created *.jar files from "amerabi", "amerabi-v7a", "x86" by zip'ing them and changing their format to *.jar.
  3. I have copied amerabi.jar, amerabi-v7a.jar and x86.jar to libs folder of my Project.
  4. There is no need to change anything in gradle because it is already configured to import every jar file from libs projects. See below:

    dependencies {
        compile 'com.android.support:support-v4:18.0.+'
        compile 'com.crashlytics.android:crashlytics:1.+'
    
        compile fileTree(dir: 'libs', include: '*.jar')
    
        compile project(':FacebookSDK')
        compile project(':actionbarsherlock')
        compile project(':Aviary-SDK')
    }
    
  5. Every class form zBar lib can be seen so I have configured everything. I run my ScannerActivity and in onCreate I get error in this line:

    scanner = new ImageScanner();  // this line shows an error
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);
    

So implementation is 1:1 the same as in example.

My error log:

java.lang.UnsatisfiedLinkError: Couldn't load zbarjni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/pl.toptof.android.debug-2.apk"],nativeLibraryDirectories=[/data/app-lib/pl.toptof.android.debug-2, /vendor/lib, /system/lib]]]: findLibrary returned null

Please help me with that problem. I don't know why my Android Studio can see lib but can't use it in the same way it's used in example.

Drice answered 11/12, 2013 at 16:32 Comment(0)
K
13

I think, you made mistake in your jars structures. If you want to make jar package from *.so libs you should use that kind of structure:

/lib/armeabi/*.so

It is directory structure example for your library:

lib/
---/armeabi
------/libiconv.so
------/libzbarjni.so

and of course you should rename final package from lib.zip to armeabi.jar. In your case you should repeat this process for armeabi-v7a and x86.

Karlotte answered 11/12, 2013 at 19:19 Comment(3)
Can you please elaborate? I can't seem to get this to work and I am having the same issue as @DriceJigging
I will, because I have the same problem and he give me correct answer. So if you use Android studio then create 2 folders first one is "lib". Inside lib create "armeabi" folder. Inside armeabi folder put .so files(libiconv.so and libzbarjni.so). then make an archive from lib folder... will be lib.zip for example. After that you will have to rename it into armeabi.jar. Last step is to copy your jar in libs and compile into gradle.Enamor
even I am facing same problem while working on eclipse, project runs on android devices but not on android TV. I followed the above steps, but the jars are going away as soon as I run or build the project. Any suggestions??Zwiebel
H
1

The solution is too complicated. What I did to get it working, was to use the jar files already compiled in the example solution from this example. Copy them to your lib folder and make sure to also add them in the gradle file. However, your line compile fileTree(dir: 'libs', include: '*.jar') should do the trick.

Hawkweed answered 20/6, 2015 at 7:33 Comment(0)
C
1

Put the directories armeabi, armeabi-v7a, and x86 in a sub-directory called native-libs under your root project folder. Then add these settings to your build.gradle file:

android {
    // other settings
    sourceSets {
            main {
                jni.srcDirs=[] //to suppress makefiles autogeneration
                jniLibs.srcDirs=['native-libs'] //native *.so in armeabi x86 and mips to include
            }
        }
}

The resulting .apk should have the native libs included now.

Crossbill answered 17/11, 2015 at 8:27 Comment(0)
W
1

You better check if you have the newest possible version of ZBar in dependencies in your app.gradle file. Getting the latest version worked for me and solved all the problems like failing to find libzbarjni.so and libiconv.so

Wellbalanced answered 2/6, 2017 at 9:44 Comment(9)
For me with compile 'me.dm7.barcodescanner:zbar:1.9.3' I keep on getting the errorKolodgie
And do you have "compile 'net.jcip:jcip-annotations:1.0'" in your app.gradle? I have these plus compileSdkVersion 25, minSdkVersion 16, buildToolsVersion "25.0.2" and it worked for me. I didn't have to add anything extra.Wellbalanced
I did not have this dependency, but now I added it and the problem still remains. Can you share your whole build,gradle so that I can compare?Kolodgie
Sure. You can find it here. dropbox.com/s/wc2nz75sxyxu8bc/build.gradle?dl=0Wellbalanced
By the way on which device was your application crashing? I have one Galaxy Nexus observing the problem on my side in my app.Kolodgie
I had problems on Asus Zenphone (version 6.0) and on some other devices with android version 6 or higher. A had this issue a long ago, but it worked fine with android 4.0.3 and 5.0.0 as I remember.Wellbalanced
Today i did another experiment I created an emulator running API 17. It crashes with the same error as my real phone. I know I have already given you too much work, but is it possible that you check with such and see if your application will run ok on such an emulatorKolodgie
After much of fight, adding this line ` System.loadLibrary("iconv");` before loading the ScannerView made the error go away for me. Using zbar 1.9.3Kolodgie
Happy for you:) Don't forget about asking for permissions and it will work like a charmWellbalanced

© 2022 - 2024 — McMap. All rights reserved.