Android Native Development Kit Cookbook

Book description

Create Android apps using Native C/C++ with the expert guidance contained in this cookbook. From basic routines to advanced multimedia development, it helps you harness the full power of Android NDK.

  • Build, debug, and profile Android NDK apps
  • Implement part of Android apps in native C/C++ code
  • Optimize code performance in assembly with Android NDK

In Detail

Building Android applications would usually mean that you spend all of your time working in Java. There are however times when this is not the most efficient or best method for the application being built. This is where Android NDK comes in. Android NDK allows the developer to write in Native C/C++, giving you the power to reuse code and libraries and also, in most cases, increase the speed and efficiency of your application.

The "Android Native Development Kit Cookbook" will help you understand the development, building, and debugging of your native Android applications. We will discover and learn JNI programming and essential NDK APIs such as OpenGL ES, and the native application API. We will then explore the process of porting existing libraries and software to NDK. By the end of this book you will be able to build your own apps in NDK apps.

"Android Native Development Kit Cookbook" begins with basic recipes that will help you in the building and debugging of native apps, and JNI programming. The recipes cover various topics of application development with Android NDK such as OpenGL programming and Multimedia programming. We will begin with a simple recipe, Hello NDK, before moving on to cover advanced topics with recipes on OpenGL ES that focus on 2D and 3D graphics, as well as recipes that discuss working with NDK and external APIs. If you are looking for ways to make your application available in Android and take measures to boost your application’s performance, then this Cookbook is for you.

Table of contents

  1. Android Native Development Kit Cookbook
    1. Table of Contents
    2. Android Native Development Kit Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Hello NDK
      1. Introduction
      2. Setting up an Android NDK development environment in Windows
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Setting up an Android NDK development environment in Ubuntu Linux
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Setting up an Android NDK development environment in Mac OS
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Updating Android NDK
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Writing a Hello NDK program
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    9. 2. Java Native Interface
      1. Introduction
      2. Loading native libraries and registering native methods
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Passing parameters and receiving returns in primitive types
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Manipulating strings in JNI
        1. Getting ready
        2. How to do it
        3. How it works…
        4. There's more…
      5. Managing references in JNI
        1. How to do it…
        2. How it works…
        3. There's more…
      6. Manipulating classes in JNI
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Manipulating objects in JNI
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Manipulating arrays in JNI
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Accessing Java static and instance fields in the native code
        1. Getting ready
        2. How to do it…
        3. How it works…
      10. Calling static and instance methods from the native code
        1. Getting ready
        2. How to do it…
        3. How it works…
      11. Caching jfieldID, jmethodID, and referencing data to improve performance
        1. Getting ready
        2. How to do it…
        3. How it works…
      12. Checking errors and handling exceptions in JNI
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      13. Integrating assembly code in JNI
        1. Getting ready
        2. How to do it…
        3. How it works…
    10. 3. Build and Debug NDK Applications
      1. Introduction
      2. Building an Android NDK application at the command line
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
          1. Taking screenshots from the command line
      3. Building an Android NDK application in Eclipse
        1. Getting ready
        2. How to do it…
        3. How it works...
      4. Building an Android NDK application for different ABIs
        1. Getting ready
        2. How to do it...
        3. How it works…
      5. Building Android NDK applications for different CPU features
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. More about CPU feature detection
          2. Different approaches of building for different cpu features
      6. Debugging an Android NDK application with logging messages
        1. How to do it…
        2. How it works...
      7. Debugging an Android NDK application with CheckJNI
        1. How to do it...
        2. How it works...
      8. Debugging an Android NDK application with NDK GDB
        1. Getting ready
        2. How to do it...
        3. How it works...
      9. Debugging an Android NDK application with CGDB
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Debugging an Android NDK application in Eclipse
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    11. 4. Android NDK OpenGL ES API
      1. Introduction
      2. Drawing 2D Graphics and applying transforms with the OpenGL ES 1.x API
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. OpenGL ES rendering display through GLSurfaceView
          2. Drawing objects at OpenGL ES
          3. Colors at OpenGL ES
          4. OpenGL ES transformation
      3. Drawing 3D graphics and lighting up the scene with the OpenGL ES 1.x API
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Mapping texture to 3D objects with the OpenGL ES 1.x API
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Drawing 3D graphics with the OpenGL ES 2.0 API
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. OpenGL Shading Language (GLSL)
          2. How to use shader:
        4. There's more...
      6. Displaying graphics with EGL
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Window management
        4. There's more...
    12. 5. Android Native Application API
      1. Introduction
      2. Creating a native activity with the native_activity.h interface
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Creating a native activity with the Android native app glue
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Managing native windows at Android NDK
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Detecting and handling input events at Android NDK
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Accessing sensors at Android NDK
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Managing assets at Android NDK
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    13. 6. Android NDK Multithreading
      1. Introduction
      2. Creating and terminating native threads at Android NDK
        1. Getting ready…
        2. How to do it...
        3. How it works...
          1. Build with pthreads
          2. Thread creation
          3. Thread termination
      3. Synchronizing native threads with mutex at Android NDK
        1. How to do it...
        2. How it works...
          1. Initialize and destroy mutex
          2. Using the mutex
        3. There's more...
      4. Synchronizing native threads with conditional variables at Android NDK
        1. How to do it...
        2. How it works...
          1. Initialize and destroy conditional variables
          2. Using the conditional variable:
        3. There's more...
          1. Conditional variable attributes functions
          2. Timed conditional variable functions
      5. Synchronizing native threads with reader/writer locks at Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Initialize and destroy a reader/writer lock
          2. Using a reader/writer lock
        4. There's more...
          1. Timed read/write lock and trylock
          2. Reader/writer lock attribute functions
      6. Synchronizing native threads with semaphore at Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Initialize and destroy a semaphore
          2. Using a semaphore
      7. Scheduling native threads at Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Scheduling contention scope
          2. Scheduling policy and thread priority
          3. Scheduling using nice value/level
      8. Managing data for native threads at Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Creation and deletion of thread-specific data key
          2. Set and get thread-specific data
    14. 7. Other Android NDK API
      1. Introduction
      2. Programming with the jnigraphics library in Android NDK
        1. Getting ready…
        2. How to do it...
        3. How it works...
        4. There's more…
      3. Programming with the dynamic linker library in Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
      4. Programming with the zlib compression library in Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Programming audio with the OpenSL ES audio library in Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Object creation
          2. Changing states of objects
          3. Use and build with OpenSL ES Audio library
          4. OpenSL ES audio recording
          5. OpenSL ES audio playback
        4. There's more...
      6. Programming with the OpenMAX AL multimedia library in Android NDK
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. Use and build with the OpenMAX AL multimedia library:
          2. OpenMAX AL video playback
        4. There's more....
    15. 8. Porting and Using the Existing Libraries with Android NDK
      1. Introduction
      2. Porting a library as a shared library module with the Android NDK build system
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Porting a library as a static library module with the Android NDK build system
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Porting a library with its existing build system using the Android NDK toolchain
        1. How to do it...
        2. How it works...
        3. There's more...
      5. Using a library as a prebuilt library
        1. How to do it...
        2. How it works...
      6. Using a library in multiple projects with import-module
        1. How to do it...
        2. How it works...
      7. Porting a library that requires RTTI, exception, and STL support
        1. How to do it...
        2. How it works...
    16. 9. Porting an Existing Application to Android with NDK
      1. Introduction
      2. Porting a command-line executable to Android with an NDK build system
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Understanding the Android.mk files
      3. Porting a command-line executable to Android with an NDK standalone compiler
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Porting libpng
          2. Porting libseamcarv
          3. Porting fusch
      4. Adding GUI to a ported Android app
        1. How to do it...
        2. How it works...
      5. Using background threads at porting
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Sending messages from the native code
    17. Index

Product information

  • Title: Android Native Development Kit Cookbook
  • Author(s): Feipeng Liu
  • Release date: March 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781849691505