Go to Google Groups Home    Android Developers
Re: Native C "Hello World" working in emulator

Jingtao Wang <jingt...@gmail.com>

Excellent work!

I just noticed that some classes in Android.jar used the keyword
"native". It should be a matter of time to get either offical or
unofficial suport for calling native code from the Dalvik VM.

On Nov 13, 9:31 am, TomCooksey <TomCook...@googlemail.com> wrote:

> I've managed to get a native C application working in the emulator.

> For those who are interested, here's how:

> 1) Create your hello world program:

> #include <stdio.h>

> 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. :-)

> Next, I'm going to try and get busybox up & running so we can have
> access to exciting programs such as "cp"! After that, perhaps dropbear
> for remote ssh access? Or maybe a small web server like boa so we can
> turn the android emulator into a webserver? Stay tuned.