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 Native Development Kit Cookbook

You're reading from   Android Native Development Kit Cookbook Create Android apps using Native C/C++ with the expert guidance contained in this cookbook. From basic routines to advanced multimedia development, it helps you harness the full power of Android NDK.

Arrow left icon
Product type Paperback
Published in Mar 2013
Publisher Packt
ISBN-13 9781849691505
Length 346 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Liu Feipeng Liu Feipeng
Author Profile Icon Liu Feipeng
Liu Feipeng
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Android Native Development Kit Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Hello NDK 2. Java Native Interface FREE CHAPTER 3. Build and Debug NDK Applications 4. Android NDK OpenGL ES API 5. Android Native Application API 6. Android NDK Multithreading 7. Other Android NDK API 8. Porting and Using the Existing Libraries with Android NDK 9. Porting an Existing Application to Android with NDK Index

Setting up an Android NDK development environment in Ubuntu Linux


This recipe depicts how to set up an Android NDK development environment in Ubuntu Linux.

Getting ready

Check your Ubuntu version and make sure it is version 8.04 or later.

GNU C Library (glibc) 2.7 or above is required. It is usually installed with Linux by default. Two simple methods can check the version of glibc:

  1. Start a terminal, and enter ldd --version. This will print the version of ldd and glibc:

  2. We can execute the library as an application. Start a terminal, locate the library location, and then enter the following command:

    <glibc library location>/<glibc library>. 
    

    The following output will be displayed:

  3. We need to enable 32-bit application execution if we are using a 64-bit machine. Start a terminal, and enter the following command:

    sudo apt-get install ia32-libs
    
  4. Install JDK 6 or above. At a terminal, enter the command sudo apt-get install openjdk-6-jdk, or alternatively we can enter sudo apt-get install sun-java6-jdk. After installation, we need to add the JDK path to the PATH environment variable by adding the following lines to ~/.bashrc:

    export JDK_PATH=/usr/local/jdk1.7.0/bin
    export PATH=$PATH:$JDK_PATH

We will use Eclipse as our IDE. Please refer to the Setting up an Android NDK development environment in Windows recipe for instructions.

How to do it…

The following steps indicate the procedure of setting up an Android NDK development environment on Ubuntu Linux:

  1. Follow steps 1 to 6 of the Setting up an Android NDK development environment in Windows recipe to install the ADT plugin for Eclipse.

  2. Download Android SDK from http://developer.android.com/sdk/index.html, then extract the downloaded package.

  3. Append the following lines to ~/.bashrc:

    export ANDROID_SDK=<path to Android SDK directory>
    export PATH=$PATH:$ ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
  4. Follow steps 9 and 10 of the Setting up an Android NDK development environment in Windows recipe to configure the SDK path at Eclipse, and download additional packages.

  5. Download the latest version of Android NDK from http://developer.android.com/tools/sdk/ndk/index.html, then extract the downloaded file.

  6. Change the lines that you appended to ~/.bashrc in step 3:

    export ANDROID_SDK=<path to Android SDK directory>
    export ANDROID_NDK=<path to Android NDK directory> 
    export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK
  7. Start a new terminal, then go to the samples/hello-jni directory in NDK. Type the command ndk-build. If the build is successful, it proves that the NDK environment is set up correctly:

How it works…

We first set up Android SDK and then Android NDK. Ensure that the path is set properly, so that the tools can be accessed without referring to the SDK and NDK directories.

The .bashrc file is a startup file read by the bash shell when you start a new terminal. The export commands appended the Android SDK and NDK directory locations to the environment variable PATH. Therefore, every time a new bash shell starts, PATH is set properly for SDK and NDK tools.

There's more…

The following are a few more tips on setting up an NDK development environment:

  • Configure Path at Startup File: We append to the SDK and NDK paths to the PATH environment variable at ~/.bashrc file. This assumes that our Linux system uses the bash shell. However, if your system uses another shell, the startup file used may be different. The startup files used by some commonly used shells are listed as follows:

    • For C shell (csh), the startup file to use is ~/.cshrc.

    • For ksh, the startup file to use can be obtained using the command echo $ENV.

    • For sh, the startup file to use is ~/.profile. The user needs to log out of the current session and log in again for it to take effect.

  • Switch JDK: In Android development, we can either use Oracle Java JDK or OpenJDK. In case we run into issues with any one of the JDKs, we can switch to another Java JDK, if we have installed both of them.

    • To check which JDK the system is currently using, use the following command:

      	$update-java-alternatives -l
      
    • To switch between two JDKs, use the following command:

      	$sudo update-java-alternatives -s <java name>
      

    The following is an example for switching to Oracle JDK 1.6.0:

    $sudo update-java-alternatives -s java-1.6.0-sun 
    
lock icon The rest of the chapter is locked
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