• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1NDK Development:
2====
3
4This document describes how one can modify the NDK and generate
5new experimental release packages for it.
6
7I. Getting the sources:
8---
9
10The sources live under the "ndk" and "development/ndk" directories in
11the Android source tree:
12
13  - "ndk" contains the main build scripts and documentation
14  - "development/ndk" contains platform-specific headers and samples
15
16If you have downloaded the full Android source tree through the "repo"
17tool, you can start directly there. Otherwise, you can just get these
18two repositories with the following:
19
20        mkdir workdir
21        cd workdir
22        git clone https://android.googlesource.com/platform/ndk.git ndk
23        git clone https://android.googlesource.com/platform/development.git development
24        export NDK=`pwd`/ndk
25
26
27II. Building the platforms tree:
28---
29
30You need to do that once if you want to use the content of $NDK to build
31samples, tests or anything else:
32
33        $NDK/build/tools/gen-platforms.sh
34
35What the script does is populate the $NDK/platforms and $NDK/samples
36directories from the content of development/ndk.
37
38What is under development/ndk is segregated by API level. This makes it
39easier to add a new platform to the tree, but is not well-suited to building
40stuff. The gen-platforms.sh script will gather all files appropriately
41and place the result inside $NDK/platforms and $NDK/samples.
42
43Note: 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:
45
46        $NDK/build/tools/dev-cleanup.sh
47
48which also removes all intermediate files and directories from $NDK.
49
50
51III. Prebuilt binaries:
52---
53
54The NDK requires several prebuilt binary executables to work properly, these
55include the following:
56
57  - toolchain binaries for the cross-compiler and associated tools
58  - gdbserver binaries required for native debugging
59
60These are not provided in the NDK's git repositories. However, there are
61several ways to get them:
62
63### 1. From a previous NDK release package:
64
65By far the easiest thing to do is to copy the binaries from a previous
66NDK installation. You can do that with a command like the following one:
67
68          cp -r $PREVIOUS_NDK/toolchains/* $NDK/toolchains/
69
70NOTE: The binaries are listed in $NDK/.gitignore and will not appear
71      in your git status.
72
73
74### 2. Download and rebuild directly from the internet:
75
76IMPORTANT: This is *very* long.
77
78The NDK comes with several scripts that can be used to rebuild the
79binaries from scratch, after downloading their sources from
80android.googlesource.com.
81
82There are several ways to do that, the most naive one, which will
83always work but will be *very* long (expect a few hours on a typical
84dual-core machine) is to do the following:
85
86          $NDK/build/tools/rebuild-all-prebuilt.sh
87
88This will perform all the steps required to rebuild the binaries,
89which include:
90
91  - downloading the sources from android.googlesource.com
92  - patching them with appropriate changes, if needed
93  - rebuilding everything from scratch
94  - copying the generated binaries to the proper location under $NDK
95
96You will need about 30G of free space in your /tmp directory to be
97able to do that, and *plenty* of free time.
98
99IMPORTANT: If you plan to generate NDK release packages, even
100experimental ones, we strongly suggest you to use the individual
101steps described in 3/ below.
102
103IMPORTANT:
104Since NDK r5, Windows binaries can be built on Linux by using the
105--mingw option, which requires that you have the "mingw32" package
106installed on your system. For example:
107
108        $NDK/build/tools/rebuild-all-prebuilt.sh --mingw
109
110We do not officially support building these binaries directly on
111Windows (either through Cygwin or MSys) anymore, due to the vast
112number of problems these environments create when trying to do so.
113
114
115
116### 3. Download, rebuild, package, install in separate steps:
117
118If you plan to generate your own NDK release packages, it is better
119to rebuild your binaries using separate steps, as in:
120
121  - Download the sources from the Internet, patch them, then
122    package the result in a simple tarball.
123
124  - For every target system (linux-x86, darwin-x86 and windows),
125    rebuild the binaries from the same source tarball.
126
127  - Package and collect all prebuilt binaries into a single
128    directory that will be used when packaging NDK releases.
129
130Here are more details on how to do that:
131
132#### 3.a/ Download + patching + packaging sources:
133
134Use the following command to download, patch and package the
135sources:
136
137        $NDK/build/tools/download-toolchain-sources.sh --package
138
139This will create a large tarball containing all sources ready to be
140used by the following step. The generated file path will be dumped at
141the script when it completes its operation and should be something
142like:
143
144        /tmp/android-ndk-toolchain-<date>.tar.bz2
145
146Note that if you don't use the --package option, you will need to
147provide the name of a directory where the patched sources will be
148copied instead, as in:
149
150        $NDK/build/tools/download-toolchain-sources.sh <target-src-dir>
151
152
153#### 3.b/ Build the binaries:
154
155Use the following command to rebuild the binaries from the source
156tarball that was created in the previous section with the --package
157option:
158
159        $NDK/build/tools/rebuild-all-prebuilt.sh --toolchain-pkg=<file>
160
161Where <file> points to the package generated by the
162download-toolchain-sources.sh script.
163
164In the case where you downloaded the sources to a directory instead,
165use the --toolchain-src-dir option instead, as with:
166
167        $NDK/build/tools/rebuild-all-prebuilt.sh --toolchain-src-dir=<path>
168
169This will rebuild all the prebuilt binaries for your host platforms
170and place them in a directory named:
171
172        /tmp/ndk-prebuilt/prebuilt-<date>/
173
174These binary packages include the following:
175
176  - host-specific toolchain binaries. e.g.
177    `arm-linux-androideabi-4.6-linux-x86.tar.bz2`.
178
179  - toolchain specific device binaries, e.g.
180    `arm-gdbserver.tar.bz2`.
181
182IMPORTANT:
183To generate Windows binaries on Windows, install the "mingw32"
184package on your system, then use the --mingw option, as in:
185
186        $NDK/build/tools/rebuild-all-prebuilt.sh --mingw --toolchain-pkg=<file>
187
188Note that device-specific binaries (e.g. gdbserver) cannot be
189rebuilt with this option.
190
191#### 3.c/ Copy the binaries to your NDK tree:
192
193Simply go to your NDK tree, and unpack the binary tarballs in place,
194for example:
195
196        cd $NDK
197        tar xjf <path>/*.tar.bz2
198
199Where <path> is a directory containing all the tarballs (e.g. it
200could be simply /tmp/ndk-prebuilt/prebuilt-<date>)
201
202This will put the corresponding files at the correct location.
203
204#### 3.c/
205
206It is a good idea to save the generated toolchain binaries into
207an archive. To do that, use the --package option, as in:
208
209        $NDK/build/tools/rebuild-all-prebuilt.sh --package
210
211This will generate a package file containing all the prebuilts, that
212can be unpacked directly into your $NDK directory. The package name is
213printed at the end, e.g."android-ndk-prebuild-<date>-<system>.tar.bz2".
214
215Where <date> is the current date, and <system> is your system name.
216Then, to unpack:
217
218        cd $NDK
219        tar xjf /tmp/android-ndk-prebuilt-<date>-<system>.tar.bz2
220
221
222The generated package can easily be shared with other people.
223
224
225IV. Generate new package releases:
226---
227
228You can generate new experimental NDK release packages once you're satisfied
229with your changes, in order to share them with other people. There are two
230ways to do that:
231
232### 1. Using the 'make-release.sh' script:
233
234The simplest, and also the slowest way, to generate a new NDK release
235is to invoke this script, with:
236
237        $NDK/build/tools/make-release.sh
238
239NOTE: THIS WILL BE VERY VERY LONG. The script will do all the steps
240  described in section III *from* scratch, and this can take several
241  hours on a dual-core machine.
242
243You should only use it in case of desperation, or if you don't want
244to deal with all the details exposed in section III or below.
245
246
247### 2. Using a previous NDK release package:
248
249This is the second simplest way to generate a new package, and it will
250be extremely quick because it will pick the prebuilt binaries directly
251from the previous package.
252
253Do the following:
254
255        cd $NDK
256        build/tools/package-release.sh --prebuilt-ndk=<file>
257
258Where <file> points to a previous NDK package (i.e. archive file).
259
260NOTE: This method can only be used to generate a single release package
261    for the current host system.
262
263### 3. Using prebuilt tarballs:
264
265If you have generated prebuilt binary tarballs with the steps described
266in section III.3 above, you can use these to generate release packages
267as well.
268
269Assuming that you have collected prebuilt tarballs for all three supported
270host systems (i.e. linux-x86, darwin-x86 and windows) under a directory,
271do the following:
272
273        cd $NDK
274        build/tools/package-release.sh --prebuilt-dir=<path>
275
276The generated NDK package release will have a name that looks like:
277
278        /tmp/ndk-release/android-ndk-<release>-<system>.zip
279
280Where <release> is by default the current date in ISO format
281(e.g. 20100915), and <system> corresponds to the host system where the
282NDK release is supposed to run.
283
284The script 'package-release.sh' provides a few additional options:
285
286        --release=<name>       Change the name of the release
287
288        --systems=<list>       Change the list of host systems to package for
289
290        --platforms=<list>     List of API levels to package in the NDK
291
292        --out-dir=<path>       Specify a different output directory for the
293                              final packages (instead of /tmp/ndk-release)
294
295Use --help to list them all.
296