總結一下我從Ubuntu 18.04下編譯成功AOSP的過程,以及遇到的坑java
個人電腦配置:python
OS: Ubuntu 18.04 bioniclinux
Kernel: x86_64 Linux 4.18.0-17-genericgit
CPU: Intel Core i5-8250U(4核8線程)ubuntu
RAM: 8Gvim
步驟1:bash
某些步驟能夠先跳過,後面再設置markdown
若是你的電腦也是8G內存(16G能夠跳過這個步驟),就須要設置交換空間,不然到後面會出現內存不足的狀況,參考:如何在Ubuntu 16.04上增長Swap分區curl
步驟2:ionic
建議替換國內源:
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 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點完成)
看來真的該換電腦了 - -!