环境准备
- 下载ndk并解压:
wget https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip unzip android-ndk-r16-linux-x86_64.zip
- 准备独立工具链:
cd android-ndk-r16 export NDK=`pwd` export NDK19=~/ndk19 $NDK/build/tools/make_standalone_toolchain.py --arch arm --api 19 --install-dir ~/ndk19
- 这里创建了名为~/ndk19的目录,其中包含了android-19/arch-arm系统根目录,以及32位arm环境的二进制工具链。
- 准备编译环境变量:
# Add the standalone toolchain to the search path. export PATH=$PATH:$NDK19/bin # Tell configure what tools to use. target_host=arm-linux-androideabi export AR=$target_host-ar export AS=$target_host-clang export CC=$target_host-clang export CXX=$target_host-clang++ export LD=$target_host-ld export STRIP=$target_host-strip # Tell configure what flags Android requires. export CFLAGS="-fPIE -fPIC" export LDFLAGS="-pie"
- 最终则可以使用
make defconfig && make
或./configure && make
来进行最终的编译。 - 参考链接:
https://developer.android.com/ndk/guides/standalone_toolchain.html#creating_the_toolchain
http://credentiality2.blogspot.com/2010/08/native-android-c-program-using-ndk.html
ncurses-5.6
- 下载ncurses-5.6并解压:
wget https://github.com/mirror/ncurses/archive/v5.6.tar.gz tar zxvf v5.6.tar.gz
- 进入ncurses-5.6目录并编译:
cd ncurses-5.6 ./configure --host=arm-eabi --without-cxx-binding make
- 参考链接:
http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html
Trouble Shooting
-
make
过程中出现如下错误信息:error: undefined reference to 'localeconv'
- 解决方案:
- 修改文件
include/ncurses_cfg.h
,将:
修改为:#define HAVE_LOCALE_H 1
#define HAVE_LOCALE_H 0
- 修改文件
vim-7.3
- 开始使用vim-7.4编译,发现依赖boost,但android环境无boost,则换用vim-7.3。
- 下载vim-7.3并解压:
wget https://github.com/vim/vim/archive/v7.3.tar.gz tar zxvf v7.3.tar.gz
- 进入vim-7.4目录并编译:
cd vim-7.4 export NCURSES=/home/ubuntu/repo/ncurses-5.6 vim_cv_memcpy_handles_overlap=no \ vim_cv_bcopy_handles_overlap=no \ vim_cv_memmove_handles_overlap=no \ vim_cv_stat_ignores_slash=no \ vim_cv_getcwd_broken=no \ vim_cv_tty_group=world \ vim_cv_terminfo=yes \ LDFLAGS="-L$NCURSES/lib" \ CFLAGS="-I$NCURSES/lib" \ vim_cv_toupper_broken=no \ ./configure --host=arm-eabi --with-tlib=ncurses make
- 参考链接:
http://credentiality2.blogspot.com/2010/08/native-vim-for-android.html
Trouble Shooting
- 执行
configure
时出现如下错误:error: could not compile program using uint32_t.
- 则需要打上如下patch文件:
Patch 7.3.378 Problem: When cross-compiling the check for uint32_t fails. Solution: Only give a warning message. (Maksim Melnikau) Files: src/configure.in, src/auto/configure *** ../vim-7.3.377/src/configure.in 2011-12-08 15:17:28.000000000 +0100 --- src/configure.in 2011-12-14 19:18:36.000000000 +0100 *************** *** 3283,3289 **** }], AC_MSG_RESULT(ok), AC_MSG_ERROR([WRONG! uint32_t not defined correctly.]), ! AC_MSG_ERROR([could not compile program using uint32_t.])) dnl Check for memmove() before bcopy(), makes memmove() be used when both are dnl present, fixes problem with incompatibility between Solaris 2.4 and 2.5. --- 3283,3289 ---- }], AC_MSG_RESULT(ok), AC_MSG_ERROR([WRONG! uint32_t not defined correctly.]), ! AC_MSG_WARN([cannot check uint32_t when cross-compiling.])) dnl Check for memmove() before bcopy(), makes memmove() be used when both are dnl present, fixes problem with incompatibility between Solaris 2.4 and 2.5. *** ../vim-7.3.377/src/auto/configure 2011-12-08 15:17:28.000000000 +0100 --- src/auto/configure 2011-12-14 19:20:55.000000000 +0100 *************** *** 11777,11783 **** { $as_echo "$as_me:${as_lineno-$LINENO}: checking uint32_t is 32 bits" >&5 $as_echo_n "checking uint32_t is 32 bits... " >&6; } if test "$cross_compiling" = yes; then : ! as_fn_error "could not compile program using uint32_t." "$LINENO" 5 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ --- 11777,11784 ---- { $as_echo "$as_me:${as_lineno-$LINENO}: checking uint32_t is 32 bits" >&5 $as_echo_n "checking uint32_t is 32 bits... " >&6; } if test "$cross_compiling" = yes; then : ! { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot check uint32_t when cross-compiling." >&5 ! $as_echo "$as_me: WARNING: cannot check uint32_t when cross-compiling." >&2;} else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ *** ../vim-7.3.377/src/version.c 2011-12-14 15:32:44.000000000 +0100 --- src/version.c 2011-12-14 19:21:08.000000000 +0100 *************** *** 716,717 **** --- 716,719 ---- { /* Add new patch number below this line */ + /**/ + 378, /**/ -- ### Hiroshima 45, Chernobyl 86, Windows 95 ### /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
安装
将src/vim
和runtime
打包,推送到Android系统的/data/vim
目录,其中需要给/data/vim/vim
加上可执行权限,再在/vendor/bin
目录下添加如下内容到文件vim,并赋予可执行权限即可:
export TERM=xterm
export VIMRUNTIME=/data/vim/runtime
/data/vim/vim $1
运行时出现如下错误:
E437: terminal capability "cm" required
这是因为是环境变量TERM没有设置或者配置错误导致,只需要执行如下命令即可:
export TERM=xterm