總結一下我從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 步 ...
總結一下我從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:
cd
/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點完成)
看來真的該換電腦了 - -!