How to integrate zbar Library in a cocos2dx Game

Hello,

I have lost a couple of days to figure this out so maybe this will help someone and save them some time.

My scenario was like this: I have a game written in Cocos2dX for iPhone and Android and one of the features needed was to scan a qr code, so I have chosen zbar for both implementations.
On iPhone was pretty straight forward, as it is very easy to mix c++ with obj c and so adding a new view controller for zbar view did the trick.
For Android the principle is almost the same, but the project kept crashing until I have done this steps:

  1. download this zbar library project I have found on zbar forum: https://github.com/DushyanthMaguluru/ZBarScanner
  2. add the project as library to your project
  3. move libgame.so from your project to ZBarScanner project
  4. Change first part of Android.mk to look like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := iconv

LOCAL_MODULE_FILENAME := libiconv

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

………………………………………………………………

That’s it. I don’t know if this is the best way to do it but now the project is working just fine.
To call zbar screens from cocos2dx you should use JNI as described here: [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_use_jni]]

Thank you for this great cocos2d port!

Hi Condor thanks for your hardwork, i am a newbie on cocos2dx, did you mind demo how to integrate zbar into ios project?

Hi,

It’s been a while since I used zbar, but on their site it is a pretty good tutorial for including zbar on a ios project:
http://zbar.sourceforge.net/iphone/sdkdoc/install.html
Hope this helps

barry hung wrote:

Hi Condor thanks for your hardwork, i am a newbie on cocos2dx, did you mind demo how to integrate zbar into ios project?