使用 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
分享到:
相关推荐
This book provides you with a number of clear step-by-step recipes which will help you to start developing mobile games with Android NDK and boost your productivity debugging them on your computer....
It controls camera devices by NDK camera2 APIs which becomes one of [public libraries](http://android-developers.blogspot.kr/2016/06/improving-stability-with-private-cc.html) in Android N. Pre-...
In previous chapter, you explored the logging, debugging, and troubleshooting tools and techniques pertaining to Android native application development....the native APIs provided by the Android NDK.
How to build your first real-world quality game app for Android smartphones and tablets using the power of the Android C++ APIs as found in the NDK How to do professional level, quality game design, ...
GoogleMap APIs SDK Google Glass SDK Google TV Addon Android SDK Extras Support Library SDK Samples NDK Android L Preview System Image JDK ADT Bundle ADT Plugin Gradle Android Gradle Plugin DSL 在线...
Since their release, Android has progressed with the debut of Android 4.0, adding better fonts, new User Interface and Experience (UI/UX) APIs, tablet considerations, multi-touch capabilities, multi-...
ARCore SDK for Android ... All rights reserved. This SDK provides APIs for all ...See the Quickstart for Android Java or Quickstart for Android NDK developer guide. API Reference See the ARCore SDK for Java
That’s where this book comes in Spanning 466 pages, The Busy Coder’s Guide to Android Development covers a wide range of Android capabilities and APIs, from creating simple user interfaces, to ...
Since their release, Android has progressed with the debut of Android 4.0, adding better fonts, new User Interface and Experience (UI/UX) APIs, tablet considerations, multi-touch capabilities, multi-...
The Media Projection APIs AlarmManager and the Scheduled Service Pattern PowerManager and WakeLocks JobScheduler Accessing Location-Based Services The Fused Location Provider Working with the ...
我正在研究在 Android 应用程序上使用英特尔 PIN。 在这个 repo 中,我提供了一组脚本来安装工具链。 我让 PIN 工作,但我还没有考虑...# export ANDROID_PIN_APIS=19 # Downloads: * Android SDK # * Requested Pin #
包括所有需要的库对于在您的local.properties中设置的ndk构建ndk.dir=C\:\\Android\\android-ndk-r10b 是的,您需要\\作为文件夹路径 支持的Apis: android.hardware.camera android.hardware.camera2 索尼Camera ...
图书馆Libtorrent VideoLan有关VLC端口的信息https://wiki.videolan.org/AndroidCompile/ https://wiki.videolan.org/LibVLC/ AsyncHTTP [Android的TMDB包装器](https://github.com/UweTrottmann/tmdb -java)...