This recipe depicts how to set up an Android NDK development environment in Ubuntu Linux.
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
:
ldd --version
. This will print the version of ldd
and glibc
:<glibc library location>/<glibc library>.
The following output will be displayed:
sudo apt-get install ia32-libs
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.
The following steps indicate the procedure of setting up an Android NDK development environment on Ubuntu Linux:
~/.bashrc
:export ANDROID_SDK=<path to Android SDK directory> export PATH=$PATH:$ ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
~/.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
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: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.
The following are a few more tips on setting up an NDK development environment:
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:csh
), the startup file to use is ~/.cshrc
.ksh
, the startup file to use can be obtained using the command echo $ENV
.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. $update-java-alternatives -l
$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