• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html><body><pre>Android 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 "ndk-build 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
17How to force a rebuild of all your sources:
18-------------------------------------------
19
20Use GNU Make's "-B" option, as in:
21
22   ndk-build -B
23
24
25How to store your native sources in a location other than $PROJECT/jni:
26-----------------------------------------------------------------------
27
28First, you can simply tell your $PROJECT/jni/Android.mk to include
29another Android.mk that are located in different places.
30
31Alternatively, you can define APP_BUILD_SCRIPT in your Application.mk
32to point to an alternative Android.mk file.
33
34
35How to build a project's native files without cd-ing to it:
36-----------------------------------------------------------
37
38Sometimes, you may need to rebuild a project's native file without
39being able to cd to its top-level path from the command-line. This
40is do-able by using the GNU-Make '-C &lt;path&gt;' option, as in:
41
42    ndk-build -C &lt;project-path&gt;
43
44
45How to store your Application.mk in a location other than $PROJECT/jni:
46-----------------------------------------------------------------------
47
48Starting with NDK r4, you can simply place the file under $PROJECT/jni/
49and launch the 'ndk-build' script from your project tree.
50
51If you want to use 'ndk-build' but place the file to a different location,
52use a GNU Make variable override as:
53
54    ndk-build NDK_APPLICATION_MK=/path/to/your/Application.mk
55
56If you're using the legacy $NDK/apps/&lt;name&gt; build method, you can create
57a symbolic link to your final Application.mk there. For example, imagine
58that you wrote:
59
60  $PROJECT/foo/Application.mk
61
62You can create a symlink like with a command like:
63
64  ln -s $PROJECT/foo  $NDK/apps/&lt;name&gt;
65
66This will make $NDK/apps/&lt;name&gt;/Application.mk point directly to
67$PROJECT/jni/Application.mk
68
69Note that generated files will still go under $NDK/out/apps/&lt;name&gt; though.
70
71Windows users: The NDK is only supported on Cygwin, which implements
72symbolic links through the "ln -s" command, as in:
73
74    ln -s  &lt;target&gt;  &lt;link&gt;
75
76
77How to properly add include directories to your module declaration:
78-------------------------------------------------------------------
79
80If you define several modules, it is common to need to include one
81module's header while compiling another one. For example, consider
82the following example:
83
84  $PROJECT/jni/foo/
85    Android.mk
86    foo.h
87    foo.c
88
89  $PROJECT/jni/bar/
90    Android.mk
91    bar.c
92
93Where the 'bar.c' uses '#include &lt;foo.h&gt;'. You will need to add the
94path to the 'foo' module in jni/bar/Android.mk to build it properly.
95
96One is tempted to use the following:
97
98  LOCAL_C_INCLUDES := ../foo
99
100However this will not work because all compilation happens from the
101directory where 'ndk-build' is invoked, and include files must be
102relative to it.
103
104The correct line is instead:
105
106  LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
107
108Which uses a path relative to $(LOCAL_PATH), in the case where you would
109need to move 'foo' and 'bar' to a deeper level in the 'sources' hierarchy.
110
111In case you absolutely need it, you can also use NDK_APP_PROJECT_PATH to
112point to your project directory:
113
114  LOCAL_C_INCLUDES := $(NDK_APP_PROJECT_PATH)/jni/foo
115
116However, we don't recommend using this, paths relative to $(LOCAL_PATH)
117being better.
118
119</pre></body></html>