Pro Android C++ with the NDK (Paperback)

Onur Cinar



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. Getting Started with C++ on Android   
  2. Exploring the Android NDK   
  3. Communicating with Native Code using JNI    
  4. Auto-Generate JNI Code Using SWIG  
  5. Logging, Debugging, and Troubleshooting    
  6. Bionic API Primer  
  7. Native Threads 
  8. POSIX Socket API: Connection Oriented Communication 
  9. POSIX Socket API: Connetionless Communication 
  10. POSIX Socket API: Local Communication
  11. C++ Support 
  12. Native Graphics API
  13. Sound Native API
  14. Profiling and NEON Optimization


Android是移動電話市場的主要參與者之一。Android是建立在Linux操作系統之上的移動平台。Android上的原生代碼支持為應用程序開發人員提供了無限的機會,不僅限於Android框架提供的功能。《Pro Android C++ with the NDK》是今天更複雜的應用程序開發人員的高級教程和專業參考,他們現在正在將C++和其他原生代碼移植、開發或應用於Android平台,以運行更複雜的原生應用程序和更高效的應用程序。本書通過一個遊戲應用程序案例研究,探討了用於故障排除、調試、分析內存問題、單元測試、單元測試代碼覆蓋率、性能測量的工具,以及將Android NDK工具鏈集成到現有的Autoconf、Makefile、CMake或JAM基於構建系統中。《Pro Android C++ with the NDK》還涵蓋了以下內容:
- Android平台,以及快速掌握Android NDK,並探索在本地空間提供的API。
- Java Native Interface(JNI)概述,以及通過簡化封裝和接口生成器(SWIG)自動生成JNI代碼。
- Bionic API簡介,本地網絡,本地多線程和C++標準模板庫(STL)支持。
- 使用JNI圖形和聲音,OpenGL ES和OpenSL ES進行本地圖形和聲音。
- 使用日誌記錄、GNU調試器(GDB)、Eclipse調試器、Valgrind、strace和其他工具進行調試和故障排除本地應用程序。
- 使用GProf進行本地代碼性能瓶頸的分析,以及從高級角度進行NEON/SIMD優化的技巧和建議。

- 什麼是Android平台,以及如何快速掌握Android NDK。
- 使用Eclipse IDE來簡化開發本地應用程序。
- 如何使用Java Native Interface(JNI)將本地代碼連接到Java世界。
- 使用簡化封裝和接口生成器(SWIG)自動生成JNI代碼。
- Bionic API簡介。
- 通過POSIX套接字進行網絡通信。
- 使用POSIX線程和Java線程開發多線程應用程序。
- 通過日誌記錄、GNU調試器(GDB)和Eclipse調試器進行調試。
- 通過Valgrind分析內存問題。
- C++支持和標準模板庫(STL)。
- 通過JNI圖形和OpenGL ES進行本地圖形。
- 通過OpenSL ES進行本地聲音。
- 使用GProf進行本地代碼性能瓶頸的分析。
- 使用SIMD/NEON優化代碼。

這本書適合軟件專業人士,他們有興趣利用Android NDK將現有的本地代碼應用程序(如C++)移植到Android平台,以及有興趣通過使用本地代碼來提高應用程序整體性能的現有Android開發人員。

1. 開始使用Android上的C++
2. 探索Android NDK
3. 使用JNI與本地代碼通信
4. 使用SWIG自動生成JNI代碼
5. 日誌記錄、調試和故障排除
6. Bionic API入門
7. 本地線程
8. POSIX套接字API:面向連接的通信
9. POSIX套接字API:無連接通信
10. POSIX套接字API:本地通信
11. C++支持
12. 本地圖形API
13. 本地音頻API
14. 性能分析和NEON優化