zbar android sdk在CentOS 7下的编译和使用

环境:CentOS 7+NDK 20.0.5594570+libiconv-1.14

下载

下载libiconv-1.14版本,地址: https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

下载zbar,地址:https://github.com/ZBar/ZBar

编译libiconv-1.14

1.执行./configure

2.执行make

报错,提示 error: ‘gets’ undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

解决办法:
cd srclib
sed -i -e '/gets is a security/d' ./stdio.in.h

 编译zbar

1.解压ZBar-master.zip,将刚才编译好的libiconv-1.14文件夹,java/zbarjni.c文件,zbar文件夹,include文件夹复制到android/jni目录下,

最后的目录结构如下:

2.修改android/AndroidManifest.xml文件,修改后的文件如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="net.sourceforge.zbar.android"
      android:versionCode="1"
      android:versionName="1.0">
  <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="28" />
    <application android:label="@string/app_name" >
        <activity android:name="ACTIVITY_ENTRY_NAME"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

3.修改android/project.properties,修改target值为系统支持的最低版本,如android-19

4.修改Android.mk,如下:

#
# Android NDK makefile 
#
# build - <ndk path>/ndk-build ICONV_SRC=<iconv library src> 
# clean -  <ndk path>/ndk-build clean
#
MY_LOCAL_PATH := $(call my-dir)

ICONV_SRC := $(MY_LOCAL_PATH)/libiconv-1.14

# libiconv
include $(CLEAR_VARS)
LOCAL_PATH := $(ICONV_SRC)

LOCAL_MODULE := libiconv

LOCAL_CFLAGS := \
    -Wno-multichar \
    -D_ANDROID \
    -DLIBDIR="c" \
    -DBUILDING_LIBICONV \
    -DBUILDING_LIBCHARSET \
    -DIN_LIBRARY

LOCAL_SRC_FILES := \
    $(ICONV_SRC)/lib/iconv.c \
    $(ICONV_SRC)/libcharset/lib/localcharset.c \
    $(ICONV_SRC)/lib/relocatable.c

LOCAL_C_INCLUDES := \
    $(ICONV_SRC)/include \
    $(ICONV_SRC)/libcharset \
    $(ICONV_SRC)/libcharset/include

include $(BUILD_SHARED_LIBRARY)

LOCAL_LDLIBS := -llog -lcharset

# libzbarjni
include $(CLEAR_VARS)

LOCAL_PATH := $(MY_LOCAL_PATH)
LOCAL_MODULE := zbarjni
LOCAL_SRC_FILES := zbarjni.c \
           zbar/img_scanner.c \
           zbar/decoder.c \
           zbar/image.c \
           zbar/symbol.c \
           zbar/convert.c \
           zbar/config.c \
           zbar/scanner.c \
           zbar/error.c \
           zbar/refcnt.c \
           zbar/video.c \
           zbar/video/null.c \
           zbar/decoder/code128.c \
           zbar/decoder/code39.c \
           zbar/decoder/code93.c \
           zbar/decoder/codabar.c \
           zbar/decoder/databar.c \
           zbar/decoder/ean.c \
           zbar/decoder/i25.c \
           zbar/decoder/qr_finder.c \
           zbar/qrcode/bch15_5.c \
           zbar/qrcode/binarize.c \
           zbar/qrcode/isaac.c \
           zbar/qrcode/qrdec.c \
           zbar/qrcode/qrdectxt.c \
           zbar/qrcode/rs.c \
           zbar/qrcode/util.c

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \
            $(LOCAL_PATH)/zbar \
            $(ICONV_SRC)/include 

LOCAL_SHARED_LIBRARIES := libiconv

include $(BUILD_SHARED_LIBRARY)

5.修改Application.mk,如下:

APP_ABI := armeabi-v7a

6.切换到android/jni目录下,执行ndk-build命令

报错,如下:

解决办法:

修改libiconv-1.14/libcharset/config.h第14行,修改后的内容如下:#define HAVE_LANGINFO_CODESET 0

 报错,如下:

解决办法:

修改文件libiconv-1.14/libcharset/lib/localcharset.c文件中函数get_charset_aliases (void),搜索:int c;把该变量定义放到该函数的开始处

 

继续编译,大功告成,在android/libs/armeabi-v7a目录下就可以看到生成的文件了

zbar的具体编译demo可参考:https://github.com/kongpf8848/zbar-android

zbar的具体使用demo可参考:https://github.com/kongpf8848/zbarcamera

 

posted @ 2019-07-18 17:28  南极冰川雪  阅读(444)  评论(0编辑  收藏  举报