vim for Android编译

环境准备

  1. 下载ndk并解压:
    wget https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip
    unzip android-ndk-r16-linux-x86_64.zip
    
  2. 准备独立工具链:
    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环境的二进制工具链。
  3. 准备编译环境变量:
    # 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"
    
  4. 最终则可以使用make defconfig && make./configure && make来进行最终的编译。
  5. 参考链接:
    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

  1. 下载ncurses-5.6并解压:
    wget https://github.com/mirror/ncurses/archive/v5.6.tar.gz
    tar zxvf v5.6.tar.gz
    
  2. 进入ncurses-5.6目录并编译:
    cd ncurses-5.6
    ./configure --host=arm-eabi --without-cxx-binding
    make
    
  3. 参考链接:
    http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html

Trouble Shooting

  1. make过程中出现如下错误信息:
    error: undefined reference to 'localeconv'
    
  2. 解决方案:
    1. 修改文件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。
  1. 下载vim-7.3并解压:
    wget https://github.com/vim/vim/archive/v7.3.tar.gz
    tar zxvf v7.3.tar.gz
    
  2. 进入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
    
  3. 参考链接:
    http://credentiality2.blogspot.com/2010/08/native-vim-for-android.html

Trouble Shooting

  1. 执行configure时出现如下错误:
    error: could not compile program using uint32_t.
    
  2. 则需要打上如下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 -- [email protected] -- 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/vimruntime打包,推送到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

你可能感兴趣的:(vim for Android编译)