error: iconv.h: No such file or directory
In fact there is currently no iconv.h available in the Android NDK and you will have to port libiconv to Android yourself.
I successfully used the following instructions to cross-compile libiconv.so for Android.
Get the source code for libconv-1.13.1:
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
Unzip and untar the file:
$ tar zxvf
libiconv-1.13.1.tar.gz
Patch localcharset.c using the following patch file (or else you will get another error: : langinfo.h: No such file or directory) :
$ echo "diff --ignore-file-name-case -wuprN libiconv-1.13.1.orig/libcharset/lib/localcharset.c libiconv-1.13.1/libcharset/lib/localcharset.c
--- libiconv-1.13.1.orig/libcharset/lib/localcharset.c 2009-06-21 07:17:33.000000000 -0400
+++ libiconv-1.13.1/libcharset/lib/localcharset.c 2012-12-18 10:20:27.000000000 -0500
@@ -44,7 +44,7 @@
# endif
#endif
-#if !defined WIN32_NATIVE
+#if !defined(WIN32_NATIVE) && !defined(__ANDROID__)
# if HAVE_LANGINFO_CODESET
# include <langinfo.h>
# else
@@ -328,7 +328,7 @@ locale_charset (void)
const char *codeset;
const char *aliases;
-#if !(defined WIN32_NATIVE || defined OS2)
+#if !(defined WIN32_NATIVE || defined OS2 || defined __ANDROID__)
# if HAVE_LANGINFO_CODESET " > iconv.patch
$ patch -b -p0 < ./iconv.patch
--- libiconv-1.13.1.orig/libcharset/lib/localcharset.c 2009-06-21 07:17:33.000000000 -0400
+++ libiconv-1.13.1/libcharset/lib/localcharset.c 2012-12-18 10:20:27.000000000 -0500
@@ -44,7 +44,7 @@
# endif
#endif
-#if !defined WIN32_NATIVE
+#if !defined(WIN32_NATIVE) && !defined(__ANDROID__)
# if HAVE_LANGINFO_CODESET
# include <langinfo.h>
# else
@@ -328,7 +328,7 @@ locale_charset (void)
const char *codeset;
const char *aliases;
-#if !(defined WIN32_NATIVE || defined OS2)
+#if !(defined WIN32_NATIVE || defined OS2 || defined __ANDROID__)
# if HAVE_LANGINFO_CODESET " > iconv.patch
$ patch -b -p0 < ./iconv.patch
Run the configure script and generate iconv.h:
$ cd libiconv-1.13.1
$ ./configure
Create a jni sub-directory:
$ ./configure
$ mkdir jni
And save the following lines in jni/Android.mk:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) TARGET_ARCH_ABI := armeabi-v7a LOCAL_MODULE := iconv LOCAL_CFLAGS := \ -Wno-multichar \ -D_ANDROID \ -DLIBDIR="\"c\"" \ -DBUILDING_LIBICONV \ -DIN_LIBRARY LOCAL_C_INCLUDES := \ ../libiconv-1.13.1 \ ../libiconv-1.13.1/include \ ../libiconv-1.13.1/lib \ ../libiconv-1.13.1/libcharset/include LOCAL_SRC_FILES := \ ../libiconv-1.13.1/lib/iconv.c \ ../libiconv-1.13.1/lib/relocatable.c \ ../libiconv-1.13.1/libcharset/lib/localcharset.c include $(BUILD_SHARED_LIBRARY)
Finally cross-compile iconv using the ndk-build tool:
$ cd jni
$ ndk-build V=1
If everything goes well, you will find iconv.h under libiconv-1.13.1/include and libiconv.so under libs/armeabi.
$ ndk-build V=1