• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Android NDK How-To:
2===================
3
4A collection of tips and tricks for NDK users
5
6
7How to force the display of build commands:
8-------------------------------------------
9
10Do "make APP=<yourapp> V=1" and actual build commands will be
11displayed. This can be used to verify that things are compiled
12as you expect them to, and check for bugs in the NDK build system.
13
14(The V=1 trick comes from the Linux kernel build system)
15
16
17
18How to force a rebuild of all your sources:
19-------------------------------------------
20
21Use GNU Make's "-B" option, as in:
22
23   make APP=<yourapp> -B
24
25
26How to store your native sources in a location other than $PROJECT/jni:
27-----------------------------------------------------------------------
28
29First, you can simply tell your $PROJECT/jni/Android.mk to include
30another Android.mk that are located in different places.
31
32Alternatively, you can define APP_BUILD_SCRIPT in your Application.mk
33to point to an alternative Android.mk file, getting rid of the
34$PROJECT/jni directory hierarchy entirely if you need to.
35
36
37How to store your Application.mk in a location other than $NDK/app/<name>:
38--------------------------------------------------------------------------
39
40At the moment, the application descriptor files must be accessible from
41$NDK/app/<name>. You can however create a symlink to a different directory.
42
43For example, imagine that you wrote:
44
45  $PROJECT/jni/Application.mk
46
47You can create a symlink like with a command like:
48
49  ln -s $PROJECT/jni  $NDK/apps/<name>
50
51This will make $NDK/apps/<name>/Application.mk point directly to
52$PROJECT/jni/Application.mk
53
54Note that generated files will still go under $NDK/out/apps/<name> though.
55
56Windows users: The NDK is only supported on Cygwin, which implements
57symbolic links through the "ln -s" command, as in:
58
59    ln -s  <target>  <link>
60
61
62How to properly add include directories to your module declaration:
63-------------------------------------------------------------------
64
65If you define several modules, it is common to need to include one
66module's header while compiling another one. For example, consider
67the following example:
68
69  $NDK_ROOT/sources/foo/
70    Android.mk
71    foo.h
72    foo.c
73
74  $NDK_ROOT/sources/bar/
75    Android.mk
76    bar.c
77
78Where the 'bar.c' uses '#include <foo.h>'. You will need to add the
79path to the 'foo' module in bar/Android.mk to build it properly.
80
81One is tempted to use the following:
82
83  LOCAL_C_INCLUDES := ../foo
84
85However this will not work because all compilation happens from the
86root NDK directory (i.e. $NDK_ROOT), and include files must be relative
87to it. The above line really translates to:
88
89  LOCAL_C_INCLUDES := $(NDK_ROOT)/../foo
90
91Which adds a non-existing directory to the C include path. The correct
92line is instead:
93
94  LOCAL_C_INCLUDES := sources/foo
95
96Or even better:
97
98  LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
99
100Which uses a path relative to $(LOCAL_PATH), in the case where you would
101need to move 'foo' and 'bar' to a deeper level in the 'sources' hierarchy.
102
103
104