• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Application.mk
2@jd:body
3
4<div id="qv-wrapper">
5    <div id="qv">
6      <h2>On this page</h2>
7
8      <ol>
9        <li><a href="#over">Overview</a></li>
10        <li><a href="#var">Variables</a></li>
11      </ol>
12    </div>
13  </div>
14
15<p>This document explains the {@code Application.mk} build file, which describes the
16native <em>modules</em> that your app requires. A module can be a static library, a shared library,
17or an executable.</p>
18
19<p>We recommend that you read the <a href="{@docRoot}ndk/guides/concepts.html">Concepts</a> and
20<a href="{@docRoot}ndk/guides/android_mk.html">Android.mk</a> pages before this one. Doing so will
21help maximize your understanding of the material on this page. </p>
22
23<h2 id="over">Overview</h2>
24The {@code Application.mk} file is really a tiny GNU Makefile fragment that defines several
25variables for compilation. It usually resides under {@code $PROJECT/jni/}, where {@code $PROJECT}
26points to your application's project directory. Another alternative is to place it under a
27sub-directory of the top-level {@code $NDK/apps/} directory. For example:</p>
28
29<pre>
30$NDK/apps/&lt;myapp&gt;/Application.mk
31</pre>
32
33<p>Here, {@code <myapp>} is a short name used to describe your app to the NDK build system. It
34doesn't actually go into your generated shared libraries or your final packages.</p>
35
36<h2 id="var">Variables</h2>
37<h4>APP_PROJECT_PATH</h4>
38<p>This variable stores the absolute path to your app's project-root directory. The build system
39uses this information to place stripped-down versions of the generated JNI shared libraries
40into a specific location known to the APK-generating tools.</p>
41
42<p>If you place your {@code Application.mk} file under {@code $NDK/apps/<myapp>/}, you must
43define this variable. If you place it under {@code $PROJECT/jni/}, it is optional.
44
45<h4>APP_OPTIM</h4>
46<p>Define this optional variable as either {@code release} or {@code debug}. You use it to
47alter the optimization level when building your application's modules.</p>
48
49<p>Release mode is the default, and generates highly optimized binaries. Debug mode generates
50unoptimized binaries that are much easier to debug.</p>
51
52<p>Note that you can debug either release or debug binaries. Release binaries, however, provide less
53information during debugging. For example, the build system optimizes out some variables,
54preventing you from inspecting them. Also, code re-ordering can make it more difficult to step
55through the code; stack traces may not be reliable.</p>
56
57<p>Declaring {@code android:debuggable} in your application manifest's {@code <application>}
58tag will cause this variable to default to {@code debug} instead of {@code release}. Override this
59default value by setting {@code APP_OPTIM} to {@code release}.</p>
60
61
62<h4>APP_CFLAGS</h4>
63<p>This variable stores a set of C compiler flags that the build system passes to the compiler
64when compiling any C or C++ source code for any of the modules. You can use this variable to change
65the build of a given module according to the application that needs it, instead of having to modify
66the {@code Android.mk} file itself. </p>
67
68
69<p>All paths in these flags should be relative to the top-level NDK directory. For example, if you
70have the following setup:</p>
71
72<pre>
73sources/foo/Android.mk
74sources/bar/Android.mk
75</pre>
76
77<p>To specify in {@code foo/Android.mk} that you want to add the path to the {@code bar} sources
78during compilation, you should use:
79
80<pre>
81APP_CFLAGS += -Isources/bar
82</pre>
83
84<p>Or, alternatively:</p>
85
86<pre>
87APP_CFLAGS += -I$(LOCAL_PATH)/../bar
88</pre>
89
90<p>{@code -I../bar} will not work since it is equivalent to
91{@code -I$NDK_ROOT/../bar}.</p>
92
93<p class="note"><strong>Note: </strong>This variable only works on C, not C++, sources in
94android-ndk-1.5_r1. In all versions after that one, {@code APP_CFLAGS} matches the full Android
95build system.</p>
96
97<h4>APP_CPPFLAGS</h4>
98<p>This variable contains a set of C++ compiler flags that the build system passes to the compiler
99when building only C++ sources.</p>
100
101<p class="note"><strong>Note: </strong> In android-ndk-1.5_r1, this variable works on both C and
102C++ sources. In all subsequent versions of the NDK, {@code APP_CPPFLAGS} now matches the full
103Android build system. For flags that apply to both C and C++ sources, use {@code APP_CFLAGS}.</p>
104
105<h4>APP_LDFLAGS</h4>
106<p>A set of linker flags that the build system passes when linking the application. This variable
107is only relevant when the build system is building shared libraries and executables. When the
108build system builds static libraries, it ignores these flags.</p>
109
110<h4>APP_BUILD_SCRIPT</h4>
111<p>By default, the NDK build system looks under {@code jni/} for a file named
112<a href="{@docRoot}ndk/guides/android_mk.html">{@code Android.mk}</a>.</p>
113
114<p>If you want to override this behavior, you can define {@code APP_BUILD_SCRIPT} to point to an
115alternate build script. The build system always interprets a non-absolute path as relative to the
116NDK's top-level directory.</p>
117
118<h4>APP_ABI</h4>
119<p>By default, the NDK build system generates machine code for the
120<a href="{@docRoot}ndk/guides/abis.html">{@code armeabi}</a> ABI. This machine code
121corresponds to an ARMv5TE-based CPU with software floating point operations. You can use
122{@code APP_ABI} to select a different ABI. Table 1 shows the {@code APP_ABI}
123settings for different instruction sets.</p>
124
125<p class="table-caption" id="table1">
126  <strong>Table 1.</strong> {@code APP_ABI} settings for different instruction sets.</p>
127<table>
128  <tr>
129    <th scope="col">Instruction set</th>
130    <th scope="col">Value</th>
131  </tr>
132  <tr>
133    <td>Hardware FPU instructions on ARMv7 based devices</td>
134    <td>{@code APP_ABI := armeabi-v7a}</td>
135  </tr>
136  <tr>
137    <td>ARMv8 AArch64</td>
138    <td>{@code APP_ABI := arm64-v8a}</td>
139  </tr>
140    <tr>
141    <td>IA-32</td>
142    <td>{@code APP_ABI := x86}</td>
143  </tr>
144    <tr>
145    <td>Intel64</td>
146    <td>{@code APP_ABI := x86_64}</td>
147  </tr>
148    <tr>
149    <td>MIPS32</td>
150    <td>{@code APP_ABI := mips}</td>
151  </tr>
152    <tr>
153    <td>MIPS64 (r6)</td>
154    <td>{@code APP_ABI := mips64}</td>
155  </tr>
156    <tr>
157    <td>All supported instruction sets</td>
158    <td>{@code APP_ABI := all}</td>
159  </tr>
160</table>
161
162<p class="note"><strong>Note:</strong> {@code all} is available starting from NDKr7.</p>
163
164<p>You can also specify multiple values by placing them on the same line, delimited by spaces.
165For example:</p>
166
167<pre>
168APP_ABI := armeabi armeabi-v7a x86 mips
169</pre>
170
171<p>For the list of all supported ABIs and details about their usage and limitations, refer to
172<a href="{@docRoot}ndk/guides/abis.html">ABI Management</a>.</p>
173
174<h4>APP_PLATFORM</h4>
175<p>This variable contains the name of the target Android platform. For example, {@code android-3}
176specifies the Android 1.5 system images. For a complete list of platform names and corresponding
177Android system images, see <a href="{@docRoot}ndk/guides/stable_apis.html">Android NDK Native APIs
178</a>.</p>
179
180<h4>APP_STL</h4>
181<p>By default, the NDK build system provides C++ headers for the minimal C++ runtime library
182({@code system/lib/libstdc++.so}) provided by the Android system. In addition, it comes with
183alternative C++ implementations that you can use or link to in your own applications.
184Use {@code APP_STL} to select one of them. For information about the supported runtimes, and the
185features they offer, see <a href="{@docRoot}ndk/guides/cpp-support.html#runtimes">NDK Runtimes and
186Features</a>.
187
188<h4>APP_SHORT_COMMANDS</h4>
189<p>The equivalent of {@code LOCAL_SHORT_COMMANDS} in {@code Application.mk} for your whole project.
190For more information, see the documentation for this variable on
191<a href="{@docRoot}ndk/guides/android_mk.html">{@code Android.mk}</a>.</p>
192
193<h4>NDK_TOOLCHAIN_VERSION</h4>
194<p>Define this variable as either {@code 4.9} or {@code 4.8} to select a version of the GCC
195compiler. Version 4.9 is the default for 64-bit ABIs, and 4.8 is the default for 32-bit ABIs.
196To select a version of Clang, define this variable as {@code clang3.4}, {@code clang3.5}, or
197{@code clang}. Specifying {@code clang} chooses the most recent version of Clang.</p>
198
199<h4>APP_PIE</h4>
200<p>Starting from Android 4.1 (API level 16), Android's dynamic linker supports position-independent
201executables (PIE). From Android 5.0 (API level 21), executables require PIE.
202
203To use PIE to build your executables, set the {@code -fPIE} flag. This flag makes it harder to
204exploit memory corruption bugs by randomizing code location. By default, {@code ndk-build}
205automatically sets this value to {@code true} if your project targets {@code android-16} or higher.
206You may set it manually to either {@code true} or {@code false}.</p>
207
208<p>This flag applies only to executables. It has no effect when building shared or static
209libraries.</p>
210
211<p class="note"><strong>Note: </strong> PIE executables cannot run on Android releases prior to 4.1.
212<p>This restriction only applies to executables. It has no effect when building shared or static
213libraries.</p>
214
215<h4>APP_THIN_ARCHIVE</h4>
216<p>Sets the default value of {@code LOCAL_THIN_ARCHIVE} in the {@code Android.mk} file for all
217static library modules in this project. For more information, see the documentation for
218{@code LOCAL_THIN_ARCHIVE} on <a href="{@docRoot}ndk/guides/android_mk.html">{@code Android.mk}.</a>
219</p>
220