David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 1 | Android NDK Stable APIs: |
| 2 | ======================== |
| 3 | |
| 4 | This is the list of stable APIs/ABIs exposed by the Android NDK. |
| 5 | |
| 6 | I. Purpose: |
| 7 | ----------- |
| 8 | |
| 9 | Each API corresponds to a set of headers files, and a shared library file |
| 10 | that contains the corresponding implementation, and which must be linked |
| 11 | against by your native code. |
| 12 | |
| 13 | For example, to use system library "Foo", you would include a header |
| 14 | like <foo.h> in your code, then tell the build system that your native |
| 15 | module needs to link to /system/lib/libfoo.so at load-time by adding |
| 16 | the following line to your Android.mk file: |
| 17 | |
| 18 | LOCAL_LDLIBS := -lfoo |
| 19 | |
| 20 | Note that the build system automatically links the C library, the Math |
| 21 | library and the C++ support library to your native code, there is no |
| 22 | need to list them in a LOCAL_LDLIBS line. |
| 23 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 24 | There are several "API Levels" defined. Each API level corresponds to |
| 25 | a given Android system platform release. The following levels are |
| 26 | currently supported: |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 27 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 28 | android-3 -> Official Android 1.5 system images |
David 'Digit' Turner | 9eff6cb | 2009-10-21 14:43:09 -0700 | [diff] [blame] | 29 | android-4 -> Official Android 1.6 system images |
David 'Digit' Turner | f5862d8 | 2009-11-18 18:05:55 -0800 | [diff] [blame] | 30 | android-5 -> Official Android 2.0 system images |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 31 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 32 | II. Android-3 Stable Native APIs: |
| 33 | --------------------------------- |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 34 | |
| 35 | All the APIs listed below are available for developing native code that |
| 36 | runs on Android 1.5 system images and above. |
| 37 | |
| 38 | The C Library: |
| 39 | -------------- |
| 40 | |
| 41 | The C library headers, as they are defined on Android 1.5 are available |
| 42 | through their standard names (<stdlib.h>, <stdio.h>, etc...). If one header |
| 43 | is not there at build time, it's because its implementation is not available |
| 44 | on a 1.5 system image. |
| 45 | |
| 46 | The build system automatically links your native modules to the C library, |
| 47 | you don't need to add it to LOCAL_LDLIBS. |
| 48 | |
| 49 | Note that the Android C library includes support for pthread (<pthread.h>), |
| 50 | so "LOCAL_LIBS := -lpthread" is not needed. The same is true for real-time |
| 51 | extensions (-lrt on typical Linux distributions). |
| 52 | |
| 53 | |
| 54 | ** VERY IMPORTANT NOTE: ****************************************************** |
| 55 | * |
| 56 | * The kernel-specific headers in <linux/...> and <asm/...> are not considered |
| 57 | * stable at this point. Avoid including them directly because some of them |
| 58 | * are likely to change in future releases of the platform. This is especially |
| 59 | * true for anything related to specific hardware definitions. |
| 60 | * |
| 61 | ****************************************************************************** |
| 62 | |
| 63 | |
| 64 | The Math Library: |
| 65 | ----------------- |
| 66 | |
| 67 | <math.h> is available, and the math library is automatically linked to your |
| 68 | native modules at build time, so there is no need to list "-lm" through |
| 69 | LOCAL_LDLIBS. |
| 70 | |
| 71 | |
| 72 | |
| 73 | C++ Library: |
| 74 | ------------ |
| 75 | |
| 76 | An *extremely* minimal C++ support API is available. For Android 1.5, this is |
| 77 | currently limited to the following headers: |
| 78 | |
| 79 | <cstddef> |
| 80 | <new> |
| 81 | <utility> |
| 82 | <stl_pair.h> |
| 83 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 84 | They may not contain all definitions required by the standard. Notably, |
| 85 | support for C++ exceptions and RTTI is not available with Android 1.5 system |
| 86 | images. |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 87 | |
| 88 | The C++ support library (-lstdc++) is automatically linked to your native |
| 89 | modules too, so there is no need to list it through LOCAL_LDLIBS |
| 90 | |
| 91 | |
| 92 | |
| 93 | Android-specific Log Support: |
| 94 | ----------------------------- |
| 95 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 96 | <android/log.h> contains various definitions that can be used to send log |
| 97 | messages to the kernel from your native code. Please have a look at its |
| 98 | content in (build/platforms/android-3/common/include/android/log.h), which |
| 99 | contain many informative comments on how to use it. |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 100 | |
| 101 | You should be able to write helpful wrapper macros for your own usage to |
| 102 | access this facility. |
| 103 | |
| 104 | If you use it, your native module should link to /system/lib/liblog.so with: |
| 105 | |
| 106 | LOCAL_LDLIBS := -llog |
| 107 | |
| 108 | |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 109 | ZLib Compression Library: |
| 110 | ------------------------- |
| 111 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 112 | <zlib.h> and <zconf.h> are available and can be used to use the ZLib |
| 113 | compression library. Documentation for it is at the ZLib page: |
| 114 | |
| 115 | http://www.zlib.net/manual.html |
David 'Digit' Turner | a9e8d43 | 2009-06-01 20:38:19 +0200 | [diff] [blame] | 116 | |
| 117 | If you use it, your native module should link to /system/lib/libz.so with: |
| 118 | |
| 119 | LOCAL_LDLIBS := -lz |
| 120 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 121 | |
| 122 | III. Android-4 Stable Native APIs: |
| 123 | ---------------------------------- |
| 124 | |
| 125 | All the APIs listed below are available for developing native code that runs |
David 'Digit' Turner | 9eff6cb | 2009-10-21 14:43:09 -0700 | [diff] [blame] | 126 | on Android 1.6 system images and above, |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 127 | |
| 128 | |
| 129 | The OpenGL ES 1.x Library: |
| 130 | -------------------------- |
| 131 | |
| 132 | The standard OpenGL ES headers <GLES/gl.h> and <GLES/glext.h> contain the |
| 133 | declarations needed to perform OpenGL ES 1.x rendering calls from native |
| 134 | code. |
| 135 | |
| 136 | If you use them, your native module should link to /system/lib/libGLESv1_CM.so |
| 137 | as in: |
| 138 | |
| 139 | LOCAL_LDLIBS := -lGLESv1_CM.so |
| 140 | |
David 'Digit' Turner | eef791e | 2010-01-13 16:50:57 -0800 | [diff] [blame] | 141 | |
| 142 | The '1.x' here refers to both versions 1.0 and 1.1 of the OpenGL ES APIs. |
| 143 | Please note that: |
| 144 | |
| 145 | - OpenGL ES 1.0 is supported on *all* Android-based devices. |
| 146 | - OpenGL ES 1.1 is fully supported only on specific devices that |
| 147 | have the corresponding GPU. |
| 148 | |
| 149 | This is because Android comes with a 1.0-capable software renderer that can |
| 150 | be used on GPU-less devices. |
| 151 | |
| 152 | Developers should query the OpenGL ES version string and extension string |
| 153 | to know if the current device supports the features they need. See the |
| 154 | description of glGetString() in the specification to see how to do that: |
| 155 | |
| 156 | http://www.khronos.org/opengles/sdk/1.1/docs/man/glGetString.xml |
| 157 | |
| 158 | Additionally, developers must put a <uses-feature> tag in their manifest |
| 159 | file to indicate which version of OpenGL ES their application requires. See |
| 160 | the documentation linked below for details: |
| 161 | |
| 162 | http://developer.android.com/guide/topics/manifest/uses-feature-element.html |
| 163 | |
David 'Digit' Turner | d7e5aae | 2009-07-27 16:23:42 +0200 | [diff] [blame] | 164 | Please note that, at the moment, native headers and libraries for the EGL APIs |
| 165 | are *not* available. EGL is used to perform surface creation and flipping |
| 166 | (instead of rendering). The corresponding operations must be performed in your |
| 167 | VM application instead, for example with a GLSurfaceView, as described here: |
| 168 | |
| 169 | http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html |
David 'Digit' Turner | 197a8fe | 2009-07-29 19:02:21 +0200 | [diff] [blame] | 170 | |
| 171 | The "san-angeles" sample application shows how you can do that, while |
| 172 | rendering each frame in native code. This is a small Android port of the |
| 173 | excellent "San Angeles Observation" demo program. For more information about |
| 174 | it, see: |
| 175 | |
| 176 | http://jet.ro/visuals/san-angeles-observation/ |
David 'Digit' Turner | 9eff6cb | 2009-10-21 14:43:09 -0700 | [diff] [blame] | 177 | |
| 178 | |
| 179 | IV. Android-5 Stable Native APIs: |
| 180 | ---------------------------------- |
| 181 | |
| 182 | All the APIs listed below are available for developing native code that runs |
David 'Digit' Turner | a13e890 | 2009-12-09 15:46:07 -0800 | [diff] [blame] | 183 | on Android 2.0 system images and above. |
David 'Digit' Turner | 9eff6cb | 2009-10-21 14:43:09 -0700 | [diff] [blame] | 184 | |
| 185 | |
| 186 | The OpenGL ES 2.0 Library: |
| 187 | -------------------------- |
| 188 | |
| 189 | The standard OpenGL ES 2.0 headers <GLES2/gl2.h> and <GLES2/gl2ext.h> contain the |
| 190 | declarations needed to perform OpenGL ES 2.0 rendering calls from native code. |
| 191 | This includes the ability to define and use vertex and fragment shaders using the |
| 192 | GLSL language. |
| 193 | |
| 194 | If you use them, your native module should link to /system/lib/libGLESv2.so |
| 195 | as in: |
| 196 | |
| 197 | LOCAL_LDLIBS := -lGLESv2.so |
| 198 | |
David 'Digit' Turner | eef791e | 2010-01-13 16:50:57 -0800 | [diff] [blame] | 199 | Not all devices support OpenGL ES 2.0, developers should thus query the |
| 200 | implementation's version and extension strings, and put a <uses-feature> |
| 201 | tag in their Android manifest. See Section III above for details. |
| 202 | |
David 'Digit' Turner | 9eff6cb | 2009-10-21 14:43:09 -0700 | [diff] [blame] | 203 | Please note that, at the moment, native headers and libraries for the EGL APIs |
| 204 | are *not* available. EGL is used to perform surface creation and flipping |
| 205 | (instead of rendering). The corresponding operations must be performed in your |
| 206 | VM application instead, for example with a GLSurfaceView, as described here: |
| 207 | |
| 208 | http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html |
David 'Digit' Turner | 27ad1ef | 2009-10-22 16:59:10 -0700 | [diff] [blame] | 209 | |
| 210 | The "hello-gl2" sample application demonstrate this. It is used to draw a very |
| 211 | simple triangle with the help of a vertex and fragment shaders. |
David 'Digit' Turner | a13e890 | 2009-12-09 15:46:07 -0800 | [diff] [blame] | 212 | |
| 213 | IMPORTANT NOTE: |
| 214 | The Android emulator does not support OpenGL ES 2.0 hardware emulation |
| 215 | at this time. Running and testing code that uses this API requires a |
| 216 | real device with such capabilities. |