12c593315Sopenharmony_ciBuilding Android binary 22c593315Sopenharmony_ci======================= 32c593315Sopenharmony_ci 42c593315Sopenharmony_ciIn this article, we briefly describe how to build Android binary using 52c593315Sopenharmony_ci`Android NDK <https://developer.android.com/ndk>`_ cross-compiler on 62c593315Sopenharmony_ciDebian Linux. 72c593315Sopenharmony_ci 82c593315Sopenharmony_ciThe easiest way to build android binary is use Dockerfile.android. 92c593315Sopenharmony_ciSee Dockerfile.android for more details. If you cannot use 102c593315Sopenharmony_ciDockerfile.android for whatever reason, continue to read the rest of 112c593315Sopenharmony_cithis article. 122c593315Sopenharmony_ci 132c593315Sopenharmony_ciWe offer ``android-config`` script to make the build easier. To make 142c593315Sopenharmony_cithe script work, NDK directory must be set to ``NDK`` environment 152c593315Sopenharmony_civariable. NDK directory is the directory where NDK is unpacked: 162c593315Sopenharmony_ci 172c593315Sopenharmony_ci.. code-block:: text 182c593315Sopenharmony_ci 192c593315Sopenharmony_ci $ unzip android-ndk-$NDK_VERSION-linux.zip 202c593315Sopenharmony_ci $ cd android-ndk-$NDK_VERSION 212c593315Sopenharmony_ci $ export NDK=$PWD 222c593315Sopenharmony_ci 232c593315Sopenharmony_ciThe dependent libraries, such as OpenSSL, libev, and c-ares should be 242c593315Sopenharmony_cibuilt with the same NDK toolchain and installed under 252c593315Sopenharmony_ci``$NDK/usr/local``. We recommend to build these libraries as static 262c593315Sopenharmony_cilibrary to make the deployment easier. libxml2 support is currently 272c593315Sopenharmony_cidisabled. 282c593315Sopenharmony_ci 292c593315Sopenharmony_ciAlthough zlib comes with Android NDK, it seems not to be a part of 302c593315Sopenharmony_cipublic API, so we have to built it for our own. That also provides us 312c593315Sopenharmony_ciproper .pc file as a bonus. 322c593315Sopenharmony_ci 332c593315Sopenharmony_ciBefore running ``android-config``, ``NDK`` environment variable must 342c593315Sopenharmony_cibe set to point to the correct path. 352c593315Sopenharmony_ci 362c593315Sopenharmony_ciYou need to set ``NGHTTP2`` environment variable to the absolute path 372c593315Sopenharmony_cito the source directory of nghttp2. 382c593315Sopenharmony_ci 392c593315Sopenharmony_ciTo configure OpenSSL, use the following script: 402c593315Sopenharmony_ci 412c593315Sopenharmony_ci.. code-block:: sh 422c593315Sopenharmony_ci 432c593315Sopenharmony_ci #!/bin/sh 442c593315Sopenharmony_ci 452c593315Sopenharmony_ci . $NGHTTP2/android-env 462c593315Sopenharmony_ci 472c593315Sopenharmony_ci export ANDROID_NDK_HOME=$NDK 482c593315Sopenharmony_ci export PATH=$TOOLCHAIN/bin:$PATH 492c593315Sopenharmony_ci 502c593315Sopenharmony_ci ./Configure no-shared --prefix=$PREFIX android-arm64 512c593315Sopenharmony_ci 522c593315Sopenharmony_ciAnd run the following script to build and install without 532c593315Sopenharmony_cidocumentation: 542c593315Sopenharmony_ci 552c593315Sopenharmony_ci.. code-block:: sh 562c593315Sopenharmony_ci 572c593315Sopenharmony_ci #!/bin/sh 582c593315Sopenharmony_ci 592c593315Sopenharmony_ci . $NGHTTP2/android-env 602c593315Sopenharmony_ci 612c593315Sopenharmony_ci export PATH=$TOOLCHAIN/bin:$PATH 622c593315Sopenharmony_ci 632c593315Sopenharmony_ci make install_sw 642c593315Sopenharmony_ci 652c593315Sopenharmony_ciTo configure libev, use the following script: 662c593315Sopenharmony_ci 672c593315Sopenharmony_ci.. code-block:: sh 682c593315Sopenharmony_ci 692c593315Sopenharmony_ci #!/bin/sh 702c593315Sopenharmony_ci 712c593315Sopenharmony_ci . $NGHTTP2/android-env 722c593315Sopenharmony_ci 732c593315Sopenharmony_ci ./configure \ 742c593315Sopenharmony_ci --host=$TARGET \ 752c593315Sopenharmony_ci --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 762c593315Sopenharmony_ci --prefix=$PREFIX \ 772c593315Sopenharmony_ci --disable-shared \ 782c593315Sopenharmony_ci --enable-static \ 792c593315Sopenharmony_ci CPPFLAGS=-I$PREFIX/include \ 802c593315Sopenharmony_ci LDFLAGS=-L$PREFIX/lib 812c593315Sopenharmony_ci 822c593315Sopenharmony_ciAnd run ``make install`` to build and install. 832c593315Sopenharmony_ci 842c593315Sopenharmony_ciTo configure c-ares, use the following script: 852c593315Sopenharmony_ci 862c593315Sopenharmony_ci.. code-block:: sh 872c593315Sopenharmony_ci 882c593315Sopenharmony_ci #!/bin/sh -e 892c593315Sopenharmony_ci 902c593315Sopenharmony_ci . $NGHTTP2/android-env 912c593315Sopenharmony_ci 922c593315Sopenharmony_ci ./configure \ 932c593315Sopenharmony_ci --host=$TARGET \ 942c593315Sopenharmony_ci --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 952c593315Sopenharmony_ci --prefix=$PREFIX \ 962c593315Sopenharmony_ci --disable-shared 972c593315Sopenharmony_ci 982c593315Sopenharmony_ciAnd run ``make install`` to build and install. 992c593315Sopenharmony_ci 1002c593315Sopenharmony_ciTo configure zlib, use the following script: 1012c593315Sopenharmony_ci 1022c593315Sopenharmony_ci.. code-block:: sh 1032c593315Sopenharmony_ci 1042c593315Sopenharmony_ci #!/bin/sh -e 1052c593315Sopenharmony_ci 1062c593315Sopenharmony_ci . $NGHTTP2/android-env 1072c593315Sopenharmony_ci 1082c593315Sopenharmony_ci export HOST=$TARGET 1092c593315Sopenharmony_ci 1102c593315Sopenharmony_ci ./configure \ 1112c593315Sopenharmony_ci --prefix=$PREFIX \ 1122c593315Sopenharmony_ci --libdir=$PREFIX/lib \ 1132c593315Sopenharmony_ci --includedir=$PREFIX/include \ 1142c593315Sopenharmony_ci --static 1152c593315Sopenharmony_ci 1162c593315Sopenharmony_ciAnd run ``make install`` to build and install. 1172c593315Sopenharmony_ci 1182c593315Sopenharmony_ciAfter prerequisite libraries are prepared, run ``android-config`` and 1192c593315Sopenharmony_cithen ``make`` to compile nghttp2 source files. 1202c593315Sopenharmony_ci 1212c593315Sopenharmony_ciIf all went well, application binaries, such as nghttpx, are created 1222c593315Sopenharmony_ciunder src directory. Strip debugging information from the binary 1232c593315Sopenharmony_ciusing the following command: 1242c593315Sopenharmony_ci 1252c593315Sopenharmony_ci.. code-block:: text 1262c593315Sopenharmony_ci 1272c593315Sopenharmony_ci $ $NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip src/nghttpx 128