1 <html><body><pre>NDK Development:
4 This document describes how one can modify the NDK and generate
5 new experimental release packages for it.
7 I. Getting the sources:
8 =======================
10 The sources live under the "ndk" and "development/ndk" directories in
11 the Android source tree:
13 - "ndk" contains the main build scripts and documentation
14 - "development/ndk" contains platform-specific headers and samples
16 If you have downloaded the full Android source tree through the "repo"
17 tool, you can start directly there. Otherwise, you can just get these
18 two repositories with the following:
22 git clone git://android.git.kernel.org/platform/ndk.git ndk
23 git clone git://android.git.kernel.org/platform/development.git development
27 II. Building the platforms tree:
28 ================================
30 You need to do that once if you want to use the content of $NDK to build
31 samples, tests or anything else:
33 $NDK/build/tools/build-platforms.sh
35 What the script does is populate the $NDK/platforms and $NDK/samples
36 directories from the content of development/ndk.
38 What is under development/ndk is segregated by API level. This makes it
39 easier to add a new platform to the tree, but is not well-suited to building
40 stuff. The build-platforms.sh script will gather all files appropriately
41 and place the result inside $NDK/platforms and $NDK/samples.
43 Note: These directories are listed by $NDK/.gitignore, so they won't appear
44 on your git status. You can remove them if you want by running:
46 $NDK/build/tools/dev-cleanup.sh
48 which also removes all intermediate files and directories from $NDK.
51 III. Prebuilt binaries:
52 =======================
54 The NDK requires several prebuilt binary executables to work properly, these
55 include the following:
57 - toolchain binaries for the cross-compiler and associated tools
58 - gdbserver binaries required for native debugging
60 These are not provided in the NDK's git repositories. However, there are
61 several ways to get them:
63 1/ From a previous NDK release package:
65 By far the easiest thing to do is to copy the binaries from a previous
66 NDK installation. You can do that with a command like the following one:
68 cp -r $PREVIOUS_NDK/toolchains/* $NDK/toolchains/
70 NOTE: The binaries are listed in $NDK/.gitignore and will not appear
74 2/ Download and rebuild directly from the internet:
76 IMPORTANT: This is *very* long.
78 The NDK comes with several scripts that can be used to rebuild the
79 binaries from scratch, after downloading their sources from
80 android.git.kernel.org.
82 There are several ways to do that, the most naive one, which will
83 always work but will be *very* long (expect a few hours on a typical
84 dual-core machine) is to do the following:
86 $NDK/build/tools/rebuild-all-prebuilt.sh
88 This will perform all the steps required to rebuild the binaries,
91 - downloading the sources from android.git.kernel.org
92 - patching them with appropriate changes, if needed
93 - rebuilding everything from scratch
94 - copying the generated binaries to the proper location under $NDK
96 You will need about 30G of free space in your /tmp directory to be
97 able to do that, and *plenty* of free time.
99 IMPORTANT: If you plan to generate NDK release packages, even
100 experimental ones, we strongly suggest you to use the individual
101 steps described in 3/ below.
104 Since NDK r5, Windows binaries can be built on Linux by using the
105 --mingw option, which requires that you have the "mingw32" package
106 installed on your system. For example:
108 $NDK/build/tools/rebuild-all-prebuilt.sh --mingw
110 We do not officially support building these binaries directly on
111 Windows (either through Cygwin or MSys) anymore, due to the vast
112 number of problems these environments create when trying to do so.
116 3/ Download, rebuild, package, install in separate steps:
118 If you plan to generate your own NDK release packages, it is better
119 to rebuild your binaries using separate steps, as in:
121 - Download the sources from the Internet, patch them, then
122 package the result in a simple tarball.
124 - For every target system (linux-x86, darwin-x86 and windows),
125 rebuild the binaries from the same source tarball.
127 - Package and collect all prebuilt binaries into a single
128 directory that will be used when packaging NDK releases.
130 Here are more details on how to do that:
132 3.a/ Download + patching + packaging sources:
134 Use the following command to download, patch and package the
137 $NDK/build/tools/download-toolchain-sources.sh --package
139 This will create a large tarball containing all sources ready to be
140 used by the following step. The generated file path will be dumped at
141 the script when it completes its operation and should be something
144 /tmp/android-ndk-toolchain-<date>.tar.bz2
146 Note that if you don't use the --package option, you will need to
147 provide the name of a directory where the patched sources will be
148 copied instead, as in:
150 $NDK/build/tools/download-toolchain-sources.sh <target-src-dir>
153 3.b/ Build the binaries:
155 Use the following command to rebuild the binaries from the source
156 tarball that was created in the previous section with the --package
159 $NDK/build/tools/rebuild-all-prebuilt.sh --toolchain-pkg=<file>
161 Where <file> points to the package generated by the
162 download-toolchain-sources.sh script.
164 In the case where you downloaded the sources to a directory instead,
165 use the --toolchain-src-dir option instead, as with:
167 $NDK/build/tools/rebuild-all-prebuilt.sh --toolchain-src-dir=<path>
169 This will rebuild all the prebuilt binaries for your host platforms
170 and place them in a directory named:
172 /tmp/ndk-prebuilt/prebuilt-<date>/
174 These binary packages include the following:
176 - host-specific toolchain binaries. e.g.
177 arm-eabi-4.4.0-linux-x86.tar.bz2
179 - toolchain specific device binaries, e.g.
180 arm-eabi-4.4.0-gdbserver.tar.bz2
183 To generate Windows binaries on Windows, install the "mingw32"
184 package on your system, then use the --mingw option, as in:
186 $NDK/build/tools/rebuild-all-prebuilt.sh --mingw --toolchain-pkg=<file>
188 Note that device-specific binaries (e.g. gdbserver) cannot be
189 rebuilt with this option.
191 3.c/ Copy the binaries to your NDK tree:
193 Simply go to your NDK tree, and unpack the binary tarballs in place,
197 tar xjf <path>/*.tar.bz2
199 Where <path> is a directory containing all the tarballs (e.g. it
200 could be simply /tmp/ndk-prebuilt/prebuilt-<date>)
202 This will put the corresponding files at the correct location.
207 It is a good idea to save the generated toolchain binaries into
208 an archive. To do that, use the --package option, as in:
210 $NDK/build/tools/rebuild-all-prebuilt.sh --package
212 This will generate a package file containing all the prebuilts, that
213 can be unpacked directly into your $NDK directory. The package name is
214 printed at the end, e.g."android-ndk-prebuild-<date>-<system>.tar.bz2".
216 Where <date> is the current date, and <system> is your system name.
220 tar xjf /tmp/android-ndk-prebuilt-<date>-<system>.tar.bz2
223 The generated package can easily be shared with other people.
226 IV. Generate new package releases:
227 ==================================
229 You can generate new experimental NDK release packages once you're satisfied
230 with your changes, in order to share them with other people. There are two
233 1/ Using the 'make-release.sh' script:
235 The simplest, and also the slowest way, to generate a new NDK release
236 is to invoke this script, with:
238 $NDK/build/tools/make-release.sh
240 NOTE: THIS WILL BE VERY VERY LONG. The script will do all the steps
241 described in section III *from* scratch, and this can take several
242 hours on a dual-core machine.
244 You should only use it in case of desperation, or if you don't want
245 to deal with all the details exposed in section III or below.
248 1/ Using a previous NDK release package:
250 This is the second simplest way to generate a new package, and it will
251 be extremely quick because it will pick the prebuilt binaries directly
252 from the previous package.
257 build/tools/package-release.sh --prebuilt-ndk=<file>
259 Where <file> points to a previous NDK package (i.e. archive file).
261 NOTE: This method can only be used to generate a single release package
262 for the current host system.
264 2/ Using prebuilt tarballs:
266 If you have generated prebuilt binary tarballs with the steps described
267 in section III.3 above, you can use these to generate release packages
270 Assuming that you have collected prebuilt tarballs for all three supported
271 host systems (i.e. linux-x86, darwin-x86 and windows) under a directory,
275 build/tools/package-release.sh --prebuilt-dir=<path>
277 The generated NDK package release will have a name that looks like:
279 /tmp/ndk-release/android-ndk-<release>-<system>.zip
281 Where <release> is by default the current date in ISO format
282 (e.g. 20100915), and <system> corresponds to the host system where the
283 NDK release is supposed to run.
285 The script 'package-release.sh' provides a few additional options:
287 --release=<name> Change the name of the release
289 --systems=<list> Change the list of host systems to package for
291 --platforms=<list> List of API levels to package in the NDK
293 --out-dir=<path> Specify a different output directory for the
294 final packages (instead of /tmp/ndk-release)
296 Use --help to list them all.