First Step of Android NDK

To run C/C++ Native code in Android, we need to use Android NDK. Android NDK is different library from Android SDK.

There are several steps to use Android NDK


  1. Download NDK from Android NDK web site
  2. Compress under anywhere
  3. Add path of the NDK directory ex c:\android-ndk-r8e
  4. ADT Install NDK Plugin
  5. Set up Eclipse Preferences -> NDK -> NDK Location (Add NDK path)


We consider CPU to compile native codes. Android has 3 CPU architectures

  • ARM
  • x86
  • MIPS

ARM is most popular architecture of Android phone, or tablets.
x86 is PC architecture, sometimes PC like tablets use that CPU.
We should change compile settings of each architectures.

First NDK Project

Create general Android Project same as Android application.
Next, you add native support(Project -> Right click -> Android Tools -> Native Support)


Select native support. After it, library name dialog show up.


We don’t care about library name. We finally make share library (.so) in Android NDK. This is name.
But, we can change
This is default name, so eclipse will make script) to make this name library.
Actually, automatic script is useless. We need change drastically.


Click OK. We can see jni directory under our project. And there are and Projectname.cpp file.

Prepare was done.

This is build script to build shared libary.
See default script

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := AndroidCrypto3
LOCAL_SRC_FILES := AndroidCrypto3.cpp


A bit different from Linux Make File.


To build native code from

Eclipse -> Project -> Build Project
The result is shown in Eclipse console. You can see it!

NDK uses ndk-build command in Android NDK tools.


The shared library is located under libs/armeabi (ARM base) directory