Book description
Discover the native side of Android and inject the power of C/C++ in your applications
In Detail
Android NDK is all about injecting high-performance and portable code into your mobile apps by exploiting the maximum speed of the device they run on.
This book will show you how to create C/C++-enabled mobile applications and integrate them with Java. The books starts with teaching you how to access native API and port libraries used in some of the most successful Android applications. Next, you will move on to create a real native application project through the complete implementation of a native API and porting existing third-party libraries. Moving forward, you will learn how to access the keyboard and input peripherals and read accelerometer or orientation sensors. Finally, you will dive into more advanced topics such as RenderScript.
What You Will Learn
- Build your first Android native project from scratch
- Communicate with Java through Java Native Interfaces
- Learn the key design intricacies of creating a native OpenGL ES 2.0 graphics application
- Initialize, play, and record sound and music with OpenSL ES
- Handle input events and sensors to create different interaction types
- Port an existing library on Android by compiling most common C++ frameworks on Android
- Interface and optimize the existing code with RenderScript
- Combine graphics, sound, input, sensors, and physics in your application
Table of contents
-
Android NDK Beginner's Guide Second Edition
- Table of Contents
- Android NDK Beginner's Guide Second Edition
- Credits
- About the Author
- About the Reviewers
- www.PacktPub.com
- Preface
-
1. Setting Up Your Environment
- Getting started with Android development
- Time for action – preparing Windows for Android development
- Time for action – installing Android SDK and NDK on Windows
- Time for action – preparing OS X for Android development
- Time for action – installing Android SDK and NDK on OS X
- Time for action – preparing Ubuntu for Android development
- Time for action – installing Android SDK and NDK on Ubuntu
- Time for action – installing Eclipse with ADT on your OS
- Time for action – creating an Android virtual device
- Time for action – setting up an Android device
- Summary
-
2. Starting a Native Android Project
- Building NDK sample applications
- Time for action – compiling and deploying San Angeles sample
- Creating your first native Android project
- Time for action – creating a native Android project
- Interfacing Java with C/C++
- Time for action – calling C code from Java
- Debugging native Android applications
- Time for action – debugging a native Android application
- Analyzing native crash dumps
- Time for action – analyzing a native crash dump
- Setting up a Gradle project to compile native code
- Time for action – creating a native Android project
- Time for action – using your own Makefiles with Gradle
- Summary
-
3. Interfacing Java and C/C++ with JNI
- Initializing a native JNI library
- Time for action – defining a simple GUI
- Time for action – initializing the native store
- Converting Java strings in native code
- Time for action – handling strings in the native store
- Passing Java primitives to native code
- Time for action – handling primitives in the native store
- Referencing Java objects from native code
- Time for action – saving references to Objects in native Store
- Managing Java arrays
- Time for action – handling Java arrays in native Store
- Raising and checking Java exceptions
- Time for action – raising & catching exceptions in native Store
- Summary
-
4. Calling Java Back from Native Code
- Calling Java back from native code
- Time for action – determining JNI method signatures
- Time for action – calling back Java from native code
- Time for action – allocating an object with JNI
- Time for action – running and synchronizing a thread
- Processing bitmaps natively
- Time for action – decoding a camera's feed
- Time for action – processing pictures with the Bitmap API
- Summary
-
5. Writing a Fully Native Application
- Creating a native Activity
- Time for action – creating a basic native Activity
- Handling Activity events
- Time for action – stepping the event loop
- Time for action – handling Activity events
- Accessing window surface natively
- Time for action – displaying raw graphics
- Measuring time natively
- Time for action – animating graphics with a timer
- Summary
-
6. Rendering Graphics with OpenGL ES
- Initializing OpenGL ES
- Time for action – initializing OpenGL ES
- Time for action – clearing and swapping buffers
- An insight into the OpenGL pipeline
- Loading textures using the Asset manager
- Time for action – reading assets with the Asset manager
- Time for action – compiling and embedding libpng module
- Time for action – loading a PNG image
- Time for action – generating an OpenGL texture
- Drawing 2D sprites
- Time for action – initializing OpenGL ES
- Rendering particle effects
- Time for action – rendering a star field
- Adapting graphics to various resolutions
- Time for action – adapting resolution with off-screen rendering
- Summary
- 7. Playing Sound with OpenSL ES
-
8. Handling Input Devices and Sensors
- Interacting with touch events
- Time for action – handling touch events
- Detecting keyboard, D-Pad, and Trackball events
- Time for action – handling keyboard, D-Pad, and trackball events natively
- Probing device sensors
- Time for action – handling accelerometer events
- Time for action – turning an Android device into a Joypad
- Summary
-
9. Porting Existing Libraries to Android
- Activating the Standard Template Library
- Time for action – activating GNU STL in DroidBlaster
- Time for action – read files with STL stream
- Time for action – using STL containers
- Porting Box2D to Android
- Time for action – compiling Box2D on Android
- Time for action – running Box2D physics engine
- Prebuilding Boost on Android
- Time for action – prebuilding Boost static library
- Time for action – compiling an executable linked to Boost
- Mastering module Makefiles
- Summary
-
10. Intensive Computing with RenderScript
- What is RenderScript ?
- Executing a predefined Intrinsic
- Time for action – creating a Java UI
- Time for action – running RenderScript Blur intrinsic
- Writing a custom Kernel
- Time for action – writing a luminance threshold filter
- Combining scripts together
- Time for action – combining Intrinsics and scripts together
- Summary
- 11. Afterword
- Index
Product information
- Title: Android NDK Beginner's Guide - Second Edition
- Author(s):
- Release date: April 2015
- Publisher(s): Packt Publishing
- ISBN: 9781783989645
You might also like
book
Pro Android C++ with the NDK
Android is one of the major players in the mobile phone market. Android is a mobile …
book
OpenGL ES 2 for Android
Android is booming like never before, with millions of devices shipping every day. It's never been …
book
Android 9 Development Cookbook - Third Edition
Build feature-rich, reliable Android Pie apps with the help of more than 100 proven industry standard …
book
Professional Android Sensor Programming
Learn to build human-interactive Android apps, starting with device sensors This book shows Android developers how …