Skip to content

Instantly share code, notes, and snippets.

@h1code2
Last active August 7, 2021 15:49
Show Gist options
  • Save h1code2/67323f57c0b64cfa67d697f84baf7f8c to your computer and use it in GitHub Desktop.
Save h1code2/67323f57c0b64cfa67d697f84baf7f8c to your computer and use it in GitHub Desktop.
Android 11 系统编译采坑 #android #编译 #源码 #repo #shell #git

Android 11 系统编译采坑

1.编译尝试使用 docker 环境

docker pull ubuntu:18.04

2.安装 Repo

mkdir ~/bin
PATH=~/bin:$PATH

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

如果想使用旧版 Repo 启动器, 请使用一下命令:

curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
chmod a+x ~/bin/repo

3.Ubuntu18.04 基本环境配置

apt update
apt install python python3 curl git -y

sudo apt-get install openjdk-8-jdk
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

4.下载源码:

将 Google 的地址 https://android.googlesource.com/kernel/manifest 替换清华的地址 https://aosp.tuna.tsinghua.edu.cn/platform/manifest 下载速度更快 加 --depth 1 控制git深度可以极大节省硬盘空间。最终 .repo 目录 21G 左右

git config --global user.email "h1code2@163.com"
git config --global user.name "h1code2"

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
repo init --depth 1 -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-11.0.0_r1 
repo sync -j20

5.专有硬件库下载

Android 11 上不加硬件库会导致刷机后无限重启,但之前 pixel 1 时没有硬件库也能启动,这里踩了一个坑。 记得匹配好对应的 BUILD_ID 和代码, 查看 build/core/build_id.mk 文件,我的 BUILD_ID=RP1A.200720.009,pixel 3 的代号是 blueline,所以对应的下载地址是:https://developers.google.cn/android/drivers?hl=zh-cn#bluelinerp1a.200720.009, 将两个文件下载到源码根目录,然后执行,会自动生成 vendor 文件

~/code/android11$ tar zxvf google_devices-blueline-rp1a.200720.009-6cd41940.tgz
~/code/android11$ tar zxvf qcom-blueline-rp1a.200720.009-f772c38c.tgz
~/code/android11$ ./extract-google_devices-blueline.sh
~/code/android11$ ./extract-qcom-blueline.sh

6.开始编译

编译 Android 系统镜像(Android 10 和 Android 11 ): https://zwc365.com/2020/09/13/ubuntu18-build-android10-11

使用如下参数设定内存限制:

export _JAVA_OPTIONS="-Xmx10g"

将 swap 设置为 16G :

sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1G count=16
sudo mkswap /swapfile
sudo swapon /swapfile


OPM4.171019.021.P1	android-8.1.0_r38	Oreo	Pixel、Pixel XL
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx9216m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment