Android* NDK for Intel® Architecture

Objective

This whitepaper discusses the Android* NDK, a tool set for developing Android* applications with embedded native code. It describes the basic coding structures of NDK applications. It also provides instructions on how to install the NDK, and how to use the NDK to build applications.

Table of Contents

  1. Introduction to the Android* NDK
  2. When to Use the NDK
  3. System Requirements
  4. Installing the NDK
  5. The Structure of NDK Applications
  6. Building NDK Applications
  7. Debugging NDK Applications
  8. Summary

Introduction to the Android* NDK

The NDK helps the Android* developer include C or C++ code in their applications. It consists of the following components:

  • A set of cross-tool chains and build scripts used to generate binary libraries for Intel® x86 architecture from C/C++ source files on your development platforms
  • Methods to package the native binary libraries into apk files to be installed on the Intel® Atom™ processor-based devices
  • A set of native headers and libraries supported by the Android* platforms

When to Use the NDK

The main goals of the NDK include:

  • To re-use the logic and source code implemented in C or C++
  • Under some circumstances, to achieve higher performance

Coding in C or C++ does not always result in higher performance of the applications. Instead it always increases the complexity of the code. Outside of the two main goals discussed above, we encourage developers to implement new functionalities solely based on the Android* SDK.

System Requirements

The Android* SDK

  • Android* 1.5 or later
  • Applications that use native activities require Android* 2.3 or later

Java*

  • JDK 1.5 or 1.6

Operating Systems

  • Linux (32 or 64-bit, Ubuntu 11.04 or later, Fedora F-12 or later )
  • Windows XP* (32-bit), Windows Vista* or Win 7* (32 or 64-bit), with Cygwin 1.7 or higher

Installing the NDK

You can go to http://developer.android.com/sdk/ndk/index.html to find the NDK installation package.

  • Download the NDK package for the development environment you use
  • Extract the package to a directory. The NDK files will reside in the directory android-ndk- under the directory.
  • To support the Intel® Atom™ architecture, NDK r6b or later is required.

The Structure of NDK Applications

The Android* NDK is based on the Java* Native Interface (JNI) programming framework.

  • Place your application's Java source code under $PROJECT/jni/ and declare one or more ‘native’ methods, which indicate that they are implemented through native code. E.g.: native String calculatePI(int decimalPosition);
  • Provide a native shared library which is named according to the standard UNIX convention. The shared library contains the implementation of these methods, e.g. libpicalc.so. It will be packaged into your application's .apk file.
  • Explicitly load the library. For example: System.loadLibrary("picalc");
    Note that the 'lib' prefix and the '.so' suffix in the shared library file name should not be included in the parameter in the loadLibrary function call. For more on this topic, see: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
  • Place your native sources under $PROJECT/jni/.
  • Write $PROJECT/jni/Android.mk to describe your sources to the NDK build system.
  • Optional, write $PROJECT/jni/Application.mk to describe your project in more details to the build system.

Building NDK Applications

You can build your native code by running "$NDK/ndk-build" script from your project directory, or any of its sub-directories.

  • In the NDK for Intel Architecture, use "APP_ABI := x86 " command line parameter. This generates the shared library under $PROJECT/libs/x86/ $NDK/ndk-build "APP_ABI := x86 "
  • Now you can follow the standard process to build the Android* apk, for example, using Eclipse* or Apache Ant*. The generated apk file can be found $PROJECT/bin. You can install the apk on Intel Architecture-based devices or Emulators to test the application.

Debugging NDK Applications

The NDK provides a command line script ndk-gdb which can be used to debug the embedded native code.

Summary

For Intel® architecture-based Android* platforms, the NDK is a very useful complement to the SDK. It enables the reusability and under some circumstance increases the performance. With these fundamental goals, the NDK provides a set of tools to build, integrate, test, and debug the native source code embedded in the application. On the other hand, the NDK increases the coding complexity. It should be applied only to achieve the goals described here.

Notices

* Other names and brands may be claimed as the property of others

Copyright © 2011 Intel Corporation. All rights reserved.

Intel and Atom are trademarks of Intel Corporation in the U.S. and/or other countries.

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined". Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm

Optimization Notice in English

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.