You are previewing Pro Android C++ with the NDK.
O'Reilly logo
Pro Android C++ with the NDK

Book Description

Android is one of the major players in the mobile phone market. Android is a mobile platform that is built on the top of Linux operating system. The native-code support on Android offers endless opportunities to application developers, not limited the functionality that is provided by Android framework. Pro Android C++ with the NDK is an advanced tutorial and professional reference for today's more sophisticated app developers now porting, developing or employing C++ and other native code to integrate into the Android platform to run sophisticated native apps and better performing apps in general. Using a game app case study, this book explores tools for troubleshooting, debugging, analyzing memory issues, unit testing, unit test code coverage, performance measurement, on native applications, as well as integrating the Android NDK toolchain into existing Autoconf, Makefile, CMake, or JAM based build systems. Pro Android C++ with the NDK also covers the following:

  • The Android platform, and getting up to speed with the Android NDK, and exploring the APIs that are provided in native space.

  • An overview of Java Native Interface (JNI), and auto-generating JNI code through Simplified Wrapper and Interface Generator (SWIG).

  • An introduction to Bionic API, native networking. native multithreading, and the C++ Standard Template Library (STL) support.

  • Native graphics and sound using JNI Graphics, OpenGL ES, and OpenSL ES.

  • Debugging and troubleshooting native applications using Logging, GNU Debugger (GDB), Eclipse Debugger, Valgrind, strace, and other tools.

  • Profiling native code using GProf to identify performance bottlenecks, and NEON/SIMD optimization from an advanced perspective, with tips and recommendations.

What you'll learn

  • What is the Android platform, and getting up to speed with the Android NDK.

  • Using the Eclipse IDE to streamline developing native applications

  • How to use Java Native Interface (JNI) to connect native code to Java world.

  • Auto-generate JNI code using Simplified Wrapper and Interface Generator (SWIG).

  • Introduction to Bionic API

  • Networking through POSIX sockets

  • Developing multithreaded applications using POSIX Threads, and Java Threads.

  • Debug through Logging, GNU Debugger (GDB), and Eclipse Debugger

  • Analyze memory issues through Valgrind

  • C++ Support and Standard Template Library STL

  • Native Graphics through JNI Graphics and OpenGL ES

  • Native Sound through OpenSL ES

  • Profiling the native code using GProf to identify performance bottlenecks

  • Optimize code using SIMD/NEON

Who this book is for

This book is for software professionals who are interested in leveraging the Android NDK to port their existing native-code app, such as C++, to the Android platform, as well as existing Android developers who are interested in improving their apps overall performance by utilizing native-code.

Table of Contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Author
  6. About the Technical Reviewer
  7. Preface
  8. Chapter 1: Getting Started with C++ on Android
    1. Microsoft Windows
    2. Apple Mac OS X
    3. Ubuntu Linux
    4. Downloading and Installing the ADT
    5. Summary
  9. Chapter 2: Exploring the Android NDK
    1. Components Provided with the Android NDK
    2. Structure of the Android NDK
    3. Starting with an Example
    4. Build System
    5. Using the NDK-Build Script
    6. Troubleshooting Build System Problems
    7. Summary
  10. Chapter 3: Communicating with Native Code using JNI
    1. What is JNI?
    2. Starting with an Example
    3. Data Types
    4. Operations on Reference Types
    5. Exception Handling
    6. Local and Global References
    7. Threading
    8. Summary
  11. Chapter 4: Auto-Generate JNI Code Using SWIG
    1. What is SWIG?
    2. Installation
    3. Experimenting with SWIG Through an Example
    4. Wrapping C Code
    5. Wrapping C++ Code
    6. Exception Handling
    7. Memory Management
    8. Calling Java from Native Code
    9. Summary
  12. Chapter 5: Logging, Debugging, and Troubleshooting
    1. Logging
    2. Debugging
    3. Troubleshooting
    4. Summary
  13. Chapter 6: Bionic API Primer
    1. Reviewing Standard Libraries
    2. Yet Another C Library?
    3. Memory Management
    4. Standard File I/O
    5. Interacting with Processes
    6. System Configuration
    7. Users and Groups
    8. Inter-Process Communication
    9. Summary
  14. Chapter 7: Native Threads
    1. Creating the Threads Example Project
    2. Java Threads
    3. POSIX Threads
    4. Return Result from POSIX Threads
    5. Synchronizing POSIX Threads
    6. Priority and Scheduling Strategy for POSIX Threads
    7. Summary
  15. Chapter 8: POSIX Socket API: Connection-Oriented Communication
    1. Echo Socket Example Application
    2. Connection-Oriented Communication through TCP Sockets
    3. Summary
  16. Chapter 9: POSIX Socket API: Connectionless Communication
    1. Adding Native UDP Server Method to Echo Server Activity
    2. Implementing the Native UDP Server
    3. Adding Native UDP Client Method to Echo Client Activity
    4. Implementing the Native UDP Client
    5. Running the UDP Sockets Example
    6. Summary
  17. Chapter 10: POSIX Socket API: Local Communication
    1. Echo Local Activity Layout
    2. Echo Local Activity
    3. Implementing the Native Local Socket Server
    4. Adding Local Echo Activity to Manifest
    5. Running the Local Sockets Example
    6. Asynchronous I/O
    7. Summary
  18. Chapter 11: C++ Support
    1. Supported C++ Runtimes
    2. Specifying the C++ Runtime
    3. Static vs. Shared Runtimes
    4. C++ Exception Support
    5. C++ RTTI Support
    6. C++ Standard Library Primer
    7. Thread Safety of C++ Runtime
    8. C++ Runtime Debug Mode
    9. Summary
  19. Chapter 12: Native Graphics API
    1. Availability of Native Graphics API
    2. Creating an AVI Video Player
    3. Rendering using JNI Graphics API
    4. Rendering Using OpenGL ES
    5. Rendering Using Native Window API
    6. Summary
  20. Chapter 13: Native Sound API
    1. Using the OpenSL ES API
    2. Creating the WAVE Audio Player
    3. Running the WAVE Audio Player
    4. Summary
  21. Chapter 14: Profiling and NEON Optimization
    1. GNU Profiler for Measuring Performance
    2. Optimization using ARM NEON Intrinsics
    3. Automatic Vectorization
    4. Summary
  22. Index