aaashun's site

home

using aimake to build libiconv for android

08 May 2013

今日一同事在android项目中用到iconv, 需要编译一个android版的静态库, 折腾了好久也没编译成功. 直接使用ndk编译libiconv关键是配置好交叉编译文件(Android.mk), 这里给出一份更简单的方法.

将如下内容保存在aimakefile

mk := 'LOCALMODULE := iconv\n\n'
mk += 'LOCALCFLAGS := -DHAVECONFIGH -DBUILDINGLIBICONV -DBUILDINGDLL -DENABLERELOCATABLE=1 -DINLIBRARY -DNOXMALLOC -DLIBDIR=\"\" -Dsetrelocationprefix=libiconvsetrelocationprefix -Drelocate=libiconvrelocate -I .  -I include -I libcharset/include -I lib -I libcharset/lib\n\n'
mk += 'LOCALSRCFILES := lib/iconv.c libcharset/lib/localcharset.c lib/relocatable.c\n\n'
mk += 'include $$(BUILDSTATICLIBRARY)\n\n'
mk += 'install:\n'
mk += '\tcp include/iconv.h $$(PLATFORM)/usr/include\n'
mk += '\tcp libiconv.a $$(PLATFORM)/usr/lib'
all:
	@rm -rf libiconv*
	@echo "downloading libiconv ..."
	@wget -q -O /dev/stdout http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz | tar -xzf /dev/stdin
	@mv libiconv-* libiconv
	@echo -e $(mk) > libiconv/aimakefile
	@sed -i -e 's/-e //' -e 's/^ //' libiconv/aimakefile
	@cd libiconv; ./configure;
	@sed -i '/HAVELANGINFOCODESET/s/1/0/' libiconv/config.h
	@sed -i '/HAVELANGINFOCODESET/s/1/0/' libiconv/lib/config.h
	@sed -i '/HAVELANGINFO_CODESET/s/1/0/' libiconv/libcharset/config.h
	@cd libiconv; aimake -t android clean all install;

编译android平台的libiconv, 执行完如下命令会在libiconv目录下生成android版本的libiconv.a, 并且自动将iconv.h和libiconv.a安装到android-ndk/platforms/android-3/arch-arm目录下

aimake

aimake是基于gnu make的一个简单编译工具, 支持ios, android, linux, darwin, mingw32, 等平台的编译和交叉编译. https://github.com/ashun/aimake


参考:

comments powered by Disqus