Android NDK APIs

使用 Android NDK 的一般方法:
1、假如想要使用foo这个模块,先要 #include <foo.h>, 然后链接 /system/lib/libfoo.so 。
(在 Android.mk 文件中加入 LOCAL_LDLIBS := -lfoo)

ndk-build 会自动链接 C库、数学库、C++库
android-3 -> Official Android 1.5 system images
android-4 -> Official Android 1.6 system images
android-5 -> Official Android 2.0 system images
android-6 -> Official Android 2.0.1 system images
android-7 -> Official Android 2.1 system images
android-8 -> Official Android 2.2 system images
android-9 -> Official Android 2.3 system images

Android 1.5 以上的系统,下面这些库可用:
1、C库(这个C库包含多线程支持,所以不需要指定 -lpthread,也不需要指定 -lrt )
      注意:内核头文件很没有稳定下来(今后可能变动),这些头文件是 <linux/*.h>  和 <asm/*.h>
2、数学库(也不需要指定 -lm)
3、C++库: 目前只有这些头文件可用。(不需要指定 -lstdc++ ,是自动链接的)
      <cstddef> <new> <utility> <stl_pair.h>
4、Android log:
      <android/log.h>   android系统的log功能
      要用这个API,需要指定 LOCAL_LDLIBS := -llog
5、zlib库:
      <zlib.h> 和 <zconf.h>
      链接:  -lz   ( /system/lib/libz.so)
      http://www.zlib.net/manual.html
6、动态连接器库:
      <dlfcn.h>
      这个库提供的函数例如: dlopen()/dlsym()/dlclose()
      LOCAL_LDLIBS := -ldl ( /system/lib/libdl.so)
----------------------- 以上由 android-3提供 ---------------------------------
1、OpenGL ES 1.x 库
       <GLES/gl.h> 和 <GLES/glext.h>
       LOCAL_LDLIBS := -lGLESv1_CM.so( /system/lib/libGLESv1_CM.so)
      <uses-feature>   ( http://developer.android.com/guide/topics/manifest/uses-feature-element.html)

----------------------- 以上是 android-4 新增的NDK API -------------------------
1、OpenGL ES 2.0
      <GLES2/gl2.h> 和 <GLES2/gl2ext.h>
      LOCAL_LDLIBS := -lGLESv2.so  ( /system/lib/libGLESv2.so)
      <uses-feature>
注意: 目前模拟器还不支持这个库
--------------------------以上是 android-5 新增的内容  ------------------------------
1、jnigraphics 库
      一个小型的C语言库,提供对Java中的 bitmap 对象的操作。
     包含: <android/bitmap.h>
     链接: LOCAL_LDLIBS += -ljnigraphics
     典型用法:
           a) 用 AndroidBitmap_getInfo() 函数从位图句柄(从JNI得到)获得信息(宽度、高度、像素格式)
           b) 用 AndroidBitmap_lockPixels() 对像素缓存上锁,即获得该缓存的指针。
           c) 用C/C++ 对这个缓冲区进行读写
           d) 用 AndroidBitmap_unlockPixels() 解锁

------------------------ 以上是 android-8 新增 -----------------------------
1、OpenSL ES 本地音频库
     头文件: <SLES/OpenSLES.h> 和 <SLES/OpenSLES_Platform.h>
     链接: LOCAL_LDLIBS += -lOpenSLES (libOpenSLES.so)

----------------------- 以上是 android-9 新增的 -------------------------------
从android-9 开始,就可以完全用C/C++来写android程序了(完全脱离java)
但是,仍然没有脱离java虚拟机,许多东西还是需要通过jni来访问 (参考 docs/NATIVE-ACTIVITY.html )
头文件:
       <android/native_activity.h>
1、活动(Activity)生命期的管理
头文件: <android/looper.h>   <android/input.h>   <android/keycodes.h>   <android/sensor.h>
2、监听事件和传感器
头文件:  <android/rect.h>  <android/window.h>  <android/native_window.h>  <android/native_window_jni.h>
3、窗口管理(包括对像素缓存加锁、解锁)
头文件: <android/configuration.h> <android/asset_manager.h> <android/storage_manager.h>
                 <android/obb.h>  对嵌入 apk中的资源(或OBB文件)进行只读的、直接访问。
                OBB(Opaque Binary Blob)文件,新特性,允许把较大的数据放在apk之外(对于游戏程序有用)

上面提到的头文件在 "libandroid.so" 共享库中。
链接方法:  LOCAL_LDLIBS += -landroid

猜你喜欢

转载自darar.iteye.com/blog/1828170