Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 0.2.6 and ZBar project setup

Tags:

android

zbar

I am using the latest Android Studio 0.2.6 and the latest ZBar Android SDK. What I have done so far:

  1. Created a brand new project called QRTest

  2. Created a folder called libs in my project

  3. Put the content of the Zbar libs directory into my project folder

  4. Right clicked the zbar.jar file in my project and Added as a Library

  5. In my build.gradle file, edited it so that it is now:

    dependencies { compile 'com.android.support:support-v4:13.0.0' compile files('libs/zbar.jar') }

  6. Basically copied the example code from the ZBar android SDK example to my own project.

  7. The project compiles and runs fine (0 errors, 0 warnings), but it crashes upon running. The logs show:

09-01 16:06:02.026: W/dalvikvm(7050): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lnet/sourceforge/zbar/ImageScanner;

09-01 16:06:02.036: E/AndroidRuntime(7050): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]: 209 could not load needed library 'libiconv.so' for 'libzbarjni.so' (load_library[1093]: Library 'libiconv.so' not found)

09-01 16:06:02.036: E/AndroidRuntime(7050): at net.sourceforge.zbar.ImageScanner.(Unknown Source)

Looking at the code in my MainActivity, it appears to be dying here:

 /* Instance barcode scanner */
 scanner = new ImageScanner();

Which seems to suggest to me that somehow I havent imported my Zbar library files correctly. Any help on how to get this very basic example up and going would be appreciated!

Just to note, if I use Android Studio to import a new project from the ZBar Android SDK example, it compiles and runs fine. However, it is using the old ant build system. I would rather use the new gradle build system, so thats why I'm trying to import ZBar into a fresh Android 0.2.6 project. Thanks!

Another note: I tried modifying my build gradle to the accepted answer here: How to change libs directory in Gradle? and it did not work.

enter image description here

like image 963
kurisukun Avatar asked Dec 06 '22 05:12

kurisukun


2 Answers

Solution:

  1. Add zbar.jar into app/libs

  2. Create a folder called "jniLibs"-Java Native Interface (JNI) under src/main and copy folder armeabi-v7a, armeabi, and x86 into src/main/jniLibs.

The file structure like below:

src/main/jniLibs/armeabi-v7a
src/main/jniLibs/armeabi
src/main/jniLibs/x86

  1. Go to File > Project Structure> app > Dependencies > Add support-v4 into project
like image 193
Rosy Avatar answered Dec 21 '22 03:12

Rosy


You should add *.so libraries to your project. If you use Android Studio and Gradle it's a little complicated because you need to pack libraries into jar. Check my answer here: ZBar - QR Code Scanner, crashing in Android Studio to see more details.

like image 40
froger_mcs Avatar answered Dec 21 '22 05:12

froger_mcs