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
- Download NDK from Android NDK web site
- Compress under anywhere
- Add path of the NDK directory ex c:\android-ndk-r8e
- ADT Install NDK Plugin http://dl.google.com/eclipse/plugin/4.2
- Set up Eclipse Preferences -> NDK -> NDK Location (Add NDK path)
We consider CPU to compile native codes. Android has 3 CPU architectures
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 Android.mk(build 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 Android.mk 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 include $(BUILD_SHARED_LIBRARY)
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