Android 11 源码编译

最近用Ubuntu20.04 编译了Android 11的代码,编译过程中我也遇到过许多坑,这是我整理的一个没有坑可以编译成功的流程,希望看到的人少趟坑。

准备环境

  • Ubuntu 20.04 系统环境,可以用物理机,也可以用虚拟机
  • 内存16G、硬盘300G,这是最低配置

配置Ubuntu 国内源

因为某种原因,我们可能不能直接用Ubuntu系统自带的源下载软件,所以需要将源换为国内的

  1. 备份以前的源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. gedit 打开源列表文件
sudo gedit /etc/apt/sources.list
  1. 将国内清华源复制到源列表中,最后两条源需要保留,在后面下载软件dpkg-dev时需要用到,这个源仅适用Ubuntu20.04系统。
# qing hua
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main universe
  1. 保存后,更新源和系统软件
sudo apt-get update
sudo apt-get upgrade

下载Android 源码

  1. 下载git,配置环境变量
#下载git,配置git账号
sudo apt-get install git
git config --global user.email "[email protected]"
git config --global user.name "xiake"

#配置PATH环境变量
mkdir ~/bin
echo "PATH=~/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
  1. 安装curl
sudo apt-get install curl

3.下载repo工具

PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
  1. 下载aosp 压缩包(目前时86G左右),然后解压后进行同步(解压后可以将压缩包删除掉,后面编译还需要大量空间),同步后可以得到源码的目录,要是想要本地代码和线上代码保持同步可以定期进行同步
# 下载压缩包,最好在晚上下载,有时超时次数多了,需要手动再次执行此命令
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar

# 解压
tar xf aosp-latest.tar

#切换到 aosp目录下面
cd aosp

#同步目录
repo sync

编译源码

  1. 准备编译环境
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev

2.执行编译命令,lscpu可以查看cpu的详细信息,线程为cpu的两倍,这时候考验电脑配置的时候到了,配置差点的线程就开少一点,不然电脑吃不消。最后界面出现绿色字体successfully 即表示编译成功。

source build/envsetup.sh
lunch 2
time make -j8

你可能感兴趣的:(Android 11 源码编译)