This post describes the approach that I used to NDK compile the Zbar bar code / QR code source code into a native Android library.
Preparing the Workspace
Create 2 new folders in your eclipse workspace – jni and libs
Download the Zbar source tarball from SourceForge – http://zbar.sourceforge.net/download.html
Now open the tarball and locate the zbar folder.
Extract the contents of the zbar folder into the jni folder in your Eclipse workspace. You will also need to extract the zbar.h file from the include folder to the jni folder in your Eclipse workspace. Then download the ZBarAndroidPatch and unzip into the jni folder. The directory structure should look something like this:
You now need to code the JNI wrapper class that will be used to call the ZBar library. The following is an example of the source code for this class:
Generate JNI header
After the Eclipse workspace is setup you are ready to generate the JNI header for your wrapper class. To do this, you need to use the Java Header File Generator javah which can be found in the Java JDK. Go to the classes directory and run javah against your wrapper class:
This will generate a C header file. Copy this header file into the jni directory and edit the android_zbar.c source file to align with the newly generated JNI header:
Build the Library
You are now ready to NDK build the ZBar library. In the jni directory run the ndk-build command:
All going well, this should build the libzbar.so library:
Copy ZBar Library Into Workspace
The last step is to copy the ZBar library back into your eclipse workspace. Copy the armeabi directory (including the libzbar.so file) into the libs directory of your workspace:
Using the Library
To use the native ZBar library, simply call the method on your JNI wrapper class: