Starting from revision 5 of their NDK, Google added a (very usefull) script to build a standalone toolchain, i.e which works without having to deal with specific setup scripts (ndk-build and so on). Make, configure, and autoconf are now welcome !
First of all, download and uncompress the NDK :
$ mkdir Android && cd Android $ wget http://dl.google.com/android/ndk/android-ndk-r5b-linux-x86.tar.bz2 $ tar xf android-ndk-r5b-linux-x86.tar.bz2
Now, we’ll build the standalone toolchain, for example, for the Gingerbread API (level 9) :
$ ls android-ndk-r5b $ export NDK=`pwd`/android-ndk-r5b $ chmod +x $NDK/build/tools/make-standalone-toolchain.sh $ $NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=$NDK/.standalone/android-9-toolchain
That’s it ! The toolchain binaries do not depend or contain host-specific paths, in other words, they can be installed in any location, or even moved if you need to. Now, you just need to set your environment :
$ export PATH=$NDK/.standalone/android-9-toolchain/bin:$PATH $ export CC=arm-linux-androideabi-gcc
Ok, now, let’s do our first build :
$ cat helloandroid.c #includeint main(void) { printf("Hello Android !\n"); return 0; } $ $CC -o helloandroid helloandroid.c $ file helloandroid helloandroid: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
And burn it into your device :
$ adb push helloandroid /data/ 115 KB/s (3324 bytes in 0.028s) $ adb shell chmod +x /data/helloandroid $ adb shell /data/helloandroid Hello Android !
Huuurraa ! ![]()
For lazy peoples (like me), I wrote a litlle script which will automatically build the desired toolchain (if needed) and set your path accordingly :
$ ./set-toolchain.sh android-9 Forking a new shell... $PATH = /home/renaud/Android/android-ndk-r5b/.standalone/android-9-toolchain/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games $CC = arm-linux-androideabi-gcc
Enjoy ! ![]()
This entry was posted
on Wednesday, June 1st, 2011 at 7:52 am and is filed under Android.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

1 comment so far
[...] aplicaciones en código nativo para Android (es decir archivos binarios ejecutables) en este blog (www.myboyfriendisageek.com), aquí les dejo una [...]
June 19th, 2011 at 7:31 am
Leave a Comment