This article was first published on the wechat public account “Backend Technical Officer”

This is the fourth installment of BATcoder, a sequel to the Android Advanced Trilogy that expands and updates the Android Advanced Trilogy and will be shared in a video. The reason why I call it BATcoder is because I want you to watch my video and get into your favorite factory.

Video version

See the video for more details and content:

B station address: www.bilibili.com/video/BV19f…

Personal blog address: liuwangshu. Cn/batcoder/ao…

1. About the AOSP

AOSP (Android Open Source Project) is Open Google Android Open Source Project, Chinese website is: the Source. The Android. Google. Cn /. AOSP is generally an Android system source project, through which it can customize the Android operating system, domestic mobile phone manufacturers are developed on this basis of the customized system. Because of the wall, if you cannot connect to Google server to get AOSP source code, you can from tsinghua University mirror station or university of Science and Technology mirror. This article takes the mirror station of Tsinghua University as an example.

Download the REPO tool

Android source code contains hundreds of Git libraries, just downloading so many Git libraries is a heavy task, so Google developed repo, which is a tool for managing Android version libraries. It uses Python to encapsulate Git to a certain extent, simplifying the management of multiple Git version libraries. Install Git and type the following command in Ubuntu:

sudo apt-get install git
Copy the code

The following error may be reported:

Another program is running, so the resource is locked and unavailable. Enter the following command to resolve the problem:

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
Copy the code

Next create bin and add it to PATH.

mkdir ~/bin
PATH=~/bin:$PATH
Copy the code

Curl library:

sudo apt-get install curl
Copy the code

Download the REPO and set permissions:

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
Copy the code

Finally, install Python, which is used for repO initialization:

sudo apt-get install python
Copy the code

Restart the VM and download the source code.

3. Download the source code

Create a working directory:

mkdir aosp
cd aosp
Copy the code

While repo is running, it will try to update itself with an official Git source. If you want to update it with a tuna image source, you can copy the following contents into your ~/.bashrc:

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
Copy the code

Set identity, add your own email address and name:

git config --global user.email "[email protected]"
git config --global user.name "piratemorgen"
Copy the code

Initialize the repository (no version specified, most recent code downloaded by default)

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
Copy the code

Initialize and specify the version:

Repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest - b android - 11.0.0 _r1Copy the code

Synchronous source code:

repo sync
Copy the code

After downloading the source code, see the following information to indicate that the download was successful. 9.0 whole source code size is 36.5g, 11.0 source code size is 59.1g

If you feel very troublesome, you can also directly go to a Baidu network disk I share to download the source code of AOSP, version range from 1.6 to 11.0. Inside the source code is a condensed version, can not be compiled. Link: pan.baidu.com/s/1cDHDwVNh… Extraction code: BZA8

4. Download the kernel source code

AOSP source code does not include the kernel source code, which needs to be downloaded separately. There are many versions of the kernel source code, for example, Common is the universal Linux kernel, MSM is the Android device that uses Qualcomm MSM chip, and Piranere is the kernel source code for the Android emulator. Here piranere is taken as an example.

As with downloading the AOSP source code, we need to create the working directory first:

mkdir kernel
cd kernel
Copy the code

Using tsinghua’s image:

git clone https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.git
Copy the code

Then the kernel directory will generate a goldfish folder, enter the goldfish directory and run the git command.

cd goldfish
git branch -a
Copy the code

It lists which kernel version branches are available for download.

Choose to download Goldfish version 3.4 here.

Git checkout remotes/origin/android - goldfish - 3.4Copy the code

See the video for more details and content:

B station address: www.bilibili.com/video/BV19f…

Personal blog address: liuwangshu. Cn/batcoder/ao…

Author introduction: Liu Wangshu, the most valuable expert of Tencent Cloud, is the author of the best-selling books “Android Advanced Light”, “Android Advanced Decryption”, “Android Advanced Refers to the North”, has been the annual outstanding author of the Publishing House of Electronics Industry for four consecutive years, the former huawei interviewer, is now the technical director of Dachang, Google Developer community guest lecturer.

Also welcome to pay attention to my public number will share big front-end, Java related technology.