Skip to content
Mark Johnson edited this page Mar 11, 2018 · 12 revisions

<-- 'List of Themes'

<-- 'List of Projects'


Creating toolchains from the installed ndk

The original documentation for this theme can be found here:


  • Goal is to call ./configure for a specific project, using a specific target
    • armeabi-v7a 32-bit
    • arm64-v8a 64-bit
    • x86_64 64-bit
      • such as this project that contains arm specific source code not used in X86

NDK

First you must download the latest ndk from here:

wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip

At the time of writing it is version r16b

I have placed this in long/path/to/adt-bundle-linux/archive

and unziped the archive to long/path/to/adt-bundle-linux/ndk

so that you now have a directory called:

  • long/path/to/adt-bundle-linux/ndk/android-ndk-r16b

Inside the ndk directory, I created a toolchains directory

  • long/path/to/adt-bundle-linux/ndk/toolchains

This is where the needed toolchains will be stored.

Inside the android-ndk-r16b/build/tools directory

  • there you will find a python script: make_standalone_toolchain.py
    • Note: the same of the original page uses a faulty syntax
      • all parameters are *without the = between the parameter and value

From inside this directory you can call the script with --help

./make_standalone_toolchain.py --help

  --arch {arm,arm64,mips,mips64,x86,x86_64}
  --api API             Target the given API version (example: "--api 24").
  --stl {gnustl,**libc++**,stlport}
  --install-dir INSTALL_DIR
                        Install toolchain to the given directory instead of
                        packaging.

I will be creating for:

  • arm,arm64,x86_64
  • --api 21

to be stored in

  • long/path/to/adt-bundle-linux/ndk/toolchains/
    • arm32.21
    • arm64.21
    • x8664.21

Call from ndk/android-ndk-r16b/build/tools

./make_standalone_toolchain.py --arch arm --api 21 --stl libc++ --install-dir /home/mj10777/000_links/gnu_source/adt-bundle-linux/ndk/toolchains/arm32.21

./make_standalone_toolchain.py --arch arm64 --api 21 --stl libc++ --install-dir /home/mj10777/000_links/gnu_source/adt-bundle-linux/ndk/toolchains/arm64.21

./make_standalone_toolchain.py --arch x86_64 --api 21 --stl libc++ --install-dir /home/mj10777/000_links/gnu_source/adt-bundle-linux/ndk/toolchains/x8664.21

After a few minutes, you will find that the 2 directories have been created and filled.

Now come the important part: which target triplets must be used.

Sample arm64, which was created in directory arm64.21

Look inside the arm64.21/bin directory:

  • look for any file that ends with
    • -ar, -c++,, -cpp, -gcc, -g++
      • aarch64-linux-android-g++
        • aarch64-linux-android is the target triplet
          • used for the --host parameter of ./configure
    • aarch64-linux-android will exist as a directory

call.arm64.sh

#/bin/bash
#--------------------------------------
ANDROID_NDK="/home/mj10777/000_links/gnu_source/adt-bundle-linux/ndk";
ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/arm64.21";
ANDROID_TOOLCHAIN_BIN="${ANDROID_TOOLCHAIN}/bin";
# Add the standalone toolchain to the search path.
export PATH=$PATH:${ANDROID_TOOLCHAIN_BIN}
#--------------------------------------
build_host=x86_64-pc-linux-gnu
#--------------------------------------
# Tell configure what tools to use.
target_host=aarch64-linux-android
#--------------------------------------
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"
#--------------------------------------
./configure  --host=${target_host}  --build=${build_host}
#--------------------------------------


2018-03-11: Mark Johnson, Berlin Germany


Clone this wiki locally