Install NDK on MAC

1. download NDK from here.

2. unzip and move to Applications\android-ndk-r6b

3, open export Path setting,  open the USR\(Your name)\.bash_profile

4. update .bash_profile

export ANDROID_NDK=/Applications/android-ndk-r6b
export PATH=$PATH:$ANDROID_NDK:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin

export ANDROID_SDK=/Applications/android-sdk-mac_86-2.2

5. Build Hello-Jni
open Terminal AP and go to "samples/hello-jni"/ folder in NDK,
then type the command "ndk-build" to start compilation. 

6. please make sure your has install Android SDk

if not, see here PowenKo, Android Tutorial 001, Install Android SDK on MAC

6. update .bash_profile for Android SDK

don’t forget update .bash_profile

export ANDROID_SDK=/Applications/android-sdk-mac_86-2.2

6. Run Hello-Jni

We package the .apk file now. “Ant” is required by making apk file, and it’s built-in the mac os x, so we can skip this step.

now use “cd ../” command and go back to the parent folder of hello-jni, then use “android update project –path hello-jni” to update the hello-jni project,

just generate a build.xml file for the finally apk package. After the update, you need to enter the root path of project, use “cd hello-jni”, and then is the key step, build apk file. use “ant debug”. If you see the screenshot below, you’re lucky.

Now you can find an .APK file in “samples/hello-jni/bin”. It’s time to download and debug it on mobile device or simulator.
How I  copy APK to Android:
adb shell #su #mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
open a second terminal and use:
adb push myApp.apk /system/app/
in first terminal:

4. Debug Hello-Jni

Since Android NDK r4, we can use GDB to step-debugging JNI codes. (Yes, gdb command line only, no IDE, WTF… — Walzer). About how to use GDB, there’re many articles on the internet, we won’t discuss this here.

Enter “samples/hello-jni” folder, then run “ndk-gdb” command. Wait for your mobile device or simulator to run hello-jni. Meanwhile the terminal enters the gdb interface, as the image below. Don’t forget to set “debug” to “true” in the xml before you can debug the project.


By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is

Leave a Reply