Nov 26

As soon as Android was released people got to work delving into the native side of things and now Macrobug has posted about how you can use Scratchpad to build ARM binaries for Android:

Benno explains how to build simple native programs for Android. But any significant pre-existing Linux software package uses a complex array of libraries and a correspondingly complicated build process, typically based around GNU Autoconf. That build process usually involves a “configure” script whose purpose is to run tiny programs to experiment with the system, to find out its capabilities and set up the code appropriately.

Terrific, except it doesn’t work if, say, you’re building on an Intel x86 box, but trying to build for Android, which is based around Linux and an entirely different CPU. Fortunately, the Scratchbox project exists to solve this problem. It provides you with a special Linux universe, which uses the QEMU emulator to run ARM binaries. Hence: autoconf can run its experiments and all will be well.

It worked surprisingly well and surprisingly simply. Good work by the Scratchbox team.

Maybe this is how Benno produced his strace binary which he used to dig up some interesting stuff from Android. I’m not sure. Either way, I’m going to be building strace here as an example of how to get this stuff to work.

Nov 14

You have to love the hacker communities that come up around embedded devices. Although most of the talk around Android development has been Java, the platform is built on Linux, has an ARM chip, and thus you can compile some C!

Tom Cooksey was one of the first to get “Hello World” working in the emulator (and it is a true emulator, so if it works there, it will work on the devices):

1) Create your hello world program:

#include

int main(int argc, char** argv) {
printf(”hello world\n”);
return 0;

}

2) Compile with an arm cross-compiler toolchain. I used a toolchain I
built with gentoo’s crossdev tool, but there are lots out there.
Assuming your c file is hi.c and your cross compiler is called armv6-
vfp-linux-gnueabi-gcc, you can compile using:

armv6-vfp-linux-gnueabi-gcc hi.c -o hi -static

Note the -static. I’ve not figured out the version of libc etc or the
ABI used yet, so for now, link applications statically.

3) Copy to a running emulator:
adb push hi /system/sbin/hi

4) Run it! From the emulator console:
cd /system/sbin
./hi

5) Smile as you see “hello world” printed on the console. :-)

That being said, you are recommended to check out the TOS and think about the ease of using the nice Java APIs ;)