很久没有写过文章了,今天给大家分享一下如何在Android系统中使用vim。
再用Linux系统中最常用的是编辑器就是vim,奈何Android系统中很多的命令行工具都没有。所以只能通过交叉编译生成Android的一些Linux常用命令。
环境准备:
- 一个root的手机/一个模拟器
- 一个Linux主机(vmware/云服务器)
步骤
1.在Linux主机中配置ndk环境
- 下载ndk并解压 (在home目录)
wget https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip
unzip android-ndk-r16-linux-x86_64.zip
- 配置ndk
$NDK/build/tools/make_standalone_toolchain.py --arch arm --api 19 --install-dir ~/ndk
所有的交叉编译工具会添加的ndk目录
- 配置.bash_profile
export ANDROID_NDK=~/android-ndk-r16
export PATH=$ANDROID_NDK:$PATH
export NDK=~/ndk
export PATH=$PATH:$NDK/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"
- source一下.bash_profile
source ~/.bash_profile
2.下载并编译ncurses-5.6
- 下载ncurses-5.6
wget https://github.com/mirror/ncurses/archive/v5.6.tar.gz
tar -zxvf v5.6.tar.gz
- 修改
include/ncurses_cfg.h
#ifndef HAVE_LOCALE_H //加了这行和endif
#define HAVE_LOCALE_H 1
#endif
- 编译ncurses-5.6
CFLAGS="-DHAVE_LOCALE_H=0" ./configure --host=arm-eabi --without-cxx-binding
make
- 继续配置.bash_profile,加上一句
export NCURSES=~/ncurses-5.6
- source一下.bash_profile
source ~/.bash_profile
3.下载并编译vim
- 下载vim-7.3并解压
wget https://github.com/vim/vim/archive/v7.3.tar.gz
tar zxvf v7.3.tar.gz
- 创建vim.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 ///
- 编译编译脚本并执行
#!/bin/bash
cp vim.patch vim-7.3
cd vim-7.3
patch -p0 < vim.patch
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 -pie -fPIE" \
CFLAGS="-I$NCURSES/lib -pie -fPIE" \
vim_cv_toupper_broken=no \
./configure --host=arm-eabi --with-tlib=ncurses
make
4.把编译的vim放入Android的/bin目录
- 比较简单不在介绍
需要主要的是如果是真机可能会因为只读的文件系统放不进去
可使用下述命令重新挂载,在复制
su
mount -o rw,remount /