Android下使用vim

2022-03-28  本文已影响0人  孤独的根号十二

很久没有写过文章了,今天给大家分享一下如何在Android系统中使用vim。
再用Linux系统中最常用的是编辑器就是vim,奈何Android系统中很多的命令行工具都没有。所以只能通过交叉编译生成Android的一些Linux常用命令。

环境准备:

步骤

1.在Linux主机中配置ndk环境

wget https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip
unzip android-ndk-r16-linux-x86_64.zip
$NDK/build/tools/make_standalone_toolchain.py --arch arm --api 19 --install-dir ~/ndk

所有的交叉编译工具会添加的ndk目录

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

2.下载并编译ncurses-5.6

wget https://github.com/mirror/ncurses/archive/v5.6.tar.gz
tar -zxvf  v5.6.tar.gz
#ifndef HAVE_LOCALE_H //加了这行和endif
#define HAVE_LOCALE_H 1
#endif

CFLAGS="-DHAVE_LOCALE_H=0" ./configure --host=arm-eabi --without-cxx-binding
make
export NCURSES=~/ncurses-5.6
source ~/.bash_profile

3.下载并编译vim

wget https://github.com/vim/vim/archive/v7.3.tar.gz
tar zxvf v7.3.tar.gz
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 /
上一篇下一篇

猜你喜欢

热点阅读