http://developer.android.com/sdk/ndk/overview.html
The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications.
Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. This can provide benefits to certain classes of applications, in the form of reuse of existing code and in some cases increased speed.
The NDK provides:
· A set of tools and build files used to generate native code libraries from C and C++ sources
· A way to embed the corresponding native libraries into an application package file (.apk
) that can be deployed on Android devices
· A set of native system headers and libraries that will be supported in all future versions of the Android platform, starting from Android 1.5. Applications that use native activities must be run on Android 2.3 or later.
· Documentation, samples, and tutorials
The latest release of the NDK supports these ARM instruction sets:
· ARMv5TE (including Thumb-1 instructions)
· ARMv7-A (including Thumb-2 and VFPv3-D16 instructions, with optional support for NEON/VFPv3-D32 instructions)
Future releases of the NDK will also support:
· x86 instructions (see CPU-ARCH-ABIS.HTML for more information)
ARMv5TE machine code will run on all ARM-based Android devices. ARMv7-A will run only on devices such as the Verizon Droid or Google Nexus One that have a compatible CPU. The main difference between the two instruction sets is that ARMv7-A supports hardware FPU, Thumb-2, and NEON instructions. You can target either or both of the instruction sets — ARMv5TE is the default, but switching to ARMv7-A is as easy as adding a single line to the application's Application.mk
file, without needing to change anything else in the file. You can also build for both architectures at the same time and have everything stored in the final .apk
. Complete information is provided in the CPU-ARCH-ABIS.HTML in the NDK package.
The NDK provides stable headers for libc (the C library), libm (the Math library), OpenGL ES (3D graphics library), the JNI interface, and other libraries, as listed in the Development Tools section.
When to Develop in Native Code
The NDK will not benefit most applications. As a developer, you need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but always increases application complexity. In general, you should only use native code if it is essential to your application, not just because you prefer to program in C/C++.
Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.
The Android framework provides two ways to use native code:
· Write your application using the Android framework and use JNI to access the APIs provided by the Android NDK. This technique allows you to take advantage of the convenience of the Android framework, but still allows you to write native code when necessary. You can install applications that use native code through the JNI on devices that run Android 1.5 or later.
· Write a native activity, which allows you to implement the lifecycle callbacks in native code. The Android SDK provides theNativeActivity
onCreate
(
)
,onPause
()
, onResume
()
, etc). You can implement the callbacks in your native code to handle these events when they occur. Applications that use native activities must be run on Android 2.3 (API Level 9) or later. Development tools
· libz (Zlib compression) headers
· liblog (Android logging) header
· OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
· libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
· A Minimal set of headers for C++ support
· OpenSL ES native audio libraries
· Android native application APIS
Documentation
· INSTALL.HTML — describes how to install the NDK and configure it for your host system
· OVERVIEW.HTML — provides an overview of the NDK capabilities and usage
· CPLUSPLUS-SUPPORT.HTML — describes the C++ support provided in the Android NDK
· CPU-ARCH-ABIS.HTML — a description of supported CPU architectures and how to target them.
· CPU-ARM-NEON.HTML — a description of how to build with optional ARM NEON / VFPv3-D32 instructions.
· CHANGES.HTML — a complete list of changes to the NDK across all releases.
· DEVELOPMENT.HTML — describes how to modify the NDK and generate release packages for it
· HOWTO.HTML — information about common tasks associated with NDK development
· IMPORT-MODULE.HTML — describes how to share and reuse modules
· LICENSES.HTML — information about the various open source licenses that govern the Android NDK
· NATIVE-ACTIVITY.HTML — describes how to implement native activities
· NDK-BUILD.HTML — describes the usage of the ndk-build script
· NDK-GDB.HTML — describes how to use the native code debugger
· PREBUILTS.HTML — information about how shared and static prebuilt libraries work
· STABLE-APIS.HTML — a complete list of the stable APIs exposed by headers in the NDK.
· OVERVIEW.HTML — provides an overview of the "bionic" C library and the features it offers.
Sample applications
· native-plasma — a version of bitmap-plasma implemented with a native activity.
Next, build the sample Android applications that use the shared libraries:
Exploring the hello-jni Sample
The main components of the sample include:
· A tests/
directory that contains unit test code.
a. Click File > New Android Project...
b. Select the Create project from existing source radio button.
c. Select any API level above Android 1.5.
d. In the Location field, click Browse... and select the <ndk-root>/samples/hello-jni
directory.
a. Change to the <ndk-root>/samples/hello-jni
directory.
b. Run the following command to generate a build.xml file:
2. Compile the native code using the ndk
-build
command.
Exploring the native-activity Sample Application
To build this sample application:
a. Click File > New Android Project...
b. Select the Create project from existing source radio button.
c. Select any API level above Android 2.3.
a. Change to the <ndk-root>/samples/native-activity
directory.
b. Run the following command to generate a build.xml file:
2. Compile the native code using the ndk
-build
command.
The Android SDK
· A complete Android SDK installation (including all dependencies) is required.
· Android 1.5 SDK or later version is required.
Supported operating systems
· Windows XP (32-bit) or
· Mac OS X 10.4.8 or later (x86 only)
· Linux (32- or 64-bit, tested on Linux Ubuntu Dapper Drake)
Required development tools
· A recent version of awk (either GNU Awk or Nawk) is also required.
0 件のコメント:
コメントを投稿