Android Studio 0.2.6 and ZBar project setup

a 夏天 提交于 2019-12-01 20:08:37

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/18556114/android-studio-0-2-6-and-zbar-project-setup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!