The Android source tree is housed in a Google-hosted Git repository. The Git repository contains metadata for the Android source, such as modifications to the source and the dates they were made. This article explains how to obtain the source tree for a particular Android code line.
Table of Content
Things You Should Know About Android Source Code
- Android programming continues to improve with the current Lollipop version. Since the initial AOSP release, the platform has matured significantly, raising user expectations significantly.
- There are thousands of devices available, each having a unique screen size, chip architecture, hardware configuration, and software version. Unfortunately, segmentation is the cost of openness, and even as an accomplished Android coder, there are thousands of ways your app can fail on different devices.
- Despite such extensive segmentation, the majority of defects are introduced as a result of logic errors. These issues are easily avoidable if you pay attention to the fundamentals.
Initializing a Repo client
Set up your client to use the Android source repository after installing the Repo Launcher:
- Make a directory with no files in it to hold your working files. Call it whatever you want:
mkdir WORKING_DIRECTORY cd WORKING_DIRECTORY
- Put your real name and email address into Git. To use the Gerrit code-review tool, you need an email address that is linked to a Google account. Make sure this is a working address where you can get mail. The name you give here will be used to credit your code contributions.
git config --global user.name Your Name git config --global user.email you@example.com
- If you run repo init, you’ll get the most recent version of Repo with the latest bug fixes. You must give a URL for the manifest, which tells your working directory where to put the different repositories that come with the Android source.
repo init -u https://android.googlesource.com/platform/manifest
- To look at the main branch:
repo init -u https://android.googlesource.com/platform/manifest -b master
- You can use -b to check out a branch other than master.
In Python 3, if you get a message that says “/usr/bin/env ‘python‘ no such file or directory,” try one of the following:
sudo ln -s /usr/bin/python3 /usr/bin/python
If you are using Git version 2.19 or higher, you can tell repo init to use —partial-clone. This uses Git’s partial clone feature so that only the Git objects that are needed are downloaded instead of everything. Because using partial clones means that many operations must talk to the server, here’s what a developer should do if they’re using a low-latency network:
repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M
Only for Windows OS:
Refer to the GitHub Symbolic Links documentation to build these or to enable their support if you receive an error message claiming that symbolic links could not be generated, causing repo init to fail. See the section on allowing non-administrators to create symbolic links for more information on non-administrators.
Repo is initialized in your working directory, according to a notification that appears after a successful startup. There is now a.repo directory in your client directory where files like the manifest are stored.
Obtaining the source code for Android
Run the following command to get the Android source tree from the repositories listed in the default manifest and download it to your working directory:
repo sync
- Pass the -c (current branch) and -jthreadcount flags to expedite syncs:
repo sync -c -j8
- The project names of the Android source files are downloaded in your working directory.
If you give the -q (quiet) flag, the output will be muted. All options are listed in the Repo Command Reference.
Using authentication
The Android source code is anonymous by default. Each IP address has a quota assigned to it in order to safeguard the servers against excessive usage.
- Even for routine use patterns, the quotas may be activated while sharing an IP address with other users (for instance, when accessing source repositories outside of a NAT firewall) (for example, if many users sync new clients from the same IP address within a short period).
- Then, regardless of the IP address, you can employ authorized access, which requires a separate quota for every user.
- First, use the password generator to generate a password and then adhere to the prompts on the password generator page.
- Use the manifest URI https://android.googlesource.com/a/platform/manifest to force authenticated access after that. Take note of how the /a/ directory prefix enforces required authentication. With the following command, you can change an existing client to require the required authentication:
repo init -u https://android.googlesource.com/a/platform/manifest
Resolving network problems
If you want Repo to utilize a specific proxy when downloading through one (which is typical in some corporate situations), you may need to do the following:
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>
Linux clients more seldom face connectivity issues that cause downloads to stall in the middle (typically during receiving objects). The problem can be improved by modifying the TCP/IP stack’s settings and employing non-parallel instructions. For you to change the TCP setting, you need root access:
sudo sysctl -w net.ipv4.tcp_window_scaling=0 repo sync -j1
Using a Local Mirror
It is preferable to build a local mirror of the complete server content when employing multiple clients, especially when bandwidth is limited, and to sync clients from that mirror (which requires no network access). The download for a full mirror is smaller and contains more data than the download for two clients.
These guidelines presuppose that the mirror has already been set up in /usr/local/aosp/mirror. Create and synchronize the mirror first. Take note of the —mirror flag, which is only available when a new client is created:
mkdir -p /usr/local/aosp/mirror cd /usr/local/aosp/mirror repo init -u https://android.googlesource.com/mirror/manifest --mirror repo sync
- You can make new clients from the mirror once it has been synchronized. Keep in mind that an absolute route must be specified:
mkdir -p /usr/local/aosp/master cd /usr/local/aosp/master repo init -u /usr/local/aosp/mirror/platform/manifest.git repo sync
- The mirror must first be synchronized with the server before the client is synchronized with the mirror in order to sync a client with the server:
cd /usr/local/aosp/mirror repo sync cd /usr/local/aosp/master repo sync
- The mirror can be kept on a LAN server and accessed through NFS, SSH, or Git. It can also be kept on a detachable disc that can be shared between users or devices.
the public key listed below into your GnuPG key database. Annotated tags that stand in for releases are signed using the key.
gpg --import
- Copy and paste the key below, then press the EOF (Ctrl-D) keyboard shortcut 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+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq /HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5 jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4 MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9 b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI 2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+ OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM= =Wi5D -----END PGP PUBLIC KEY BLOCK-----
- You can validate any tag after importing the keys with:
git tag -v TAG_NAME
Obtaining Exclusive Binaries
AOSP cannot be utilized only from source code and requires extra hardware-related proprietary libraries to function, such as hardware graphics acceleration. Download links and Device binaries are available in the sections below.
Downloading Proprietary Binaries
Google’s drivers provide official binaries for supported devices running tagged AOSP release branches. These binaries provide non-open source programming access to additional hardware features. Instead, utilize the Binaries Preview to build the AOSP master branch. Use the binaries for the most recent numbered release or with the most recent date when developing the master branch for a device.
Extracting Proprietary Binaries
Each set of binaries is delivered in the form of a self-extracting script in a compressed archive. Uncompress each archive, then run the attached self-extracting script from the source tree’s root, then confirm you agree to the contained license agreement. The binaries and their corresponding makefiles are installed in the source tree’s vendor/ hierarchy.
Cleaning Up
To guarantee that the newly installed binaries are appropriately taken into consideration after extraction, erase any prior build output using the:
make clobber
Tips
- Android is a robust platform that is constantly evolving. It may be unreasonable to expect users to keep up, but it is critical for Android developers to do so.
- It’s even more vital to understand that Android isn’t simply on our phones or tablets. It’s on your wrists, in our homes, in our kitchens, and in our cars. Before beginning to expand, you must first master the fundamentals.