How to compile the Android NDK examples using command line tools

Complete information is from, here is summarized just the bare minimum (but entirely self-sufficient) to get everything compiled, if you are lazy to read the more complete document.

Necessary tools needed prior to compilation:

1. “ant” (

2. Android SDK (

3. Android NDK (

And the steps are as follows:

a. Due to the “awk” utility as provided by Android NDK is a 64-bit binary, it is necessary to first rename or delete it first (

b. Then traverse to the NDK’s samples directory, and further cd to any of the samples.

c. Then issue “../../ndk-build” to execute the ndk-build as provided by Android NDK.

d. Then issue the “android update” command (here my Android SDK is installed in the /opt directory):

/opt/android-sdk-linux/tools/android update project –path . –target android-10

The target to choose should match the Android version of the your phone:

For example, my Sony Ericsson Arc S is Android 2.3.4, so the target is “android-10” as above.

e. Next compile a debug version (you can compile a release version too, but that will require you to sign the application. (Please refer to for more info).

ant debug

f. Then after connecting the phone to the computer via USB, issue the following command to install the debug apk:

/opt/android-sdk-linux/platform-tools/adb install -r bin/xxxxxxx-debug.apk

where bin/xxxxxxx-debug.apk is the name of the apk generated in the “bin” subdirectory.

The full verbose output as follow:

+ dirname ../../ndk-build
+ PROGDIR=../..
+ cd ../..
+ pwd
+ PROGDIR=/opt/android-ndk-r7
+ [ -n /opt/android-ndk-r7/prebuilt/linux-x86/bin/make ]
+ which /opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ ABS_GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ 0 != 0 ]
+ GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ = cygwin ]
+ /opt/android-ndk-r7/prebuilt/linux-x86/bin/make -f /opt/android-ndk-r7/build/core/
Compile thumb : sanangeles <= importgl.c
Compile thumb : sanangeles <= demo.c
Compile thumb : sanangeles libs/armeabi/

+ /opt/android-sdk-linux/tools/android update project –path . –target android-10
Updated file ./proguard.cfg
+ ant debug
Buildfile: /opt/android-ndk-r7/samples/san-angeles/build.xml





[echo] Gathering info for DemoActivity…
[setup] Android SDK Tools Revision 16
[setup] Project Target: Android 2.3.3
[setup] API level: 10
[setup] ——————
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup] ——————
[setup] WARNING: Attribute minSdkVersion in AndroidManifest.xml (4) is lower than the project target API level (10)

[echo] Creating output directories if needed…


[echo] ———-
[echo] Handling aidl files…
[aidl] No AIDL files to compile.
[echo] ———-
[echo] Handling RenderScript files…
[renderscript] No RenderScript files to compile.
[echo] ———-
[echo] Handling Resources…
[aapt] No changed resources. and untouched.





[dex] No new compiled code. No need to convert bytecode to dalvik format.

[crunch] Crunching PNG Files in source dir: /opt/android-ndk-r7/samples/san-angeles/res
[crunch] To destination dir: /opt/android-ndk-r7/samples/san-angeles/bin/res
[crunch] Crunched 0 PNG files to update cache

[aapt] No changed resources or assets. DemoActivity.ap_ remains untouched

[apkbuilder] No changes. No need to create apk.

[zipalign] No changes. No need to run zip-align on the apk.
[echo] Debug Package: /opt/android-ndk-r7/samples/san-angeles/bin/DemoActivity-debug.apk

[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop

Total time: 1 second
+ /opt/android-sdk-linux/platform-tools/adb install -r bin/DemoActivity-debug.apk
453 KB/s (19858 bytes in 0.042s)
pkg: /data/local/tmp/DemoActivity-debug.apk


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: