Compiling for Android

From Android Wiki

Jump to: navigation, searcha

Cross compiling native applications for the G1 can be done using the prebuilt toolchain and libraries in the Android source distribution. This can be tricky, so for simple applications, follow the instructions below.

Source(s): Android solutions

Contents


Debian Lenny

Note: In Ubuntu Maverick emdebian-tools is provided by a different package, emdebian-crush.

The Embedded Debian project provides a simple to use toolchain for ARM EABI. To set it up:

apt-get install emdebian-tools
emsetup --arch armel

To compile simple static applications:

arm-linux-gnueabi-gcc -static -o myapp myapp.c

So the limitation here is that the application is statically linked. A nicer setup would give us dynamically linked applications. One of the trickier aspects here is that Android uses a custom, tiny libc, (bionic). Here are some instructions on getting a working setup for compiling a dynamically-linked program with the prebuilt Android toolchain. Perhaps someone can use these instructions to create a simpler process using the emdebian toolchain.

To get the Android prebuilt toolchain:

1. First download the Android source.

2. That ships with a prebuilt toolchain with a compiler named something like arm-eabi-gcc . It's convenient to get that onto your PATH with something like the following (assuming Android source in $HOME/src/android):

export PATH=$HOME/src/android/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin

3. Next you'll actually need to compile at least the bionic libc. Without having gone through the effort of doing a minimal compile here, you can do just "make" and wait quite a while for all of Android to get compiled. Note that early on the Makefile will abort if it can't find a JDK that it likes. Presumably no Java is actually needed for the native compilation we're doing here, but again, without having wrestled that out of the Makefiles yet, you can satisfy that requirement with packages from Debian's main repository:

apt-get install openjdk-6-jdk

4. Next, there are various flags and things needed to cross-compile an application and properly link it to bionic. Andrew Ross has written a perl script to take the pain away here and with the android toolchain in your PATH you're ready to go. Grab his agcc script and put it into your PATH somewhere, (perhaps in $HOME/bin or so).

5. With all those steps done you can now cross-compile an application dynamically linked to bionic

agcc -o myapp myapp.c

If people could go through the above and simplify it to the following minimal steps, that would be great:

1. Install emdebian

2. Download and compile bionic

3. Use something like Andew's agcc, but designed for the emdebian toolchain.

then that would be very appreciated.


Source(s): Android solutions

Personal tools