Download android 12 source code and build img

sudo snap install curl

Then follow 

https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

install repo:

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Since the first synchronization needs to download about 60GB of data, any network failure during the process may cause the synchronization to fail. We strongly recommend that you use the initialization package for initialization.

curl -OC - https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包tar xf aosp-latest.tar 

cd AOSP   # 解压得到的 AOSP 工程目录# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
sudo apt install python2
sudo ln -s /usr/bin/python2 /usr/bin/python
sudo apt install git
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-12.0.0_r3
repo sync# 正常同步一遍即可得到完整目录# 或 repo sync -l 仅checkout代码

synchronous code

Step 3 above just downloaded the .repo file, and the specific code needs to execute repo sync to download. Due to the limitations of the mirror site and the problems that may be encountered during the download process, it is recommended that you use -j4 to download

repo sync -j4

. Code compilation

After the code and driver are downloaded, you can start to compile the code. Since the new version no longer supports Mac compilation, it is recommended that you still use Linux for compilation, and Ubuntu is recommended.

3.1 Set up the compilation environment

Reference: https://source.android.google.cn/setup/build/initializing

Run directly on Ubuntu 18.04 or 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

3.2 Setting up the code compilation environment

Every time you close the Shell, you need to re-execute the following script, which is equivalent to configuring the compilation environment

source build/envsetup.sh

or

. build/envsetup.sh

3.3 Select compilation target

lunch

After running lunch, there will be a bunch of devices for you to choose from. Let’s take my Pixel 3 XL as an example. Its code name is, and you can view the corresponding code names of all models here: https://source.android.google.cn/ The codename corresponding to setup/build/running#selecting-device-buildPixel 3 XL is: crosshatch

Find the corresponding model

So I chose to compile aosp_crosshatch-userdebug, here you can enter the number or directly enter aosp_crosshatch-userdebug

lunch option

然后脚本会进行一系列的配置,输出下面的内容

编译配置展示

3.4 全部编译

使用 m 构建所有内容。m 可以使用 -jN 参数处理并行任务。如果您没有提供 -j 参数,构建系统会自动选择您认为最适合您系统的并行任务计数

m

如上所述,您可以通过在 m 命令行中列出相应名称来构建特定模块,而不是构建完整的设备映像。此外,m 还针对各种特殊目的提供了一些伪目标。以下是一些示例:

  1. droid - m droid 是正常 build。此目标在此处,因为默认目标需要名称。

  1. all - m all 会构建 m droid 构建的所有内容,加上不包含 droid 标记的所有内容。构建服务器会运行此命令,以确保包含在树中且包含 Android.mk 文件的所有元素都会构建。

  1. m - 从树的顶部运行构建系统。这很有用,因为您可以在子目录中运行 make。如果您设置了 TOP 环境变量,它便会使用此变量。如果您未设置此变量,它便会从当前目录中查找相应的树,以尝试找到树的顶层。您可以通过运行不包含参数的 m 来构建整个源代码树,也可以通过指定相应名称来构建特定目标。

  1. mma - 构建当前目录中的所有模块及其依赖项。

  1. mmma - 构建提供的目录中的所有模块及其依赖项。

  1. croot - cd 到树顶部。

  1. clean - m clean 会删除此配置的所有输出和中间文件。此内容与 rm -rf out/ 相同。

运行 m help 即可查看 m 提供的其他命令

输入 m 之后开始第一次全部编译,漫长的等待,编译时间取决于你的电脑配置... 主要是 cpu 和内存,建议内存 32G 走起,cpu 也别太烂

编译准备界面

编译成功之后,会有下面的输出

整机编译成功

4. 刷机

自己编译的 UserDebug 固件用来 Debug 是非常方便的,不管是用来 Debug Framework 还是 App

编译好之后下面开始刷机,以我的测试机器 Pixel 3 XL 为例,依次执行下面的命令

adb reboot fastboot

# 等待手机进入 fastboot 界面之后
fastboot flashall -w

# 刷机完成之后,执行 fastboot reboot 长期系统即可
fastboot reboot

Guess you like

Origin blog.csdn.net/iffy1/article/details/129052061