Android NDK Beginner’s Guide


Android NDK Beginner’s Guide
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Create high performance applications with C/C++ and integrate with Java
  • Exploit advanced Android features such as graphics, sound, input and sensing
  • Port and reuse your own or third-party libraries from the prolific C/C++ ecosystem

Book Details

Language : English
Paperback : 436 pages [ 235mm x 191mm ]
Release Date : January 2012
ISBN : 1849691525
ISBN 13 : 9781849691529
Author(s) : Sylvain Ratabouil
Topics and Technologies : All Books, Mobile Application Development, Android, Mobile, Beginner's Guides

Table of Contents

Preface
Chapter 1: Setting Up your Environment
Chapter 2: Creating, Compiling, and Deploying Native Projects
Chapter 3: Interfacing Java and C/C++ with JNI
Chapter 4: Calling Java Back from Native Code
Chapter 5: Writing a Fully-native Application
Chapter 6: Rendering Graphics with OpenGL ES
Chapter 7: Playing Sound with OpenSL ES
Chapter 8: Handling Input Devices and Sensors
Chapter 9: Porting Existing Libraries to Android
Chapter 10: Towards Professional Gaming
Chapter 11: Debugging and Troubleshooting
Index
  • Chapter 1: Setting Up your Environment
    • Getting started with Android development
    • Setting up Windows
    • Time for action – preparing Windows for Android development
    • Installing Android development kits on Windows
    • Time for action – installing Android SDK and NDK on Windows
    • Setting up Mac OS X
    • Time for action – preparing Mac OS X for Android development
    • Installing Android development kits on Mac OS X
    • Time for action – installing Android SDK and NDK on Mac OS X
    • Setting up Linux
    • Time for action – preparing Ubuntu Linux for Android development
    • Installing Android development kits on Linux
    • Time for action – installing Android SDK and NDK on Ubuntu
    • Setting up the Eclipse development environment
    • Time for action – installing Eclipse
    • Emulating Android
    • Time for action – creating an Android virtual device
    • Developing with an Android device on Windows and Mac OS X
    • Time for action – setting up your Android device on Windows and Mac OS X
    • Developing with an Android device on Linux
    • Time for action – setting up your Android device on Ubuntu
    • Troubleshooting a development device
    • Summary
    • Chapter 2: Creating, Compiling, and Deploying Native Projects
      • Compiling and deploying NDK sample applications
      • Time for action – compiling and deploying the hellojni sample
      • Exploring Android SDK tools
        • Android debug bridge
        • Project configuration tool
      • Creating your first Android project using eclipse
      • Time for action – initiating a Java project
        • Introducing Dalvik
      • Interfacing Java with C/C++
      • Time for action – calling C code from Java
        • More on Makefiles
    • Compiling native code from Eclipse
    • Time for action – creating a hybrid Java/C/C++ project
    • Summary
      • Chapter 3: Interfacing Java and C/C++ with JNI
        • Working with Java primitives
        • Time for action – building a native key/value store
        • Referencing Java objects from native code
        • Time for action – saving a reference to an object in the Store
          • Local and global JNI references
        • Throwing exceptions from native code
        • Time for action – raising exceptions from the Store
          • JNI in C++
        • Handling Java arrays
        • Time for action – saving a reference to an object in the Store
          • Checking JNI exceptions
        • Summary
        • Chapter 4: Calling Java Back from Native Code
          • Synchronizing Java and native threads
          • Time for action – running a background thread
            • Attaching and detaching threads
            • More on Java and native code lifecycles
          • Calling Java back from native code
          • Time for action – invoking Java code from a native thread
            • More on callbacks
            • JNI method definitions
          • Processing bitmaps natively
          • Time for action – decoding camera feed from native code
          • Summary
          • Chapter 5: Writing a Fully-native Application
            • Creating a native activity
            • Time for action – creating a basic native activity
            • Handling activity events
            • Time for action – handling activity events
              • More on Native App Glue
                • UI thread
                • Native thread
                • Android_app structure
            • Accessing window and time natively
            • Time for action – displaying raw graphics and implementing a timer
              • More on time primitives
            • Summary
            • Chapter 6: Rendering Graphics with OpenGL ES
              • Initializing OpenGL ES
              • Time for action – initializing OpenGL ES
              • Reading PNG textures with the asset manager
              • Time for action – loading a texture in OpenGL ES
              • Drawing a sprite
              • Time for action – drawing a Ship sprite
              • Rendering a tile map with vertex buffer objects
              • Time for action – drawing a tile-based background
              • Summary
              • Chapter 7: Playing Sound with OpenSL ES
                • Initializing OpenSL ES
                • Time for action – creating OpenSL ES engine and output
                  • More on OpenSL ES philosophy
                • Playing music files
                • Time for action – playing background music
                • Playing sounds
                • Time for action – creating and playing a sound buffer queue
                  • Event callback
                • Recording sounds
                • Summary
                • Chapter 8: Handling Input Devices and Sensors
                  • Interacting with Android
                  • Time for action – handling touch events
                  • Detecting keyboard, D-Pad, and Trackball events
                  • Time for action – handling keyboard, D-Pad, and trackball, natively
                  • Probing device sensors
                  • Time for action – turning your device into a joypad
                  • Summary
                  • Chapter 9: Porting Existing Libraries to Android
                    • Developing with the Standard Template Library
                    • Time for action – embedding GNU STL in DroidBlaster
                      • Static versus shared
                      • STL performances
                    • Compiling Boost on Android
                    • Time for action – embedding Boost in DroidBlaster
                    • Porting third-party libraries to Android
                    • Time for action – compiling Box2D and Irrlicht with the NDK
                      • GCC optimization levels
                    • Mastering Makefiles
                      • Makefile variables
                      • Makefile Instructions
                    • Summary
                    • Chapter 10: Towards Professional Gaming
                      • Simulating physics with Box2D
                      • Time for action – simulating physics with Box2D
                        • More on collision detection
                        • Collision modes
                        • Collision filtering
                        • More resources about Box2D
                      • Running a 3D engine on Android
                      • Time for action – rendring 3D graphics with Irrlicht
                        • More on Irrlicht scene management
                      • Summary
                      • Chapter 11: Debugging and Troubleshooting
                        • Debugging with GDB
                        • Time for action – debugging DroidBlaster
                        • Stack trace analysis
                        • Time for action – analysing a crash dump
                          • More on crash dumps
                        • Performance analysis
                        • Time for action – running GProf
                          • How it works
                          • ARM, thumb, and NEON
                        • Summary

                        Sylvain Ratabouil

                        Sylvain Ratabouil is a confirmed IT consultant experienced with Java and C++ technologies. He worked in his earlier years in the development of control centers for the space industry at Communication & Systèmes. He then got involved in Aeronautic industry projects at Valtech Technologies, where he now takes part in the digital revolution. Sylvain earned a Masters degree from the IUP ISI curriculum at Paul Sabatier University in Toulouse and an MSC in Computer Science from Liverpool University. As a technology lover, he is passionate about mobile technologies and cannot live without his Android smart-phone.
                        Sorry, we don't have any reviews for this title yet.

                        Code Downloads

                        Download the code and support files for this book.


                        Submit Errata

                        Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                        Errata

                        - 3 submitted: last submission 15 Jun 2013

                        Errata type: Code | Page number: 203

                        ...
                        void png_read_callback(png_structp png, png_bytep data,
                        png_size_t size) {
                        ResourceReader& lReader =
                        *((ResourceReader*) png_get_io_ptr(png));
                        if (lReader.read(data, size) != STATUS_OK) {
                        lReader.close();
                        png_error(png, "Error while reading PNG file");
                        }
                        }
                        ...
                        Should be:
                        void GraphicsTexture::callback_read(png_structp pStruct,
                             png_bytep pData, png_size_t pSize) {
                             Resource* lResource = ((Resource*) png_get_io_ptr(pStruct));
                             if (lResource->read(pData, pSize) != STATUS_OK) {
                                 lResource->close();
                                 png_error(pStruct, "Error while reading PNG file");
                             }
                        }

                         

                        The code for the book has been re-uploaded.

                        Errata type: Others | Page number: 13

                        On page 260:
                        for (int32_t i = 0; i < mSoundCount; ++i) {
                        delete mSounds[i];
                        mSoundCount = 0;
                        }
                        should be
                        for (int32_t i = 0; i < mSoundCount; ++i) {
                        delete mSounds[i];
                        }
                        mSoundCount = 0;

                        Sample chapters

                        You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                        Frequently bought together

                        Android NDK Beginner’s Guide +    VMware View 5 Desktop Virtualization Solutions =
                        50% Off
                        the second eBook
                        Price for both: £27.34

                        Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                        What you will learn from this book

                        • Jump in the starting block and create your first Android native project
                        • Communicate with Java through Java Native Interfaces
                        • Display 2D and 3D graphics with OpenGL ES
                        • Play sound and music with OpenSL ES
                        • Manage Android input and sensors
                        • Debug and troubleshoot applications
                        • Port existing C/C++ code to Android
                        • Combine graphics, sound, input, sensors and physics in your application

                         

                        In Detail

                        Android NDK is all about injecting high performance into your apps. Exploit the maximum power of these mobile devices using high-performance and portable code.

                        This book will show you how to create C/C++ enabled applications and integrate them with Java. You will learn how to access native API and port libraries used in some of the most successful Android applications.

                        Using this practical step-by-step tutorial, highlighted with comments and tricks, discover how to run C/C++ code embedded in a Java application or in a standalone application. You will create a real native application starting from project creation through to full implementation of native API and the porting of existing third-party libraries. You will discover OpenGL ES and OpenSL ES, which are becoming the new standard in mobility. You will also understand how to access keyboard and input peripherals and how to read accelerometer or orientation sensors. Finally, you will dive into more advanced topics such as debugging and troubleshooting applications. By the end of the book, you should know the key elements to enable you to start exploiting the power and portability of native code.

                        Approach

                        This beginner's guide focuses on getting you through all the major learning points in a smooth, logical order. You'll also see how to avoid some common pitfalls.

                        Who this book is for

                        Are you an Android Java programmer who needs more performance? Are you a C/C++ developer who doesn’t want to bother with Java stuff and its out-of-control garbage collector? Do you want to create fast intensive multimedia applications or games? Answer yes to any of the above and this book is for you. With some general knowledge of C/C++ development, you will be able to dive head first into native Android development.

                        Code Download and Errata
                        Packt Anytime, Anywhere
                        Register Books
                        Print Upgrades
                        eBook Downloads
                        Video Support
                        Contact Us
                        Awards Voting Nominations Previous Winners
                        Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                        Resources
                        Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software