• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html><body><pre>Android NDK Stable APIs:
2========================
3
4This is the list of stable APIs/ABIs exposed by the Android NDK.
5
6I. Purpose:
7-----------
8
9Each API corresponds to a set of headers files, and a shared library file
10that contains the corresponding implementation, and which must be linked
11against by your native code.
12
13For example, to use system library "Foo", you would include a header
14like &lt;foo.h&gt; in your code, then tell the build system that your native
15module needs to link to /system/lib/libfoo.so at load-time by adding
16the following line to your Android.mk file:
17
18  LOCAL_LDLIBS := -lfoo
19
20Note that the build system automatically links the C library, the Math
21library and the C++ support library to your native code, there is no
22need to list them in a LOCAL_LDLIBS line.
23
24There are several "API Levels" defined. Each API level corresponds to
25a given Android system platform release. The following levels are
26currently supported:
27
28    android-3      -&gt; Official Android 1.5 system images
29    android-4      -&gt; Official Android 1.6 system images
30    android-5      -&gt; Official Android 2.0 system images
31    android-6      -&gt; Official Android 2.0.1 system images
32    android-7      -&gt; Official Android 2.1 system images
33    android-8      -&gt; Official Android 2.2 system images
34    android-9      -&gt; Official Android 2.3 system images
35
36Note that android-6 and android-7 are the same as android-5 for the NDK,
37i.e. they provide exactly the same native ABIs!
38
39IMPORTANT:
40    The headers corresponding to a given API level are now located
41    under $NDK/platforms/android-&lt;level&gt;/arch-arm/usr/include
42
43
44II. Android-3 Stable Native APIs:
45---------------------------------
46
47All the APIs listed below are available for developing native code that
48runs on Android 1.5 system images and above.
49
50The C Library:
51--------------
52
53The C library headers, as they are defined on Android 1.5 are available
54through their standard names (&lt;stdlib.h&gt;, &lt;stdio.h&gt;, etc...). If one header
55is not there at build time, it's because its implementation is not available
56on a 1.5 system image.
57
58The build system automatically links your native modules to the C library,
59you don't need to add it to LOCAL_LDLIBS.
60
61Note that the Android C library includes support for pthread (&lt;pthread.h&gt;),
62so "LOCAL_LIBS := -lpthread" is not needed. The same is true for real-time
63extensions (-lrt on typical Linux distributions).
64
65
66** VERY IMPORTANT NOTE: ******************************************************
67*
68*  The kernel-specific headers in &lt;linux/...&gt; and &lt;asm/...&gt; are not considered
69*  stable at this point. Avoid including them directly because some of them
70*  are likely to change in future releases of the platform. This is especially
71*  true for anything related to specific hardware definitions.
72*
73******************************************************************************
74
75
76The Math Library:
77-----------------
78
79&lt;math.h&gt; is available, and the math library is automatically linked to your
80native modules at build time, so there is no need to list "-lm" through
81LOCAL_LDLIBS.
82
83
84
85C++ Library:
86------------
87
88An *extremely* minimal C++ support API is available. For Android 1.5, this is
89currently limited to the following headers:
90
91   &lt;cstddef&gt;
92   &lt;new&gt;
93   &lt;utility&gt;
94   &lt;stl_pair.h&gt;
95
96They may not contain all definitions required by the standard. Notably,
97support for C++ exceptions and RTTI is not available with Android 1.5 system
98images.
99
100The C++ support library (-lstdc++) is automatically linked to your native
101modules too, so there is no need to list it through LOCAL_LDLIBS
102
103
104
105Android-specific Log Support:
106-----------------------------
107
108&lt;android/log.h&gt; contains various definitions that can be used to send log
109messages to the kernel from your native code. Please have a look at its
110content in (build/platforms/android-3/common/include/android/log.h), which
111contain many informative comments on how to use it.
112
113You should be able to write helpful wrapper macros for your own usage to
114access this facility.
115
116If you use it, your native module should link to /system/lib/liblog.so with:
117
118  LOCAL_LDLIBS := -llog
119
120
121ZLib Compression Library:
122-------------------------
123
124&lt;zlib.h&gt; and &lt;zconf.h&gt; are available and can be used to use the ZLib
125compression library. Documentation for it is at the ZLib page:
126
127    http://www.zlib.net/manual.html
128
129If you use it, your native module should link to /system/lib/libz.so with:
130
131  LOCAL_LDLIBS := -lz
132
133
134Dynamic Linker Library:
135-----------------------
136
137&lt;dlfcn.h&gt; is available and can be used to use the dlopen()/dlsym()/dlclose()
138functions provided by the Android dynamic linker. You will need to link
139against /system/lib/libdl.so with:
140
141  LOCAL_LDLIBS := -ldl
142
143
144III. Android-4 Stable Native APIs:
145----------------------------------
146
147All the APIs listed below are available for developing native code that runs
148on Android 1.6 system images and above,
149
150
151The OpenGL ES 1.x Library:
152--------------------------
153
154The standard OpenGL ES headers &lt;GLES/gl.h&gt; and &lt;GLES/glext.h&gt; contain the
155declarations needed to perform OpenGL ES 1.x rendering calls from native
156code.
157
158If you use them, your native module should link to /system/lib/libGLESv1_CM.so
159as in:
160
161  LOCAL_LDLIBS := -lGLESv1_CM
162
163
164The '1.x' here refers to both versions 1.0 and 1.1 of the OpenGL ES APIs.
165Please note that:
166
167  - OpenGL ES 1.0 is supported on *all* Android-based devices.
168  - OpenGL ES 1.1 is fully supported only on specific devices that
169    have the corresponding GPU.
170
171This is because Android comes with a 1.0-capable software renderer that can
172be used on GPU-less devices.
173
174Developers should query the OpenGL ES version string and extension string
175to know if the current device supports the features they need. See the
176description of glGetString() in the specification to see how to do that:
177
178    http://www.khronos.org/opengles/sdk/1.1/docs/man/glGetString.xml
179
180Additionally, developers must put a &lt;uses-feature&gt; tag in their manifest
181file to indicate which version of OpenGL ES their application requires. See
182the documentation linked below for details:
183
184 http://developer.android.com/guide/topics/manifest/uses-feature-element.html
185
186Please note that, at the moment, native headers and libraries for the EGL APIs
187are *not* available. EGL is used to perform surface creation and flipping
188(instead of rendering). The corresponding operations must be performed in your
189VM application instead, for example with a GLSurfaceView, as described here:
190
191http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html
192
193The "san-angeles" sample application shows how you can do that, while
194rendering each frame in native code. This is a small Android port of the
195excellent "San Angeles Observation" demo program. For more information about
196it, see:
197
198    http://jet.ro/visuals/san-angeles-observation/
199
200
201IV. Android-5 Stable Native APIs:
202----------------------------------
203
204All the APIs listed below are available for developing native code that runs
205on Android 2.0 system images and above.
206
207
208The OpenGL ES 2.0 Library:
209--------------------------
210
211The standard OpenGL ES 2.0 headers &lt;GLES2/gl2.h&gt; and &lt;GLES2/gl2ext.h&gt; contain the
212declarations needed to perform OpenGL ES 2.0 rendering calls from native code.
213This includes the ability to define and use vertex and fragment shaders using the
214GLSL language.
215
216If you use them, your native module should link to /system/lib/libGLESv2.so
217as in:
218
219  LOCAL_LDLIBS := -lGLESv2
220
221Not all devices support OpenGL ES 2.0, developers should thus query the
222implementation's version and extension strings, and put a &lt;uses-feature&gt;
223tag in their Android manifest. See Section III above for details.
224
225Please note that, at the moment, native headers and libraries for the EGL APIs
226are *not* available. EGL is used to perform surface creation and flipping
227(instead of rendering). The corresponding operations must be performed in your
228VM application instead, for example with a GLSurfaceView, as described here:
229
230http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html
231
232The "hello-gl2" sample application demonstrate this. It is used to draw a very
233simple triangle with the help of a vertex and fragment shaders.
234
235IMPORTANT NOTE:
236    The Android emulator does not support OpenGL ES 2.0 hardware emulation
237    at this time. Running and testing code that uses this API requires a
238    real device with such capabilities.
239
240
241IV. Android-8 Stable Native APIs:
242----------------------------------
243
244All the APIs listed below are available for developing native code that runs
245on Android 2.2 system images and above.
246
247
248The 'jnigraphics' Library:
249--------------------------
250
251This is a tiny library that exposes a stable, C-based, interface that allows
252native code to reliably access the pixel buffers of Java bitmap objects.
253
254To use it, include the &lt;android/bitmap.h&gt; header in your source code, and
255and link to the jnigraphics library as in:
256
257  LOCAL_LDLIBS += -ljnigraphics
258
259For details, read the source header at the following location:
260
261    build/platforms/android-8/arch-arm/usr/include/android/bitmap.h
262
263Briefly, typical usage should look like:
264
265    1/ Use AndroidBitmap_getInfo() to retrieve information about a
266       given bitmap handle from JNI (e.g. its width/height/pixel format)
267
268    2/ Use AndroidBitmap_lockPixels() to lock the pixel buffer and
269       retrieve a pointer to it. This ensures the pixels will not move
270       until AndroidBitmap_unlockPixels() is called.
271
272    3/ Modify the pixel buffer, according to its pixel format, width,
273       stride, etc.., in native code.
274
275    4/ Call AndroidBitmap_unlockPixels() to unlock the buffer.
276
277
278V. Android-9 Stable Native APIs:
279--------------------------------
280
281All the APIs listed below are available for developing native code that runs
282on Android &gt; 2.2 system images and above.
283
284The OpenSL ES native audio Library:
285-----------------------------------
286
287Android native audio is based on Khronos Group OpenSL ES&#0153; 1.0.1.
288
289The standard OpenSL ES headers &lt;SLES/OpenSLES.h&gt; and &lt;SLES/OpenSLES_Platform.h&gt;
290contain the declarations needed to perform audio input and output from the
291native side of Android.
292
293NOTE: Despite the fact that the current OpenSL ES specification uses
294      &lt;OpenSLES.h&gt; to include these headers, Khronos is currently modifying
295      the document to recommend &lt;SLES/OpenSLES.h&gt; instead, hence the later
296      approach was adopted for Android.
297
298This API level also provides Android-specific extensions, see the content
299of &lt;SLES/OpenSLES_Android.h&gt; and &lt;SLES/OpenSLES_AndroidConfiguration.h&gt; for
300details.
301
302The system library named "libOpenSLES.so" implements the public native audio
303functions. Use the following to link your modules against it:
304
305    LOCAL_LDLIBS += -lOpenSLES
306
307
308The Android native application APIs:
309------------------------------------
310
311Starting from API level 9, it is possible to entirely write an Android
312application with native code (i.e. without any Java). That does not mean
313that your code does not run inside a VM though, and most of the features
314of the platform will still need to be accessed through JNI.
315
316For more information about this topic, please read the dedicated
317document named docs/NATIVE-ACTIVITY.html (TODO: WRITE DOC).
318
319The following headers correspond to these new native APIs (see comments
320inside them for more details):
321
322  &lt;android/native_activity.h&gt;
323
324        Activity lifecycle management (and general entry point)
325
326  &lt;android/looper.h&gt;
327  &lt;android/input.h&gt;
328  &lt;android/keycodes.h&gt;
329  &lt;android/sensor.h&gt;
330
331        To Listen to input events and sensors directly from native code.
332
333  &lt;android/rect.h&gt;
334  &lt;android/window.h&gt;
335  &lt;android/native_window.h&gt;
336  &lt;android/native_window_jni.h&gt;
337
338        Window management, including the ability to lock/unlock the pixel
339        buffer to draw directly into it.
340
341  &lt;android/configuration.h&gt;
342  &lt;android/asset_manager.h&gt;
343  &lt;android/storage_manager.h&gt;
344  &lt;android/obb.h&gt;
345        Direct (read-only) access to assets embedded in your .apk. or
346        the Opaque Binary Blob (OBB) files, a new feature of Android X.X
347        that allows one to distribute large amount of application data
348        outside of the .apk (useful for game assets, for example).
349
350All the corresponding functions are provided by the "libandroid.so" library
351version that comes with API level 9. To use it, use the following:
352
353    LOCAL_LDLIBS += -landroid
354</pre></body></html>
355