How to build linux tools for Android

Prepare toolchain for Android

  1. Prepare Linux.
    • I recommend to use Ubuntu 14.04 LTS.
  2. Download Android NDK for Linux
  3. Make directory to install standalone toolchain
    • sudo mkdir /data and change owner to your user account.
  4. Make standalone toolchain from Android NDK
  5. Change directory to NDK root, and run build/tools/make-standalone-toolchain.sh --platform=android-8 --install-dir=/data/toolchain-arm
  6. Set environment variables

    export PATH=export PATH=/data/toolchain-arm/bin:/data/bin/:$PATH
    
    export PREFIX=/data/data/jackpal.androidterm/app_HOME/local
    export CC=arm-linux-androideabi-gcc
    export LD=arm-linux-androideabi-ld
    export CXX=arm-linux-androideabi-c++
    export AR=arm-linux-androideabi-ar
    export RANLIB=arm-linux-androideabi-ranlib
    export HOSTCONFIG=arm-linux-androideabi
    

A general method to build

  1. Run configure with options
    • ./configure --prefix $PREFIX --host $HOSTCONFIG LIBS="-L/data/data/jackpal.androidterm/app_HOME/local/lib" CFLAGS="-I/data/data/jackpal.androidterm/app_HOME/local/include"
  2. Run make

Since libc of Android is not full set of standard C library, compile error is not strange. If a missing function is required in a software, there are two way to fix it. One of them is patching to remove dependency, and the other is copy the required function from other C library.

Another common reason of compile error is failure of configure. Because of cross compile, configure often failed to detect functions and libraries. To resolve this problem, make a patch for sources. Another way to resolve is to run configure with --config-cache, and fix config.cache.

Configuration and patches

zlib 1.2.8

zlib is compression library.

./configure --prefix $PREFIX
make
make install

dropbear 2014.63

dropbear is tiny ssh client/server. To build, apply patch first.

./configure --prefix $PREFIX --host $HOSTCONFIG --disable-syslog --disable-loginfunc --with-zlib=/data/data/jackpal.androidterm/app_HOME/local --disable-utmp --disable-utmpx --disable-wtmp --disable-wtmpx --disable-pututline --disable-pututxline --without-pam
make
make install

ncurses 5.9

ncurses is collection of escape sequence and library of terminal manipulation. To build, apply patch first.

./configure --prefix $PREFIX --host $HOSTCONFIG
make
make install