Ubuntu 18.04编译AOSP源码

总结一下我从Ubuntu 18.04下编译成功AOSP的过程,以及遇到的坑

我的电脑配置:

OS: Ubuntu 18.04 bionic

Kernel: x86_64 Linux 4.18.0-17-generic

CPU: Intel Core i5-8250U(4核8线程)

RAM: 8G

步骤1:

某些步骤可以先跳过,后面再设置

如果你的电脑也是8G内存(16G可以跳过这个步骤),就需要设置交换空间,否则到后面会出现内存不足的情况,参考:如何在Ubuntu 16.04上增加Swap分区

步骤2:

建议替换国内源:

sudo apt update vim #先安装vim

sudo apt install vim -y

sudo vim /etc/apt/sources.list #或者sudo gedit /etc/apt/sources.list

用#注释所有内容,粘贴以下内容:

 

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
 
sudo apt update
 

依次安装

sudo apt update

sudo apt install git -y

sudo apt install repo -y

sudo apt install openjdk-8-jdk -y #请输入java -version确认安装正确

步骤3:

清华大学开源软件镜像站下载初始化包(aosp-latest.tar

tar xf aosp-latest.tar #下载完成后解压

cd aosp-latest/aosp

ls -a #应该只有一个.repo隐藏目录

repo sync #检出目录树

可能需要一个小时左右,完成后应该会显示:Syncing work tree:100%(xxx/xxx),done.

ls -a #如下

 

 

步骤4:

安装各种依赖:

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib -y
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
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 -y
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 install make make-guile -y
sudo apt-get install tofrodos -y
sudo apt-get install python-markdown libxml2-utils xsltproc zlib1g-dev:i386

这时可能无法安装libesd0-dev

sudo vim /etc/apt/sources.list

在最后添加:

deb http://kr.archive.ubuntu.com/ubuntu/ xenial main universe
deb-src http://kr.archive.ubuntu.com/ubuntu/ xenial main universe
sudo apt update

sudo apt install libesd0-dev

最后一步:

#export LC_ALL=C添加到~/.bashrc

echo "export LC_ALL=C" >> ~/.bashrc

source ~/.bashrc

链接文件

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

重新打开终端

cd到aosp根目录

ls -a #应该是这样

source build/envsetup.sh

#lunch 不带参数运行,会显示各个版本和对应序号

lunch aosp_arm64-eng #也可以lunch后手动选择

#CPU 4核8线程应输入-j8,2核4线程-j4:

make -j8 #开始编译

不出意外,若干小时后应该就会编译成功

 

启动模拟器

 

如果编译完成后关闭了终端窗口,则需要用以下方式启动模拟器

source build/envsetup.sh

lunch 2 #这里填序号aosp_arm64-eng为2

emulator

我用i5-8250U编译完成 用了8小时38分(下午3点多开始编译,00点完成)

看来真的该换电脑了 - -!

 

posted @ 2019-03-21 15:39  ptr2314  阅读(2663)  评论(0编辑  收藏  举报