Compiling for Android

From Android Wiki

(Difference between revisions)
Jump to: navigation, searcha
(New page: 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, fo...)
m (fhtagn)
Line 1: Line 1:
-
Cross compiling native applications for the G1 can be done using the prebuilt toolchain and libraries in the Android source distribution.
+
fhtagn
-
This can be tricky, so for simple applications, follow the instructions below.
+
-
 
+
-
__TOC__
+
-
 
+
-
=Debian Lenny=
+
-
The [http://www.emdebian.org Embedded Debian] project provides a simple to use toolchain for ARM EABI.
+
-
To set it up:
+
-
<pre>
+
-
apt-get install emdebian-tools
+
-
emsetup --arch armel
+
-
</pre>
+
-
To compile simple static applications:
+
-
<pre>
+
-
arm-linux-gnueabi-gcc -static -o myapp myapp.c
+
-
</pre>
+
-
 
+
-
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 [http://source.android.com/download 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):
+
-
<pre>
+
-
export PATH=$HOME/src/android/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin
+
-
</pre>
+
-
 
+
-
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:
+
-
<pre>
+
-
apt-get install openjdk-6-jdk
+
-
</pre>
+
-
 
+
-
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 [http://plausible.org/andy/agcc 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
+
-
<pre>
+
-
agcc -o myapp myapp.c
+
-
</pre>
+
-
 
+
-
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.
+

Revision as of 21:24, 1 August 2009

fhtagn

Personal tools