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