Ubuntu 20.04 配置Android编译环境

Ubuntu 20.04 LTS

Posted by LXG on November 6, 2020

搭建构建环境-AOSP

电脑硬件配置

最低要求:RAM-16G ROM:500G

推荐硬件配置

系统安装

  1. BIOS进入启动设置打开CSM Support(兼容性支持模块)
  2. U盘安装 ubuntu 20.04 LTS (注意安装无线网驱动)

系统配置

安装有线网驱动

有线网驱动下载地址

sudo apt-get install –reinstall linux-headers-$(uname -r) linux-headers-generic build-essential dkms sudo ./autorun.sh

挂载机械硬盘


1. sudo fdisk -l                                // 查看已经挂载的硬盘
2. sudo unmount /dev/sdb2                       // 卸载硬盘
3. sudo mkfs.ext4 /dev/sdb2                     // 格式化硬盘为ext4格式
4. sudo blkid                                   // 查看硬盘的UUID
5. mkdir hardware                               // 创建要挂载的目录
6. sudo mount /dev/sdb2                         // 将硬盘挂载到指定目录下
7. sudo gedit /etc/fstab                        // 开机自动挂载硬盘

增加软件更新镜像源

  1. sudo vim /etc/apt/sources.list
  2. sudo apt-get update
  3. sudo apt-get upgrade

# for aosp
deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main universe

# aliyun
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

安装支持包

安装需要的软件包 (Ubuntu 18.04)

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

安装需要的软件包 (Ubuntu 20.04)

sudo apt install openssh-server screen python git openjdk-8-jdk android-tools-adb bc bison build-essential curl flex g++-multilib gcc-multilib gnupg gperf imagemagick lib32ncurses-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc yasm zip zlib1g-dev libtinfo5 libncurses5

MTK qcom 支持包

部分包不一定能安装成功


sudo apt-get install vim samba expect sshpass openssh-server openssh-client
sudo apt-get install libssl-dev

sudo apt-get install libtool openssh-server samba git-core g++ make diffstat texi2html texinfo subversion gawk chrpath libsm6 libxrender1 libfontconfig1 lzop libxml-sax-expat-perl python3-xlrd python-xlrd-docs tofrodos xsltproc

sudo apt-get install gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev lib32z1 lib32ncurses5 x11proto-core-dev libx11-dev libreadline-gplv2-dev lib32z1-dev libgl1-mesa-dev g++-multilib binutils-mingw-w64 tofrodos python-markdown libxml2-utils xsltproc genisoimage python-imaging bc liblz4-tool

sudo apt-get install openjdk-8-jdk openjdk-8-jre openjdk-8-doc

//MTK 平台 Perl依赖安装
sudo cpan - XML::Simple
sudo cpan - Switch

下载AOSP源码

清华大学开源软件镜像站


curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-11.0.0_r8
repo sync

编译

支持旧版本-AOSP

对于 Android 5.0 版(Lollipop 或 L)到 Android 8.0 版(Oreo 或 O),请考虑使用随附的 Dockerfile,以简化所有必需软件包的安装。