tizen 2.4 release
[external/nghttp2.git] / doc / sources / building-android-binary.rst
1 Building Android binary
2 =======================
3
4 In this article, we briefly describe how to build Android binary using
5 `Android NDK <http://developer.android.com/tools/sdk/ndk/index.html>`_
6 cross-compiler on Debian Linux.
7
8 The easiest way to build android binary is use Dockerfile.android.
9 See Dockerfile.android for more details.  If you cannot use
10 Dockerfile.android for whatever reason, continue to read the rest of
11 this article.
12
13 We offer ``android-config`` and ``android-make`` scripts to make the
14 build easier.  To make these script work, NDK toolchain must be
15 installed in the following way.  First, let us introduce
16 ``ANDROID_HOME`` environment variable.  We need to install toolchain
17 under ``$ANDROID_HOME/toolchain``.  An user can freely choose the path
18 for ``ANDROID_HOME``.  For example, to install toolchain under
19 ``$ANDROID_HOME/toolchain``, do this in the the directory where NDK is
20 unpacked::
21
22     $ build/tools/make-standalone-toolchain.sh \
23       --install-dir=$ANDROID_HOME/toolchain \
24       --toolchain=arm-linux-androideabi-4.9 \
25       --llvm-version=3.5 \
26       --platform=android-16
27
28 The additional flag ``--system=linux-x86_64`` may be required if you
29 are using x86_64 system.
30
31 The platform level is not important here because we don't use Android
32 specific C/C++ API.
33
34 The dependent libraries, such as OpenSSL and libev should be built
35 with the toolchain and installed under ``$ANDROID_HOME/usr/local``.
36 We recommend to build these libraries as static library to make the
37 deployment easier.  libxml2 support is currently disabled.
38
39 We use zlib which comes with Android NDK, so we don't have to build it
40 by ourselves.
41
42 If SPDY support is required for nghttpx and h2load, build and install
43 spdylay as well.
44
45 Before running ``android-config`` and ``android-make``,
46 ``ANDROID_HOME`` environment variable must be set to point to the
47 correct path.  Also add ``$ANDROID_HOME/toolchain/bin`` to ``PATH``::
48
49     $ export PATH=$PATH:$ANDROID_HOME/toolchain/bin
50
51 To configure OpenSSL, use the following script:
52
53 .. code-block:: sh
54
55     #!/bin/sh
56
57     if [ -z "$ANDROID_HOME" ]; then
58         echo 'No $ANDROID_HOME specified.'
59         exit 1
60     fi
61     PREFIX=$ANDROID_HOME/usr/local
62     TOOLCHAIN=$ANDROID_HOME/toolchain
63     PATH=$TOOLCHAIN/bin:$PATH
64
65     export CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
66     ./Configure --prefix=$PREFIX android
67
68 And run ``make install`` to build and install.
69
70 We cannot compile libev without modification.  Apply `this patch
71 <https://gist.github.com/tatsuhiro-t/48c45f08950f587180ed>`_ before
72 configuring libev.  This patch is for libev-4.19.  After applying the
73 patch, to configure libev, use the following script:
74
75 .. code-block:: sh
76
77     #!/bin/sh
78
79     if [ -z "$ANDROID_HOME" ]; then
80         echo 'No $ANDROID_HOME specified.'
81         exit 1
82     fi
83     PREFIX=$ANDROID_HOME/usr/local
84     TOOLCHAIN=$ANDROID_HOME/toolchain
85     PATH=$TOOLCHAIN/bin:$PATH
86
87     ./configure \
88         --host=arm-linux-androideabi \
89         --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
90         --prefix=$PREFIX \
91         --disable-shared \
92         --enable-static \
93         CPPFLAGS=-I$PREFIX/include \
94         LDFLAGS=-L$PREFIX/lib
95
96 And run ``make install`` to build and install.
97
98 To configure spdylay, use the following script:
99
100 .. code-block:: sh
101
102     if [ -z "$ANDROID_HOME" ]; then
103         echo 'No $ANDROID_HOME specified.'
104         exit 1
105     fi
106     PREFIX=$ANDROID_HOME/usr/local
107     TOOLCHAIN=$ANDROID_HOME/toolchain
108     PATH=$TOOLCHAIN/bin:$PATH
109
110     ./configure \
111         --disable-shared \
112         --host=arm-linux-androideabi \
113         --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
114         --prefix=$PREFIX \
115         --without-libxml2 \
116         --disable-src \
117         --disable-examples \
118         CPPFLAGS="-I$PREFIX/include" \
119         PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" \
120         LDFLAGS="-L$PREFIX/lib"
121
122 And run ``make install`` to build and install.  After spdylay
123 installation, edit $ANDROID_HOME/usr/local/lib/pkgconfig/libspdylay.pc
124 and remove the following line::
125
126     Requires.private: zlib
127
128 After prerequisite libraries are prepared, run ``android-config`` and
129 then ``android-make`` to compile nghttp2 source files.
130
131 If all went well, application binaries, such as nghttpx, are created
132 under src directory.  Strip debugging information from the binary
133 using the following command::
134
135     $ arm-linux-androideabi-strip src/nghttpx