12 official version has been released Android: mp.weixin.qq.com/s/OiFSWEnc-… 12 the official version of the code has been released, the official document is also updated: source. Android. Google. Cn /
This article takes you through downloading and compiling the latest Android 12 code. Native-compiled code has several benefits
- It can be swiped-real to facilitate local debugging by developers, while the code can be imported into Android Studio for debugging
- You can compile the Userdebug version, root and remount, which is convenient to Debug the system and App. In Debug mode, you can see many problems that cannot be seen in the User version. At the same time, because you can see more information, it is convenient to conduct App competitive product analysis and App behavior analysis
- Android source code is easier to learn. The native version can open many system-level Debug logs, add logs, or modify the flow yourself
Cs.android.com is recommended if you do not need to download Debug and simply look at the code. For those who want to know more about Android system and those who are beginners in Android system development, the following configuration is recommended
- Get a used unlocked Pixel 3 or above (Android 12 only supports Pixel 3 or above)
- A desktop machine with a large enough hard disk (preferably SSD), large enough memory (preferably 32GB, swap if not), a weak CPU (otherwise it will affect compilation time), and Linux installed
1. Code download
Because of the use of Google official download site in China, there will be a situation, sometimes.repo can not download down, so this tutorial is based on the mirror site in China as an example, if you have a way to climb the wall, You can simply refer to official tutorial at https://source.android.google.cn/source/downloading
Hkust AOSP mirror site address: mirrors.ustc.edu.cn/help/aosp.h…
To download it, just follow the following steps (this works on Ubuntu, WSL, WSL2, Mac, but only Linux will be used when compiling the code. Therefore, it is recommended that you still use Ubuntu and other Linux systems for code download, compilation and development.
1.1 Step 1: Download the Repo tool
mkdir ~/bin
PATH=~/bin:$PATH
curl -sSL 'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
chmod a+x ~/bin/repo
Copy the code
1.2 Step 2: Configure Personal Information
If you don’t have Git installed, install it yourself and fill in your Name and Email
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Copy the code
Like what I did
git config --global user.name "Gracker"
git config --global user.email "[email protected]"
Copy the code
1.2 Step 3: Create a project directory
Create a working directory locally (any name, Android_12_AOSP as an example)
mkdir Android_12_AOSP
cd Android_12_AOSP
Copy the code
1.4 Step 4: Initialize the warehouse
There are two ways to initialize a repository, one is to download it directly, the other is to add a Tag, download a specific version of the Tag, the following two methods are described, you can choose which method (note: The two download methods here will affect subsequent driver downloads, so remember which method you are using and choose the appropriate driver in the driver download section.)
1.4.1 Direct Download (Recommended)
This method will download all the code, the default branch is master, if you don’t have to worry about space, just use this method to download
Repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest # # if prompt unable to connect to gerrit.googlesource.com, you can edit the ~ / bin/repo, The REPO_URL replaced with the following: # # REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'Copy the code
Note here that the default ‘use of address is REPO_URL =’ gerrit.googlesource.com/git-repo ‘, here we need to modify REPO_URL, can appear otherwise unable to download
- Modified method 1: in your rc file, add a configuration can be: REPO_URL = “gerrit-googlesource.proxy.ustclug.org/git-repo”
- To open direct modification method 2: ~ / bin/repo, to replace REPO_URL line as the following: REPO_URL = ‘gerrit-googlesource.proxy.ustclug.org/git-repo’
After downloading.repo, you will find the following information
➜ Android12 repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest Downloading repo source from https://gerrit-googlesource.proxy.ustclug.org/git-repo ... A new version of repo (2.17) is available.... You should upgrade soon: cp /home/gracker/Code/Android12/.repo/repo/repo /home/gracker/bin/repo Downloading manifest from git://mirrors.ustc.edu.cn/aosp/platform/manifest remote: Enumerating objects: 91965, done. remote: Total 91965 (delta 0), reused 0 (delta 0) Your identity is: Gracker <[email protected]> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in /home/gracker/Code/Android12Copy the code
If you choose to download directly, you don’t need to look at 3.2
1.4.2 Downloading a specific Tag
This method is only download the corresponding code by a single Tag, the Tag can view here, https://source.android.google.cn/setup/start/build-numbers, For example, my developer is Google Pixel 3 XL. I checked the Tag list of the corresponding model. Currently, only two tags have been released for Android 12, as follows
The corresponding tags are Android-12.0.0_R3 and Android-12.0.0_R1 respectively, so I can specify the corresponding tags when downloading. The advantage of this is that there is less code to download and the download speed is faster. The inconvenient part is that it’s not easy to update. Google will send you regular emails telling you which new tags are released and you can update your code accordingly
Repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest - b android - 12.0.0 _r3Copy the code
1.5 Step 5: Synchronize code
Step 3 above just downloaded the.repo file, but the specific code needs to be downloaded by performing repo Sync. Due to the limitations of the mirror station and the problems that may be encountered during the download process, we recommend that you use -j4 to download
repo sync -j4
Copy the code
Then the long download begins, and since there are likely to be failures during the download process, you can do an SH step to cycle the download and wake up and download it
#! /bin/bash repo sync -j4 while [ $? -ne 0 ] do echo "======sync failed ,re-sync again======" sleep 3 repo sync -j4 doneCopy the code
The specific methods
Create rebo. sh file vim rebo. sh # 2. Copy the above script contents into the repo.sh file, where you can open and modify the file using any method you like, such as vscode chmod a+x repo.sh #3. / rebo. sh # 4. Run the script and everything is fineCopy the code
2. Download the driver
After the code download, we don’t worry about compiling, if you want to run on the real machine, need to download some manufacturers closed source driver files, so that the subsequent compilation of the code can run to the real machine, The corresponding official documentation at https://source.android.google.cn/setup/build/downloading#obtaining-proprietary-binaries
When downloading the code above, we mentioned two ways, direct download and specific Tag download, different download methods corresponding to the driver is different
2.1 Driver for Direct Download
Direct download code using the master branch, drivers need to download https://developers.google.cn/android/blobs-preview here
In the case of my Pixel 3 XL, the driver I need to download is
Click Link to download the two files, unpack them to the root directory, and execute the sh script to release the driver to the appropriate location. The binary file and its corresponding Makefile will be installed in the vendor/ hierarchy of the source tree
2.2 Download the driver corresponding to the code of a specific Tag
If download – b, you will need to view the corresponding tag of the drive, the address is as follows: https://developers.google.cn/android/drivers
In the case of my Pixel 3 XL, Download a TAG for android – 12.0.0 _r3 (repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest – b android – 12.0.0 _r3)
Where sp1a.210812.016.a1 corresponds to section 4.2 above, that is, the Build ID corresponding to the Tag Android-12.0.0_R3 is SP1A.210812.016.a1. You can download a TAG to find the corresponding according to oneself the Build ID, then according to the Build ID to find the corresponding driver developers. Google. Cn/android/dri…
This corresponds to the Tag downloaded in Section 4.2:
2.3 Driver Extraction
The downloaded content is unpacked into two SH files, in the case of my Pixel 3 XL, executed at the root of the code, using D to scroll down the page until finally manually typing I ACCEPT
Extract -google_devices-crosshatch.sh /extract-google_devices-crosshatch.shCopy the code
/extract-qcom-crosshatch.sh./extract-qcom-crosshatch.shCopy the code
3. Code compilation
After the code and driver have been downloaded, you can start compiling the code. Since the new version does not support Mac compilation, it is recommended that you use Linux to compile the code. Ubuntu is recommended
Mac compilation is no longer supported
3.1 Setting the Compilation Environment
Reference: source. Android. Google. Cn/setup/build…
Ubuntu 18.04 run directly above:
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
Copy the code
3.2 Setting the code compilation environment
The following script needs to be re-executed each time the Shell is closed, which is equivalent to configuring the compilation environment
source build/envsetup.sh
Copy the code
or
. build/envsetup.sh
Copy the code
3.3 Selecting a compilation target
lunch
Copy the code
After running Lunch, a bunch of devices will come out for you to choose from. Again, take my Pixel 3 XL as an example. Check out the code names for all models here: https://source.android.google.cn/setup/build/running#selecting-device-build Pixel corresponding code is: 3 XL crosshatch
So I chose to compile aoSP_Crosshatch-userDEBUG. You can either type the number or just type AOSP_Crosshatch-userDebug
Lunch options
The script then does a series of configurations to output the following
3.4 All Compilation
Build everything with m. M can handle parallel tasks with the -jn argument. If you do not provide the -j parameter, the build system automatically selects the parallel task count that you think is best for your system.
m
Copy the code
As mentioned above, you can build specific modules by listing the corresponding names on the M command line, rather than building complete device images. In addition, M also provides some pseudo targets for various special purposes. Here are some examples:
- Droid -m Droid is a normal build. The target is here because the default target needs a name.
- All-m all builds everything that m Droid builds, plus everything that doesn’t contain the Droid tag. The build server runs this command to ensure that all elements contained in the tree that contain the Android.mk file are built.
- M – Runs the build system from the top of the tree. This is useful because you can run make in a subdirectory. If you set the TOP environment variable, it will use it. If you do not set this variable, it looks up the corresponding tree in the current directory to try to find the top level of the tree. You can build the entire source tree by running m with no arguments, or you can build specific targets by specifying names.
- Mma – Builds all modules and their dependencies in the current directory.
- Mmma – Builds all modules and their dependencies in the supplied directory.
- Croot-cd to top of tree.
- Clean -m clean deletes all output and intermediate files for this configuration. This content is the same as rm -rf out/.
Run m help to see the other commands provided by M
Enter m and start compiling for the first time. Long wait, compile time depends on your computer configuration. Mainly CPU and memory, recommended memory 32G go, CPU is not too bad
After a successful compilation, the following output is displayed
4. The flash
The self-compiled UserDebug firmware is very handy for debugging, both for the Framework and for apps
After compiling, let’s start brushing. Using my test machine Pixel 3 XL as an example, execute the following commands
Adb reboot fastboot # Fastboot flashall -w #Copy the code
flash
After that, the phone automatically reboots and enters the home screen, which concludes our download-compile-swipe part of the code
The Launcher of AOSP compiled by myself is ugly. Without the support of the Google closed source suite, it looks very shabby. It comes with very few apps and is basically poorly maintained
Or the official Pixel Launcher (developed and maintained by Google)
If the problems encountered in the process of flash, can brush official flash package to save: developers. Google. Cn/android/ima…
5. End
This article is mainly about how to download, compile, brush, subsequent code import, modify and compile module, code Debug, etc., will be introduced in another article