Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android NDK Beginner`s Guide - Second Edition

You're reading from   Android NDK Beginner`s Guide - Second Edition Discover the native side of Android and inject the power of C/C++ in your applications

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781783989645
Length 494 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sylvain Ratabouil Sylvain Ratabouil
Author Profile Icon Sylvain Ratabouil
Sylvain Ratabouil
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Setting Up Your Environment FREE CHAPTER 2. Starting a Native Android Project 3. Interfacing Java and C/C++ with JNI 4. Calling Java Back from Native Code 5. Writing a Fully Native Application 6. Rendering Graphics with OpenGL ES 7. Playing Sound with OpenSL ES 8. Handling Input Devices and Sensors 9. Porting Existing Libraries to Android 10. Intensive Computing with RenderScript 11. Afterword Index

Time for action – preparing OS X for Android development

To develop with the Android NDK on OS X, we need to set up a few prerequisites: a JDK, Developer Tools, and Ant.

  1. A JDK is preinstalled on OS X 10.6 Snow Leopard and below. On these systems, Apple's JDK is in version 6. Since this version is deprecated, it is advised to install an up-to-date JDK 7 (or JDK 8, although it is not officially supported at the time this book is written).

    On the other hand, OS X 10.7 Lion and above does not have a default JDK installed. Installing the JDK 7 is thus mandatory.

    To do so, download Oracle JDK 7 from the Oracle website at http://www.oracle.com/technetwork/java/javase/downloads/index.html. Launch the DMG and follow the installation wizard until the end.

    Time for action – preparing OS X for Android development

    Check the Java version to ensure that the JDK is properly installed.

    java -version
    
    Time for action – preparing OS X for Android development

    Tip

    To know if a JDK 6 is installed, check Java Preferences.app located by going to Applications | Utilities on your Mac. If you have JDK 7, check whether you have the Java icon under System Preferences.

  2. All Developer Tools are included in the XCode installation package (Version 5, at the time this book is written). XCode is provided on the AppStore for free. Starting from OS X 10.9, the Developer Tools package can be installed separately from a terminal prompt with the following command:
    xcode-select --install
    
    Time for action – preparing OS X for Android development

    Then, from the popup window that appears, select Install.

  3. To build native code with the Android NDK, whether XCode or the single Developer Tools package is installed, we need Make. Open a terminal prompt and check the Make version to ensure that it correctly works:
    make –version
    
    Time for action – preparing OS X for Android development
  4. On OS X 10.9 and later, Ant must be installed manually. Download Ant from its website at http://ant.apache.org/bindownload.cgi and unzip its binary package in the directory of your choice (for example, /Developer/Ant).

    Then, create or edit the file ~/.profile and make Ant available on the system path by appending the following:

    export ANT_HOME="/Developer/Ant"
    export PATH=${ANT_HOME}/bin:${PATH}

    Log out from your current session and log in again (or restart your computer) and check whether Ant is correctly installed by checking its version from the command line:

    ant –version
    
    Time for action – preparing OS X for Android development

What just happened?

Our OS X system is now set up with the necessary packages to host Android development tools:

  • A JDK 7, which contains the runtime and tools necessary to build Java applications on Android and to run the Eclipse IDE as well as Ant.
  • Developer Tools package, which packages various command-line utilities. It includes Make, which is required by the Android NDK compilation system to build native code.
  • Ant, which is a Java-based build automation utility. Although not a requirement, it allows building Android applications from the command line, as we will see in Chapter 2, Starting a Native Android Project. It is also a good solution to set up a continuous integration chain.

The next step consists of setting up the Android Development Kit.

Installing Android development kits on OS X

Android requires specific development kits to develop applications: the Android SDK and NDK. Hopefully, Google has thought about the developer community and provides all the necessary tools for free.

In the following part, we are going to install these kits to start developing native Android applications on Mac OS X Yosemite.

You have been reading a chapter from
Android NDK Beginner`s Guide - Second Edition
Published in: Apr 2015
Publisher: Packt
ISBN-13: 9781783989645
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image