Initializing A Build Environment
Initializing A Build Environment
Initializing A Build Environment
This section describes setting up local work environment, using Repo to get the Android files, and building the files on your machine. To build the Android source files, it requires Linux .
Choosing a Branch
Some of the requirements for build environment are determined by which version of the source code you plan to compile. See Build Numbers for a full listing of branches you may choose from. You may also choose to download and build the latest source code (called "master"), in which case you will simply omit the branch specification when you initialize the repository. Once you have selected a branch, follow the appropriate instructions below to set up your build environment.
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" $ sudo apt-get update $ sudo apt-get install sun-java6-jdk
# adb protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>" # fastboot protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>" # adb protocol on crespo/crespo4g (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>" # fastboot protocol on crespo/crespo4g (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
# adb protocol on stingray/wingray (Xoom) SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>" # fastboot protocol on stingray/wingray (Xoom) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>" # adb protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>" # fastboot protocol on maguro/toro (Galaxy Nexus) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>" # adb protocol on panda (PandaBoard) SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>" # fastboot protocol on panda (PandaBoard) SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>" # usbboot protocol on panda (PandaBoard) SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>" # usbboot protocol on panda (PandaBoard ES) SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
Those new rules take effect the next time a device is plugged in. It might therefore be necessary to unplug the device and plug it back into the computer.
Setting up ccache
You can optionally tell the build to use the ccache compilation tool. Ccache acts as a compiler cache that can be used to speed-up rebuilds. This works very well if you do "make clean" often, or if you frequently switch between different build products. Put the following in your .bashrc or equivalent. export USE_CCACHE=1
By default the cache will be stored in ~/.ccache. If your home directory is on NFS or some other non-local filesystem, you will want to specify the directory in your .bashrc as well. export CCACHE_DIR=<path-to-your-cache-directory>
The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code. prebuilt/linux-x86/ccache/ccache -M 50G
The output directory for each separate source tree will be named after the directory holding the source tree. For instance, if you have source trees as /source/master1 and /source/master2 and OUT_DIR_COMMON_BASE is set to /output, the output directories will be/output/master1 and /output/master2. It's important in that case to not have multiple source trees stored in directories that have the same name, as those would end up sharing an output directory, with unpredictable results. This is only supported on branches newer than 4.0.x (IceCreamSandwich).
$ mkdir ~/bin
$ PATH=~/bin:$PATH
Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.
A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.
The Android source files will be located in your working directory under their project names. The initial sync operation will take an hour or more to complete. For more aboutrepo sync and other Repo commands, see Version Control.
Using authentication
By default, access to the Android source code is anonymous. To protect the servers against excessive usage, each IP address is associated with a quota. When sharing an IP address with other users (e.g. when accessing the source repositories from beyond a NAT firewall), the quotas can trigger even for regular usage patterns (e.g. if many users sync new clients from the same IP address within a short period). In that case, it is possible to use authenticated access, which then uses a separate quota for each user, regardless of the IP address. The first step is to create a password from the password generator and to save it in ~/.netrc according to the instructions on that page. The second step is to force authenticated access, by using the following manifest URI: https://android.googlesource.com/a/platform/manifest. Notice how the /a/ directory prefix triggers mandatory authentication. You can convert an existing client to use mandatory authentication with the following command: $ repo init -u https://android.googlesource.com/a/platform/manifest
More rarely, Linux clients experience connectivity issues, getting stuck in the middle of downloads (typically during "Receiving objects"). It has been reported that tweaking the settings of the TCP/IP stack and using non-parallel commands can improve the situation. You need root access to modify the TCP setting: $ sudo sysctl -w net.ipv4.tcp_window_scaling=0 $ repo sync -j1
Once the mirror is synced, new clients can be created from it. Note that it's important to specify an absolute path: $ mkdir -p /usr/local/aosp/master $ cd /usr/local/aosp/master $ repo init -u /usr/local/aosp/mirror/platform/manifest.git $ repo sync
Finally, to sync a client against the server, the mirror needs to be synced against the server, then the client against the mirror:
It's possible to store the mirror on a LAN server and to access it over NFS, SSH or Git. It's also possible to store it on a removable drive and to pass that drive around between users or between machines.
Copy and paste the key(s) below, then enter EOF (Ctrl-D) to end the input and process the keys. -----BEGIN PGP PUBLIC KEY BLOCK----Version: GnuPG v1.4.2.2 (GNU/Linux)
mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7 8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z wNj96SA8BL+a1O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XRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM= =Wi5D -----END PGP PUBLIC KEY BLOCK-----
After importing the keys, you can verify any tag with $ git tag -v TAG_NAME
If you haven't set up ccache yet, now would be a good time to do it.
Initialize
Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation. $ source build/envsetup.sh
or $ . build/envsetup.sh
Choose a Target
Choose which target to build with lunch. The exact configuration can be passed as an argument, e.g. $ lunch full-eng
The example above refers to a complete build for the emulator, with all debugging enabled. If run with no arguments lunch will prompt you to choose a target from the menu. All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename referring to the particular feature combination:
Use limited access; suited for production like "user" but with root access and debuggability; preferred for debugging development configuration with additional debugging tools
For more information about building for and running on actual hardware, see Building for devices
Run It!
You can either run your build on an emulator or flash it on a device. Please note that you have already selected your build target with lunch, and it is unlikely at best to run on a different target than it was built for.
Flash a Device
To flash a device, you will need to use fastboot, which should be included in your path after a successful build. Place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell with $ adb reboot bootloader
The -w option wipes the /data partition on the device; this is useful for your first time flashing a particular device, but is otherwise unnecessary. For more information about building for and running on actual hardware, see Building for devices
Using ccache
ccache is a compiler cache for C and C++ that can help make builds faster. In the root of the source tree, do the following: $ export USE_CCACHE=1 $ export CCACHE_DIR=/<path_of_your_choice>/.ccache $ prebuilt/linux-x86/ccache/ccache -M 20G
You can watch ccache being used by doing the following: $ watch -n1 -d prebuilt/linux-x86/ccache/ccache -s
This may be caused by failing to install the correct JDK as specified on the Initializing page. Building Android requires Sun JDK 5 or 6 depending on which release you are building. another JDK that you previously installed appearing in your path. You can remove the offending JDK from your path with:
$ export PATH=${PATH/\/path\/to\/jdk\/dir:/}
Python Version 3
Repo is built on particular functionality from Python 2.x and is unfortunately incompatible with Python 3. In order to use repo, please install Python 2.x: $ apt-get install python
Please follow the instructions on the Initializing page for creating a case-sensitive disk image.
No USB Permission
On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions on the Initializing page for configuring USB access. If adb was already running and cannot connect to the device after getting those rules set up, it can be killed with adb kill-server. That will cause adb to restart with the new configuration.
The Motorola Xoom is supported in the Wi-fi configuration "wingray" sold in the USA. Nexus S is supported in the GSM configuration "crespo". In addition, PandaBoard a.k.a. "panda" is supported in the master branch only, but is currently considered experimental. The specific details to use a PandaBoard with the Android Open-Source Project are in the file device/ti/panda/README in the source tree. Nexus One a.k.a. "passion" is obsolete, was experimental in gingerbread and unsupported, and can't be used with newer versions of the Android Open-Source Project. Android Developer Phones (ADP1 and ADP2, a.k.a. "dream" and "sapphire") are obsolete, were experimental and unsupported in froyo, and can't be used with newer versions of the Android OpenSource Project. No CDMA devices are supported in the Android Open-Source Project.
Keys Press and hold both Volume Up and Volume Down, then press and hold Power Press and hold Input, then press Power Press and hold Volume Down, then press and hold Power Press and hold Volume Up, then press and hold Power Press and hold the trackball, then press Power Press and hold Back, then press Power
Device dream
Also, on devices running froyo or later where adb is enabled, the command adb reboot bootloader can be used to reboot from Android directly into the bootloader with no key combinations.
The procedure must be confirmed on-screen, and deletes the user data for privacy reasons. It only needs to be run once. Note that on the Nexus S, Motorola Xoom and on Galaxy Nexus, all data on the phone is erased, i.e. both the applications' private data and the shared data that is accessible over USB, including photos and movies. Be sure to make a backup of any precious files you have before unlocking the bootloader. On Nexus One, the operation voids the warranty and is irreversible. On Nexus S, Xoom, and Galaxy Nexus, the bootloader can be locked back with $ fastboot oem lock
Note that this erases user data on Xoom (including the shared USB data).
When a device is suppoted in the master branch, the binaries for the most recent numbered release are the ones that should be used in the master branch. There are no official binaries for Nexus One, ADP2 or ADP1.
Branch android-4.0.4_r2.1 or master master android-4.0.4_r2.1 or master android-4.0.4_r2.1 or master android-2.3.7_r1 android-2.2.3_r1
Device dream
Branch android-2.2.3_r1
Flashing a device
Set the device in fastboot mode if necessary (see above). Because user data is typically incompatible between builds of Android, it's typically better to delete it when flashing a new system. $ fastboot erase cache $ fastboot erase userdata
An entire Android system can be flashed in a single command: this writes the boot, recovery and system partitions together after verifying that the system being flashed is compatible with the installed bootloader and radio, and reboots the system. $ fastboot flashall
On all devices except passion, the commands above can be replaced with a single command $ fastboot -w flashall
Note that filesystems created via fastboot on Motorola Xoom aren't working optimally, and it is strongly recommended to re-create them through recovery $ adb reboot recovery
Once in recovery, open the menu (press Power + Volume Up), wipe the cache partition, then wipe data.
Android Version 2.3 (GRH55) 2.3.1 (GRH78) 2.3.2 (GRH78C) 2.3.3 (GRI40) 2.3.4 (GRJ22) 2.3.5 (GRJ90) 2.3.6 (GRK39F) 4.0.3 (IML74K) 4.0.4 (IMM76D) 4.0.4 (IMM76I) 4.0.4 (IMM76K) 4.0.4 (IMM76L)
Preferred Bootloader I9020XXJK1 I9020XXJK1 I9020XXJK1 I9020XXKA3 I9020XXKA3 I9020XXKA3 I9020XXKA3 I9020XXKL1 I9020XXKL1 I9020XXKL1 I9020XXKL1 I9020XXKL1
Preferred Radio I9020XXJK8 I9020XXJK8 I9020XXJK8 I9020XXKB1 I9020XXKD1 I9020XXKF1 I9020XXKF1 I9020XXKI1 I9020XXKI1 I9020XXKI1 I9020XXKI1 I9020XXKI1
Also possible
All previous versions All previous versions All previous versions All previous versions All previous versions
Android Version 2.3.3 (GRI54) 2.3.4 (GRJ22) 2.3.5 (GRJ90) 2.3.6 (GRK39C)
Also possible
Android Version 2.3.6 (GRK39F) 4.0.3 (IML74K) 4.0.4 (IMM76D) 4.0.4 (IMM76I) 4.0.4 (IMM76K) 4.0.4 (IMM76L)
Android Version 2.3.3 (GRI54) 2.3.4 (GRJ22) 2.3.5 (GRJ90) 2.3.6 (GRK39F) 4.0.3 (IML74K) 4.0.4 (IMM76D) 4.0.4 (IMM76I) 4.0.4 (IMM76K) 4.0.4 (IMM76L)
Preferred Bootloader I9020XXKA3 I9020XXKA3 I9020XXKA3 I9020XXKA3 I9020XXKL1 I9020XXKL1 I9020XXKL1 I9020XXKL1 I9020XXKL1
Preferred Radio I9020KRKB3 M200KRKC1 M200KRKC1 M200KRKC1 M200KRKC1 M200KRKC1 M200KRKC1 M200KRKC1 M200KRKC1
Also possible
All previous versions All previous versions All previous versions All previous versions
Android Version 4.0.1 (ITL41D) 4.0.2 (ICL53F) 4.0.3 (IML74K) 4.0.4 (IMM76D) 4.0.4 (IMM76I) 4.0.4 (IMM76K) 4.0.4 (IMM76L)
Also possible
If you're building a new version of Android, if your Nexus S or Galaxy Nexus has an older bootloader and radio image that is marked as being also possible in the table above but is not recognized by fastboot, you can locally delete the version-bootloader and version-baseband lines in device/samsung/crespo/board-info.txtor device/samsung/maguro/board-info.txt
Building Kernels
If you are only interested in the kernel, you may use this guide to download and build the appropriate kernel. The following instructions assume that you have not downloaded all of AOSP. If you have downloaded all of AOSP, you may skip the git clone steps other than the step to download the actual kernel sources. We will use the Pandaboard kernel in all the following examples.
The log should contain notes of the commit SHA1 for the appropriate kernel project. Keep this value at hand so that you can use it in a later step.
Downloading sources
Depending on which kernel you want, $ git clone https://android.googlesource.com/kernel/common.git $ git clone https://android.googlesource.com/kernel/exynos.git $ git clone https://android.googlesource.com/kernel/goldfish.git $ git clone https://android.googlesource.com/kernel/msm.git $ git clone https://android.googlesource.com/kernel/omap.git $ git clone https://android.googlesource.com/kernel/samsung.git $ git clone https://android.googlesource.com/kernel/tegra.git
The goldfish project contains the kernel sources for the emulated platforms. The msm project has the sources for ADP1, ADP2, Nexus One, and can be used as a starting point for work on Qualcomm MSM chipsets. The omap project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets. The samsung project is used for Nexus S and can be used as a starting point for work on Samsung Hummingbird chipsets. The tegra project is for Xoom, and can be used as a starting point for work on NVIDIA Tegra chipsets. The exynos project can be used as a starting point for work on Samsung Exynos chipsets.
Building
As an example, we would build the panda kernel using the following commands: $ export ARCH=arm $ export SUBARCH=arm $ export CROSS_COMPILE=arm-eabi$ cd omap $ git checkout <commit_from_first_step> $ make panda_defconfig $ make
To build the tuna kernel, you may run the previous commands replacing all instances of "panda" with "tuna". The kernel for maguro and toro is device/samsung/tuna/kernel The kernel for crespo and crespo4g is device/samsung/crespo/kernel The kernel for stingray and wingray is device/moto/wingray/kernel
The image is output as arch/arm/boot/zImage. You may copy it as device/<vendor>/<name>/kernel or device/ti/panda/kernel in the case of this example.