2017/11/20 追記
Android 5.0以上ならTermuxでnkfをコンパイルして使用できます →
Termuxの備忘録
追記ここまで
PerlのEncodeをAndroid用に作成するのは難しいので、nkfをコンパイルすることに。
#JIS, Shift JIS, EUC, UTF-8が扱えればOKなので。
nkfのソースを
http://sourceforge.jp/projects/nkf/ から取得。
これを書いている時点での最新バージョンは2.1.2。
ダウンロードしたnkf-2.1.2.tar.gzからコンパイルに必要なファイル
config.h
nkf.c
nkf.h
utf8tbl.c
utf8tbl.h
の5ファイルを~/nkf/jni/ (ディレクトリは前もって作成)にコピー。
Android.mkの内容は、
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := nkf
LOCAL_SRC_FILES := nkf.c utf8tbl.c
include $(BUILD_EXECUTABLE)
で、コンパイル。
$ ~/android-ndk-r6/ndk-build
Compile thumb : nkf <= nkf.c
In file included from /home/xxxxx/nkf/jni/nkf.c:30:
/home/xxxxx/nkf/jni/nkf.h:166:22: error: langinfo.h: No such file or directory
/home/xxxxx/nkf/jni/nkf.c: In function 'nkf_locale_charmap':
/home/xxxxx/nkf/jni/nkf.c:756: error: 'CODESET' undeclared (first use in this function)
/home/xxxxx/nkf/jni/nkf.c:756: error: (Each undeclared identifier is reported only once
/home/xxxxx/nkf/jni/nkf.c:756: error: for each function it appears in.)
make: *** [/home/xxxxx/nkf/obj/local/armeabi/objs/nkf/nkf.o] エラー 1
langinfo.hが無くてエラーとなっている。
KMC Staff Blog:RubyをAndroid用にビルドする を参考にnkf.hを修正。
$ diff -u nkf.h.org nkf.h
--- nkf.h.org 2011-09-08 21:02:30.000000000 +0900
+++ nkf.h 2012-02-10 23:44:10.000000000 +0900
@@ -153,6 +153,10 @@
# ifndef HAVE_LOCALE_H
# define HAVE_LOCALE_H
# endif
+#elif defined(__ANDROID__)
+# ifndef HAVE_LOCALE_H
+# define HAVE_LOCALE_H
+# endif
#else
# ifndef HAVE_LANGINFO_H
# define HAVE_LANGINFO_H
でコンパイルし直し。
Compile thumb : nkf <= nkf.c
Compile thumb : nkf <= utf8tbl.c
Executable : nkf
Install : nkf => libs/armeabi/nkf
実機で動くことを確認。
2013/05/19追記:
Android用のnkfをコンパイル その2 でコンパイルしたものを置いてます。