1Building Android binary 2======================= 3 4In this article, we briefly describe how to build Android binary using 5`Android NDK <https://developer.android.com/ndk>`_ cross-compiler on 6Debian Linux. 7 8The easiest way to build android binary is use Dockerfile.android. 9See Dockerfile.android for more details. If you cannot use 10Dockerfile.android for whatever reason, continue to read the rest of 11this article. 12 13We offer ``android-config`` script to make the build easier. To make 14the script work, NDK directory must be set to ``NDK`` environment 15variable. NDK directory is the directory where NDK is unpacked: 16 17.. code-block:: text 18 19 $ unzip android-ndk-$NDK_VERSION-linux.zip 20 $ cd android-ndk-$NDK_VERSION 21 $ export NDK=$PWD 22 23The dependent libraries, such as OpenSSL, libev, and c-ares should be 24built with the same NDK toolchain and installed under 25``$NDK/usr/local``. We recommend to build these libraries as static 26library to make the deployment easier. libxml2 support is currently 27disabled. 28 29Although zlib comes with Android NDK, it seems not to be a part of 30public API, so we have to built it for our own. That also provides us 31proper .pc file as a bonus. 32 33Before running ``android-config``, ``NDK`` environment variable must 34be set to point to the correct path. 35 36You need to set ``NGHTTP2`` environment variable to the absolute path 37to the source directory of nghttp2. 38 39To configure OpenSSL, use the following script: 40 41.. code-block:: sh 42 43 #!/bin/sh 44 45 . $NGHTTP2/android-env 46 47 export ANDROID_NDK_HOME=$NDK 48 export PATH=$TOOLCHAIN/bin:$PATH 49 50 ./Configure no-shared --prefix=$PREFIX android-arm64 51 52And run the following script to build and install without 53documentation: 54 55.. code-block:: sh 56 57 #!/bin/sh 58 59 . $NGHTTP2/android-env 60 61 export PATH=$TOOLCHAIN/bin:$PATH 62 63 make install_sw 64 65To configure libev, use the following script: 66 67.. code-block:: sh 68 69 #!/bin/sh 70 71 . $NGHTTP2/android-env 72 73 ./configure \ 74 --host=$TARGET \ 75 --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 76 --prefix=$PREFIX \ 77 --disable-shared \ 78 --enable-static \ 79 CPPFLAGS=-I$PREFIX/include \ 80 LDFLAGS=-L$PREFIX/lib 81 82And run ``make install`` to build and install. 83 84To configure c-ares, use the following script: 85 86.. code-block:: sh 87 88 #!/bin/sh -e 89 90 . $NGHTTP2/android-env 91 92 ./configure \ 93 --host=$TARGET \ 94 --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 95 --prefix=$PREFIX \ 96 --disable-shared 97 98And run ``make install`` to build and install. 99 100To configure zlib, use the following script: 101 102.. code-block:: sh 103 104 #!/bin/sh -e 105 106 . $NGHTTP2/android-env 107 108 export HOST=$TARGET 109 110 ./configure \ 111 --prefix=$PREFIX \ 112 --libdir=$PREFIX/lib \ 113 --includedir=$PREFIX/include \ 114 --static 115 116And run ``make install`` to build and install. 117 118After prerequisite libraries are prepared, run ``android-config`` and 119then ``make`` to compile nghttp2 source files. 120 121If all went well, application binaries, such as nghttpx, are created 122under src directory. Strip debugging information from the binary 123using the following command: 124 125.. code-block:: text 126 127 $ $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip src/nghttpx 128