Download the Android source

The Android source is located in a collection of Git repositories hosted by Google. The Git repository includes the entire history of the Android source, including changes to the source and when the changes were made. This page describes how to download the source.

Initialize the Repo client

Set up your client to access the Android source repository:

  1. Create and navigate to a working directory:

  2. Initialize your working directory for source control:

    $ repo init -b main -u

    The -b option is used to identify the branch you are initializing. If -b isn't provided, repo init defaults to the main branch. For a list of branches and tag names, see Source code tags and builds.

    The -u option is required and is used to specify a manifest file, which is an XML file specifying where the various Git projects in the Android source are placed within your working directory. In this example, the name of the manifest file isn't specified, so the command uses the default manifest file (default.xml).

    The output should contain the message:

    $ repo has been initialized in path_to_working_directory

For information on manifest file format, see repo Manifest Format.

For a list of all Repo commands, see the Repo command reference.

Download the Android source

Run the following command to download the Android source tree to your working directory:

$ repo sync -c -j8

The -c argument instructs Repo to fetch the current manifest branch from the server. The -j8 command splits the sync across threads for faster completion.

This operation should take a little over an hour.

If you run into any problems during download, refer to Troubleshoot network issues.

Troubleshoot network issues

This section provides several suggestions for fixing network issues that can cause unsuccessful syncs.

Use authentication to avoid quota barriers

To protect the servers against excessive use, each IP address that's used to access source is associated with a quota.

When sharing an IP address with other users, such as when accessing the source repositories from beyond a NAT firewall, quotas can trigger for normal patterns. For example, a quota can trigger when several users sync new clients from the same IP address, within a short period.

To avoid triggering quotas, you can use authenticated access, which uses a separate quota for each user, regardless of the IP address.

To enable authenticated access:

  1. Create a password with the password generator.

  2. Run the following command to convert your client to use automatic authentication (without changing branch):

    $ repo init -u

    Note that the /a/ directory prefix triggers automatic authentication.

Configure for proxy use

If you're downloading source from behind a proxy, as is common in some corporate environments, ensure you explicitly specify a proxy for Repo to use by running these commands:

$ export HTTP_PROXY=http://proxy_user_id:proxy_password@proxy_server:proxy_port
$ export HTTPS_PROXY=http://proxy_user_id:proxy_password@proxy_server:proxy_port

Adjust TCP/IP settings to avoid connectivity issues

While it's rare, Linux clients can experience connectivity issues, such as getting stuck in the middle of downloads while receiving objects. To improve this issue, adjust the settings of the TCP/IP stack or use non-parallel connections. You must have root access to modify the TCP setting. To modify the setting, issue the following commands:

$ sudo sysctl -w net.ipv4.tcp_window_scaling=0
$ repo sync -j1

Use a local mirror to avoid network latency

When using several clients, you can create a local mirror of the entire server content and sync clients from that mirror without accessing the network. Follow these instructions to create a local mirror in at ~/aosp-mirror/ and sync clients against that mirror:

  1. Create and sync the mirror:

    $ mkdir -p /usr/local/aosp/mirror
    $ cd /usr/local/aosp/mirror
    $ repo init -u --mirror

    These commands create a local mirror in /user/local/aosp/mirror and initialize the mirror using the --mirror flag with the repo init command.

  2. To sync clients from the mirror:

    $ mkdir -p /usr/local/aosp/main
    $ cd /usr/local/aosp/main
    $ repo init -u /usr/local/aosp/mirror/platform/manifest.git
    $ repo sync
  3. Finally, follow these commands to sync the mirror against the server and sync the client against the mirror:

    $ cd /usr/local/aosp/mirror</code>
    $ repo sync
    $ cd /usr/local/aosp/main
    $ repo sync

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 among users or machines.

Use a partial clone

If you're using Git version 2.19 or later, specify --partial-clone when performing repo init to overcome any low-latency network issues:

  $ repo init -u -b main --partial-clone --clone-filter=blob:limit=10M

Instead of initializing Repo to download everything, this command downloads Git objects as they are needed.

Download proprietary binaries

AOSP can run on Cuttlefish emulators directly, but AOSP can't be used on hardware without additional device-specific proprietary libraries. Here's how to obtain those device binaries:

  • If you're downloading the main branch and building for a Nexus or Pixel device, download the latest binaries from the Binaries preview site.
  • If you're downloading and building the main branch and building for your own device, you must provide your device-specific binaries.
  • If you're downloading and building a tagged, non-main, branch and building for a Nexus or Pixel device, download the device-specific binary from Binaries for Nexus and Pixel devices.

Extract proprietary binaries

Each set of binaries comes as a self-extracting script in a compressed archive. To extract and place these binaries in the correct location of your source tree:

  1. Extract the archive.
  2. Run the included self-extracting shell script from the root of your AOSP source tree.
  3. Agree to the terms of the enclosed license agreement. The binaries and their matching makefiles are installed in the vendor/ hierarchy of the source tree.

(optional) Verify code legitimacy

If you're concerned about the legitimacy of the source code, such as whether it came from Google, you can verify the git tags for the branch. To verify Git tags:

  1. Copy and paste the following key block into a text file, such as keyfile.asc.

    Version: GnuPG v1.4.2.2 (GNU/Linux)
  2. Run the following command to input a public key into your GnuPG key database. The key is used to sign annotated tags that represent releases.

    $ gpg --import keyfile.asc
  3. After importing the keys, you can verify any tag by running this command:

    $ git tag -v TAG_NAME