Android Source

From Gumstix User Wiki
Jump to: navigation, search

This page explains how to build Android from source from fresh or to update an existing source build. If you just want to test drive Android, you may prefer to use prebuilt images.

All the source code is freely available for download, customization, and improvement. This section explains how to set up a development machine to build all the required components from source. These instructions have been tested on Ubuntu Maverick (10.10) 32 and 64 bit machines; as a rough estimate, this process requires 10GB of hard drive space and takes 4 hours (30 minutes of setup, 1.5 hours to download code, and 2 hours to build) on a moderate development machine. Users with existing Android source can rapidly update.

Setup

Android requires Sun(tm) Java and some additional software packages. These instructions assume an Ubuntu system however for other systems, see these pointers. Begin by adding the official java repository for your system ('lucid' is fine, even if you are using a different Ubuntu version) and installing a new version of Java (you'll need to agree to the license agreement).

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
$ sudo update-java-alternatives -s java-6-sun

Note, it is normal to get some error: no alternatives for... messages.

Now, install other required software. If you are building on a 64-bit machine (i.e. uname -a|grep x86_64), these packages are required:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev expect uboot-mkimage

For 32-bit machines, use these packages instead:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib x11proto-core-dev libx11-dev expect uboot-mkimage

Finally, install the repo tool. Repo is a tool to manage multiple Git repositories. You can install it wherever you like but if you have administrator rights, you might find this convenient:

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > repo
$ chmod a+x repo
$ sudo mv repo /usr/bin/repo

Fetch Source Code

With Repo installed, it is possible to use a single manifest file that describes all the git repositories to be fetched. More information about repo can be found here. These instructions place everything in a ~/android directory but there is no restriction where this code is located.

$ mkdir ~/android
$ cd ~/android
$ repo init -u git://github.com/gumdroid/android-manifest.git

Respond to the prompted questions to finish the initialization. This next step fetches all the code and may take an hour or so. If a particular repository checkout fails, re-issue this command until everything has been successfully fetched (and most regrettably, it can takes a few tries).

$ repo sync

Tip: Use repo sync -j2 to do multi-threaded fetches (but be alert for repositories that fail to download).

Updating

Users trying to get a fresh build system running can skip this section; this may be useful for those who have previously set up an Android repository or who wish to host their own manifest.

To update from a previous android installation, simply issue these commands in your top-level directory.

$ repo init -u git://github.com/gumdroid/android-manifest.git
$ repo sync

Repository Management

A manifest file is a XML file that describes a set of git repositories that, collectively, make up a project. In this case, most of the repositories are cloned directly from Google, OMAP3-specific tweaks come from the rowboat-android repositories, and items like the kernel and the bootloaders are pulled from Gumstix repositories. To update the manifest and source code, simple issue the 'repo sync' command. Manifests are themselves stored in a git repository so it is possible to use a manifest from a different git branch or commit. To specify a new repository source, specify a new argument for the '-u' switch.

$ repo init -u <git repository source URI>

To specify a different branch or revision, specify a new argument for the '-b' switch.

$ repo init -b <branch name>

By default, the repo expects to use a file named default.xml as the manifest but it is possible to specify the specific manifest file to use.

$ repo init -m <manifest.xml>

By forking the repository on github, it should be very easy to set up your own repository. For a look under the hood, navigate to the .repo directory.

Build

All required binaries and a root file system can be built for the Overo COM using the pre-built armel cross-compilers downloaded by repo.

Root File System

In the simple case, just calling 'make PRODUCT-overo-eng' will build an engineering build of the Overo target defined in device/gumstix/overo/AndroidBoard.mk. As usual, the '-j<#>' switch allows for a multi-threaded build. However, the following commands actually pull in some convenient macros, select a predefined combination (see the device/gumstix/overo/vendorsetup.mk; use choosecombo to select your own) and use the 'm' alias for make to build the root filesystem.

$ source build/envsetup.sh
$ lunch overo-eng

The current build will not compile with out these hacks, whoever maintains the sources should look into fixing this.

$ make update-api
$ find  . -type f  -name '*.mk' -exec sed -i "s/-flto//g" '{}' \; 
$ find  . -type f -name '*.mk' -exec sed -i "s/Werror=strict-aliasing/Wall/g" '{}' \;

Then compile!

$ m -j1

Note: Those building with a 32-bit system will get angry warnings on the first build. These can be ignored.

Note: To build a specific directory, navigate there and use the 'mm' macro or use the 'mmm' macro with the directory path as an argument. As explained, 'make clean' and 'make clobber' will clean up any messes.

After an hour or two, the build should complete with populated root and system directories in the out/target/product/overo directory.

Bootloaders, Kernel, and SGX support

The x-load and u-boot bootloaders, the linux kernel, and the SGX graphics code each have their own build system. These have been crudely integrated with Android: repo fetches the necessary files and a simple script can be called to perform a clean build of each of these component:

$ source utils/gumcompile

Note: This also generates a boot.scr u-boot bootloader script to set the necessary environment variables on boot. To change this script, modify utils/androidboot.cmd. For more fine-grained control, use the corresponding build systems directly (though looking at this script prove helpful).

Create a Tarball

The final step is wrapping all the generated files into a tarball with appropriate permissions.

$ source utils/genrootfs

In the out/target/product/overo directory, you should find the following files needed to make a bootable microSD card.

  • MLO
  • u-boot.bin
  • boot.scr
  • uImage
  • rootfs.tar.bz2

Note: At the moment, the MLO built by the gumcompile will intermittently fail to boot a COM. As such, the MLO found in the output directory is copied from a known good pre-built binary in the utils/ directory.

Help and Help Out

These steps have refined from the [rowboat-android] wiki and from google documentation. Other useful links include:

Patches, suggestions and improvements are most welcome---please send to ash (at) gumstix.com. Pull requests on the github repositories are likewise appreciated.