Book Image

Android NDK Game Development Cookbook

Book Image

Android NDK Game Development Cookbook

Overview of this book

Android NDK is used for multimedia applications which require direct access to a system's resources. Android NDK is also the key for portability, which in turn provides a reasonably comfortable development and debugging process using familiar tools such as GCC and Clang toolchains. If your wish to build Android games using this amazing framework, then this book is a must-have.This book provides you with a number of clear step-by-step recipes which will help you to start developing mobile games with Android NDK and boost your productivity debugging them on your computer. This book will also provide you with new ways of working as well as some useful tips and tricks that will demonstrably increase your development speed and efficiency.This book will take you through a number of easy-to-follow recipes that will help you to take advantage of the Android NDK as well as some popular C++ libraries. It presents Android application development in C++ and shows you how to create a complete gaming application. You will learn how to write portable multithreaded C++ code, use HTTP networking, play audio files, use OpenGL ES, to render high-quality text, and how to recognize user gestures on multi-touch devices. If you want to leverage your C++ skills in mobile development and add performance to your Android applications, then this is the book for you.
Table of Contents (16 chapters)
Android NDK Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Installing Android development tools on Linux


Installation of the basic tools on Linux is as easy as it was with their Windows counterpart. In this recipe, we will see how to install the basic Android development tools on *nix systems.

Getting ready

We assume you already have an Ubuntu/Debian system with the apt package manager. Refer to http://wiki.debian.org/Apt for details.

How to do it...

Carry out the following steps to install the required basic tools:

  1. Make sure you are using the latest version of the packages for your OS by running the following command:

    >sudo apt-get update
    
  2. Install OpenJDK 6+:

    >sudo apt-get install openjdk-6-jdk
    
  3. Install the Apache Ant build automation tool:

    >sudo apt-get install ant
    
  4. Download the official Android SDK from http://developer.android.com. There is a bigger package next to it, with the ADT plugin for the Eclipse IDE. However, since we do all of our development from the command line, we won't need it. Run the following command:

    >wget http://dl.google.com/android/android-sdk_r22.2.1-linux.tgz
    
  5. Unpack the downloaded .tgz file (the actual version might vary, 22.2.1 is the latest version as of October 2013):

    >tar -xvf android-sdk_r22.2.1-linux.tgz
    
  6. Use ~/<sdk>/tools/android to install the latest Platform Tools and all of the SDKs—just like in the Windows case.

    Failure to do so will result in an error while trying to use the Ant tool when building any application for the Android.

  7. Get the official Android NDK from http://developer.android.com:

    >wget http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2
    
  8. Unpack the downloaded NDK .tgz file:

    >tar -xvf android-ndk-r9b-linux-x86_64.tar.bz2
    
  9. Set the NDK_ROOT environment variable to your Android NDK directory (for example, ~/android-ndk-r9b in our case):

    >NDK_ROOT=/path/to/ndk
    

    It is useful to put this line and the JAVA_HOME definition to /etc/profile or /etc/environment, if these settings are applicable to all the users of the system.

  10. In case you are running a 64-bit system, you must ensure that you have the 32-bit Java runtime installed also.

  11. Run the following command to install the libraries. Failure to do so may lead to errors with adb and aapt tools:

    >sudo apt-get install ia32-libs
    

There's more...

There is a nice one-liner script that helps you automatically detect the OpenJDK home directory. It essentially resolves the link /usr/bin/javac to the full path and returns the directory part of the path.

  JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:bin/javac::")