Setting up Android Studio 0.2.6 and ZBar

I am using the latest version of Android Studio 0.2.6 and the latest version of the Android ZKar Android SDK. What i have done so far:

  • Created a new project called QRTest
  • Created a folder called libs in my project
  • Put the contents of the Zbar libs directory in the project folder
  • Right click on the zbar.jar file in my project and add it to the library
  • In my build.gradle file, edited it so that it is now:

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

  • Basically copied the sample code from the ZBar android SDK sample example into my own project.
  • The project compiles and works fine (0 errors, 0 warnings), but it crashes on failure. Magazines show:

09-01 16: 06: 02.026: W / dalvikvm (7050): Ljava exception / languages ​​/ UnsatisfiedLinkError; throws when initializing Lnet / SourceForge / Zbar / ImageScanner;

09-01 16: 06: 02.036: E / AndroidRuntime (7050): called: java.lang.UnsatisfiedLinkError: Unable to load library: link_image [1891]: 209 failed to load the 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 seems to die here:

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

Which seems to me that I somehow did not import the Zbar library files correctly. Any help on how to get this very simple example would be greatly appreciated!

Just note that if I use Android Studio to import a new project from the ZBar Android SDK example, it compiles and works fine. However, it uses the old ant build system. I would rather use the new gradle build system, which is why I am trying to import ZBar into a new Android 0.2.6 project. Thanks!

Another note: I tried changing my gradle assembly to the accepted answer here: How to change the libs directory in Gradle? and it didn’t work.

enter image description here

+3
source share
2 answers

You must add * .so libraries to your project. If you use Android Studio and Gradle, this is a bit complicated because you need to pack the libraries in a jar. Check my answer here: ZBar - QR code scanner, crashing in Android Studio to see more details.

+3
source

Decision:

  • Add zbar.jar to app / libs

  • Create a folder called jniLibs -Java Native Interface (JNI) under src / main and copy the armeabi-v7a, armeabi and x86 folder to src / main / jniLibs.

File structure as below:

Src / home / jniLibs / armeabi-v7a
Src / home / jniLibs / armeabi
Src / primary / jniLibs / x86

  1. Go to File> Project Structure> Application> Dependencies> Add Support-v4 to the Project
+12
source

Source: https://habr.com/ru/post/959310/


All Articles