Sample applications
The NDK includes sample applications that illustrate how to use native code in your Android applications:
hello-jni
— a simple application that loads a string from a native method implemented in a shared library and then displays it in the application UI.- 从shared library 里 native method 获取一个字符串,显示在程序UI中
two-libs
— a simple application that loads a shared library dynamically and calls a native method provided by the library. In this case, the method is implemented in a static library imported by the shared library.- 动态加载shared library,调用其中的方法。在这个例子里,方法在一个statice library中实现,从shared library导入。
san-angeles
— a simple application that renders 3D graphics through the native OpenGL ES APIs, while managing activity lifecycle with aGLSurfaceView
object.- 使用natvie OpenGL ES APIs render 3D图形。
hello-gl2
— a simple application that renders a triangle using OpenGL ES 2.0 vertex and fragment shaders.- 图形相关
hello-neon
— a simple application that shows how to use thecpufeatures
library to check CPU capabilities at runtime, then use NEON intrinsics if supported by the CPU. Specifically, the application implements two versions of a tiny benchmark for a FIR filter loop, a C version and a NEON-optimized version for devices that support it.- CPU相关
bitmap-plasma
— a simple application that demonstrates how to access the pixel buffers of AndroidBitmap
objects from native code, and uses this to generate an old-school "plasma" effect.- Bitmap相关
native-activity
— a simple application that demonstrates how to use the native-app-glue static library to create a native activity- native activity
native-plasma
— a version of bitmap-plasma implemented with a native activity.
For each sample, the NDK includes the corresponding C source code and the necessary Android.mk and Application.mk files. There are located under <ndk>/samples/<name>/
and their source code can be found under <ndk>/samples/<name>/jni/
.
对于每个sample,NDK里提供了相应的C源代码和必要的Android.mk和Application.mk文件。它们位于<ndk>/samples/<name>/,源代码位于<ndk>/samples/<name>/jni/
You can build the shared libraries for the sample apps by going into <ndk>/samples/<name>/
then calling the ndk-build
command. The generated shared libraries will be located under <ndk>/samples/<name>/libs/armeabi/
for (ARMv5TE machine code) and/or<ndk>/samples/<name>/libs/armeabi-v7a/
for (ARMv7 machine code).
你可以到<ndk>/samples/<name>/
后调用ndk-build命令来编译shared libraries。生成的shared libraries位于<ndk>/samples/<name>/libs/armeabi/ (ARMv5TE machine code)和<ndk>/samples/<name>/libs/armeabi-v7a/
(ARMv7 machine code).
Next, build the sample Android applications that use the shared libraries:
- If you are developing in Eclipse with ADT, use the New Project Wizard to create a new Android project for each sample, using the "Import from Existing Source" option and importing the source from
<ndk>/apps/<app_name>/project/
. Then, set up an AVD, if necessary, and build/run the application in the emulator. - If you are developing with Ant, use the
android
tool to create the build file for each of the sample projects at<ndk>/apps/<app_name>/project/
. Then set up an AVD, if necessary, build your project in the usual way, and run it in the emulator.
For more information about developing with the Android SDK tools and what you need to do to create, build, and run your applications, see theOverview section for developing on Android.