You are previewing Mastering Android NDK.
O'Reilly logo
Mastering Android NDK

Book Description

Master the skills you need to develop portable, highly-functional Android applications using NDK

About This Book

  • Develop portable games using Android NDK and debug them on your desktop

  • Familiarise yourself with different popular C++ libraries on Android and use them in your games

  • Write multi-threaded code with graphics, sound, networking, and resource storage

  • Who This Book Is For

    If you want to leverage your C++ skills in mobile development and increase the performance of your Android applications, then this is the book for you. Knowledge of C or C++ is assumed, including pointer manipulation, multi-threading, object-oriented programming concepts, and the basics of C++11. It would be an added advantage if you know how to develop applications without any IDE.

    What You Will Learn

  • Explore different popular C++ libraries and import some of them to Android

  • Write portable, multithreaded native code

  • Create applications that play audio with OpenAL

  • Implement gesture recognition in your games and applications

  • Debug mobile applications on your desktop

  • Extract resources from APK archives

  • Render text with FreeType and also use OpenGL ES

  • In Detail

    Android NDK is used for multimedia applications that require direct access to system resources. NDK is also the key for portability, which in turn allows a reasonably comfortable development and debugging process using familiar tools such as GCC and Clang toolchains.

    This is a hands-on guide to extending your game development skills with Android NDK. The book takes you through many clear, step-by-step example applications to help you further explore the features of Android NDK and some popular C++ libraries and boost your productivity by debugging the development process.

    Through the course of this book, you will learn how to write portable multi-threaded native code, use HTTP networking in C++, play audio files, use OpenGL ES 3, and render high-quality text. Each chapter aims to take you one step closer to building your application. By the end of this book, you will be able to create an engaging, complete gaming application.

    Style and approach

    This book adopts a step-by-step approach and each chapter is based on the material from the previous ones. The book focuses on putting to your knowledge of C++ use while you develop Android applications of your own.

    Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Mastering Android NDK
      1. Table of Contents
      2. Mastering Android NDK
      3. Credits
      4. About the Authors
      5. About the Reviewers
        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. Using Command-line Tools
        1. Using Android command-line tools on Windows
        2. Using Android command-line tools on OS X
        3. Using Android command-line tools on Linux
        4. Creating an Ant-based application template manually
        5. Creating a Gradle-based application template manually
        6. Embedding native code
        7. Building and signing release Android applications
        8. Organizing the cross-platform code
        9. Using TeamCity continuous integration server with Android applications
        10. Summary
      9. 2. Native Libraries
        1. Dealing with precompiled static libraries
        2. Dynamic linking on Windows platform
        3. Curl
        4. OpenSSL
        5. FreeImage
        6. Loading and saving images
        7. FreeType
        8. Theora
        9. OpenAL
        10. Linking the libraries to your application
        11. Summary
      10. 3. Networking
        1. Intrusive smart pointers
        2. Portable multithreading primitives
        3. Task queues
        4. Message pumps and asynchronous callbacks
        5. Asynchronous networking with libcurl
        6. Android licensing in native applications
        7. Flurry analytics
        8. Summary
      11. 4. Organizing a Virtual Filesystem
        1. Mount points
        2. Mount points and streams
        3. Accessing files on the host filesystems
        4. In-memory files
        5. Aliasing
        6. Writing files
        7. Accessing the archive files
        8. Accessing application assets
        9. Summary
      12. 5. Cross-platform Audio Streaming
        1. Initialization and playback
        2. Streaming sounds
        3. Stringed musical instrument model
        4. Decoding compressed audio
          1. Decoding tracker music using the ModPlug library
          2. Decoding MP3 files
          3. Decoding OGG files
        5. Summary
      13. 6. OpenGL ES 3.1 and Cross-platform Rendering
        1. Linear algebra and transformations
        2. Graphics initialization using SDL2
        3. OpenGL API binding
        4. Cross-platform OpenGL abstractions
        5. Feeding the geometry data to OpenGL
        6. Shader programs
        7. Textures
        8. Summary
      14. 7. Cross-platform UI and Input System
        1. Rendering
        2. Text rendering
          1. Calculating glyph positions and string size in pixels
          2. Decoding UTF-8
          3. Glyphs rendering
          4. Font initialization and caching
          5. Integrating the text renderer into the canvas
        3. Organizing the UI system
          1. The base UI view
          2. Events
          3. Implementing UI classes
          4. Using views in application
        4. Summary
      15. 8. Writing a Rendering Engine
        1. The scene graph
        2. Lighting and shading
        3. Lights and light nodes
        4. Material system
        5. Demo application and a rendering technique
          1. Scene construction
          2. User interaction with 3D scenes
        6. Summary
      16. 9. Implementing Game Logic
        1. Boids
        2. Implementation of the flocking algorithms
        3. Digression: helper routines
        4. Collective behaviors
        5. Rendering the swarm
        6. Boids demonstration
        7. The page-based user interface
        8. Summary
      17. 10. Writing Asteroids Game
        1. Creating an on-screen joystick
        2. Implementing the particle system
          1. Using particle systems in the game
          2. Using particle systems inside a scene graph
        3. Asteroids game
        4. Summary
      18. Index