2014-08-17 12:15:19 +02:00
|
|
|
Building Android binary
|
|
|
|
=======================
|
|
|
|
|
|
|
|
In this article, we briefly describe how to build Android binary using
|
2022-09-26 10:04:42 +02:00
|
|
|
`Android NDK <https://developer.android.com/ndk>`_ cross-compiler on
|
|
|
|
Debian Linux.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2014-10-19 14:51:43 +02:00
|
|
|
The easiest way to build android binary is use Dockerfile.android.
|
|
|
|
See Dockerfile.android for more details. If you cannot use
|
|
|
|
Dockerfile.android for whatever reason, continue to read the rest of
|
|
|
|
this article.
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
We offer ``android-config`` script to make the build easier. To make
|
|
|
|
the script work, NDK directory must be set to ``NDK`` environment
|
|
|
|
variable. NDK directory is the directory where NDK is unpacked:
|
2016-07-16 12:07:31 +02:00
|
|
|
|
|
|
|
.. code-block:: text
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
$ unzip android-ndk-$NDK_VERSION-linux.zip
|
|
|
|
$ cd android-ndk-$NDK_VERSION
|
|
|
|
$ export NDK=$PWD
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2016-12-21 15:47:34 +01:00
|
|
|
The dependent libraries, such as OpenSSL, libev, and c-ares should be
|
2022-09-26 10:04:42 +02:00
|
|
|
built with the same NDK toolchain and installed under
|
|
|
|
``$NDK/usr/local``. We recommend to build these libraries as static
|
|
|
|
library to make the deployment easier. libxml2 support is currently
|
|
|
|
disabled.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2015-06-01 16:14:38 +02:00
|
|
|
Although zlib comes with Android NDK, it seems not to be a part of
|
|
|
|
public API, so we have to built it for our own. That also provides us
|
|
|
|
proper .pc file as a bonus.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
Before running ``android-config``, ``NDK`` environment variable must
|
|
|
|
be set to point to the correct path.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
You need to set ``NGHTTP2`` environment variable to the absolute path
|
|
|
|
to the source directory of nghttp2.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2014-12-03 15:09:16 +01:00
|
|
|
To configure OpenSSL, use the following script:
|
|
|
|
|
|
|
|
.. code-block:: sh
|
2014-08-17 12:15:19 +02:00
|
|
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
. $NGHTTP2/android-env
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
export ANDROID_NDK_HOME=$NDK
|
|
|
|
export PATH=$TOOLCHAIN/bin:$PATH
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
./Configure no-shared --prefix=$PREFIX android-arm64
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
And run the following script to build and install without
|
|
|
|
documentation:
|
2014-12-03 15:09:16 +01:00
|
|
|
|
|
|
|
.. code-block:: sh
|
2014-08-17 12:15:19 +02:00
|
|
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
. $NGHTTP2/android-env
|
|
|
|
|
|
|
|
export PATH=$TOOLCHAIN/bin:$PATH
|
|
|
|
|
|
|
|
make install_sw
|
|
|
|
|
|
|
|
To configure libev, use the following script:
|
|
|
|
|
|
|
|
.. code-block:: sh
|
|
|
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. $NGHTTP2/android-env
|
2014-08-17 12:15:19 +02:00
|
|
|
|
|
|
|
./configure \
|
2022-09-26 10:04:42 +02:00
|
|
|
--host=$TARGET \
|
2014-08-17 12:15:19 +02:00
|
|
|
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
|
|
|
|
--prefix=$PREFIX \
|
|
|
|
--disable-shared \
|
|
|
|
--enable-static \
|
|
|
|
CPPFLAGS=-I$PREFIX/include \
|
|
|
|
LDFLAGS=-L$PREFIX/lib
|
|
|
|
|
|
|
|
And run ``make install`` to build and install.
|
|
|
|
|
2016-12-21 15:47:34 +01:00
|
|
|
To configure c-ares, use the following script:
|
|
|
|
|
|
|
|
.. code-block:: sh
|
|
|
|
|
|
|
|
#!/bin/sh -e
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
. $NGHTTP2/android-env
|
2016-12-21 15:47:34 +01:00
|
|
|
|
|
|
|
./configure \
|
2022-09-26 10:04:42 +02:00
|
|
|
--host=$TARGET \
|
2016-12-21 15:47:34 +01:00
|
|
|
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
|
|
|
|
--prefix=$PREFIX \
|
|
|
|
--disable-shared
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
And run ``make install`` to build and install.
|
|
|
|
|
2015-06-01 16:14:38 +02:00
|
|
|
To configure zlib, use the following script:
|
|
|
|
|
|
|
|
.. code-block:: sh
|
|
|
|
|
|
|
|
#!/bin/sh -e
|
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
. $NGHTTP2/android-env
|
|
|
|
|
|
|
|
export HOST=$TARGET
|
|
|
|
|
2015-06-01 16:14:38 +02:00
|
|
|
./configure \
|
|
|
|
--prefix=$PREFIX \
|
|
|
|
--libdir=$PREFIX/lib \
|
|
|
|
--includedir=$PREFIX/include \
|
|
|
|
--static
|
|
|
|
|
|
|
|
And run ``make install`` to build and install.
|
|
|
|
|
2014-08-17 12:15:19 +02:00
|
|
|
After prerequisite libraries are prepared, run ``android-config`` and
|
2022-09-26 10:04:42 +02:00
|
|
|
then ``make`` to compile nghttp2 source files.
|
2014-08-17 12:15:19 +02:00
|
|
|
|
|
|
|
If all went well, application binaries, such as nghttpx, are created
|
|
|
|
under src directory. Strip debugging information from the binary
|
2016-07-16 12:07:31 +02:00
|
|
|
using the following command:
|
|
|
|
|
|
|
|
.. code-block:: text
|
2014-08-17 12:15:19 +02:00
|
|
|
|
2022-09-26 10:04:42 +02:00
|
|
|
$ $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip src/nghttpx
|