1:下载
到官网下载最新的libiconv库 http://ftp.gnu.org/pub/gnu/libiconv/ (1.14版本测试通过)解压到文件夹libiconv中
2:配置
打开Cygwin Terminal 进入解压文件目录
输入命令:
./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
3:编译
添加三个文件Android.mk,AndroidManifest.xml,jni/Application.mk
具体内容如下:
-
Android.mk
LOCAL_PATH:= $(call my-dir)
#libiconv.so
include $(CLEAR_VARS)
LOCAL_MODULE := libiconv
LOCAL_CFLAGS := \
-Wno-multichar \
-DANDROID \
-DLIBDIR="c" \
-DBUILDING_LIBICONV \
-DIN_LIBRARY
LOCAL_SRC_FILES := \
libcharset/lib/localcharset.c \
lib/iconv.c \
lib/relocatable.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/libcharset \
$(LOCAL_PATH)/lib \
$(LOCAL_PATH)/libcharset/include \
$(LOCAL_PATH)/srclib
include $(BUILD_STATIC_LIBRARY)
-
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.iconv.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
</manifest>
-
jni/Application.mk
APP_ABI := armeabi
APP_PLATFORM := android-9
APP_MODULES := libiconv
APP_PROJECT_PATH := $(shell pwd)
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
在目录下输入命令:
$NDK_PATH/ndk-build
如果成功得到下图输出
在目录obj/local/armeabi/ 下可以找到静态库 libiconv.a
4:错误处理
1. 编译时提示:
libiconv-1.14/jni/libcharset/lib/localcharset.c:51:24: error: langinfo.h: No such file or directory
解决方法:
修改目录文件libcharset/config.h的宏定义,禁止该宏定义:
/* Define if you haveand nl_langinfo(CODESET). */
#define HAVE_LANGINFO_CODESET 0
2. 提示错误:
报“c undeclaired”错误
解决方法:
修改文件/libcharset/lib/localcharset.c中函数get_charset_aliases (void)
搜索:int c;
把该变量定义放到该函数的开始处。