在新安裝的Ubuntu上(版本20.04LTS),完成搭建Android源碼編譯環(huán)境步驟如下。
順帶說一句,當(dāng)前用的比較多的Ubuntu是18.04和20.04,在實(shí)際項(xiàng)目中一直在用,可用性和穩(wěn)定性都沒問題。
最新的Ubuntu22.04版本,系統(tǒng)默認(rèn)的二進(jìn)制庫(kù)變化比較大,編譯Android源碼有問題(實(shí)測(cè)過,沒細(xì)研究),不如上述2個(gè)版本使用起來順暢。
1. 安裝ssh server(可選)
為了方便使用遠(yuǎn)程終端進(jìn)行操作和文件傳輸,通過ssh協(xié)議遠(yuǎn)程使用命令行終端或者winscp等軟件進(jìn)行文件傳輸。Ubuntu默認(rèn)沒有安裝server端軟件。
注意:
1)安裝后自動(dòng)運(yùn)行,無需重啟。
2)用當(dāng)前登錄的系統(tǒng)用戶就可以通過ssh遠(yuǎn)程連接。
3)用戶必須由密碼才可以遠(yuǎn)程連接。
$ sudo apt install openssh-server
2. 安裝net-tools (可選)
安裝這個(gè)軟件包是為了使用ifconfig命令,查看ip等信息。
$ sudo apt install net-tools
3. 安裝git
這個(gè)都知道是干啥用的
$ sudo apt install git
安裝完成后,需要用如下命令進(jìn)行配置,分別替換為自己的名字和郵箱(不強(qiáng)制真實(shí)郵箱)
git config --global user.name YourName
git config --global user.email you@example.com
查看當(dāng)前git配置:
$ git config -l
user.name=your_name
user.email=your_email
url.ssh://name@url:port/.insteadof=gerrit:
url.ssh://name@url:port/.pushinsteadof=gerrit:
core.repositoryformatversion=0
core.filemode=true
filter.lfs.smudge=git-lfs smudge --skip -- %f
remote.qs.url=gerrit:/platform/sdk
remote.qs.review=gerrit_url
remote.qs.projectname=platform/sdk
remote.qs.fetch=+refs/heads/*:refs/remotes/qs/*
For Ubuntu 22.02 with ssh rsa refer to: Ubuntu 22.04系統(tǒng)git/repo/github/codeup等 無法用ssh方式下載代碼問題修復(fù)
4. 配置python
Android源碼編譯中使用默認(rèn)的python命令,在Ubuntu20.04中安裝了python3,需要?jiǎng)?chuàng)建一個(gè)連接,讓編譯腳本可以找到python解釋器,否則會(huì)報(bào)錯(cuò)。
有2種方法(二選一):
1)直接創(chuàng)建一個(gè)鏈接,指向python3
$ sudo ln -s /usr/bin/python3 /usr/bin/python
2)通過update-alternatives工具管理多個(gè)版本軟件(參考鏈接)
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 300
3)低版本的Android以來Python 2
需要安裝python2.7版本,完成后參照上面的方法設(shè)置鏈接/usr/bin/python,進(jìn)行后續(xù)編譯。
$ sudo apt install python2.7
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 500
5. 安裝編譯所需依賴庫(kù)
這是Ubuntu18.04及后續(xù)版本所需的依賴庫(kù),如果是之前更老的Ubuntu版本,依賴庫(kù)會(huì)有差異。
5.1 Google原生Android源碼編譯依賴庫(kù)
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
5.2 高通Qualcom源碼依賴庫(kù)
sudo apt-get install libx11-dev libreadline-dev libgl1-mesa-dev g++-multilib git flex bison gperf build-essential libncurses-dev tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev dpkg-dev libsdl1.2-dev gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libgl1-mesa-dev libxml2-utils xsltproc unzip m4 lib32z1-dev ccache libssl-dev
5.3 使用docker運(yùn)行Ubuntu 20.04,需要單獨(dú)安裝的軟件
sudo apt install rsync cpio
5.4 Ubuntu 22.04依賴庫(kù)
需要單獨(dú)安裝openssl庫(kù),默認(rèn)情況下編譯時(shí)提示如下錯(cuò)誤:
kernel/msm-5.4/scripts/extract-cert.c:21:10: fatal error: 'openssl/bio.h' file not found
#include <openssl/bio.h>
^~~~~~~~~~~~~~~
1 error generated.
$ wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
$ tar -xf openssl-3.0.7.tar.gz
$ cd openssl-3.0.7
# 把header安裝到/usr/include,.so安裝到/usr/lib64,如果指定其他路徑,需要配置ld.so.conf
$ ./config --prefix=/usr --openssldir=/usr shared zlib
Configuring OpenSSL version 3.0.7 for target linux-x86_64
Using os-specific seed configuration
Created configdata.pm
Running configdata.pm
Created Makefile.in
Created Makefile
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub <https://github.com/openssl/openssl/issues> ***
*** and include the output from the following command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
*** (If you are new to OpenSSL, you might want to consult the ***
*** 'Troubleshooting' section in the INSTALL.md file first) ***
*** ***
**********************************************************************
$ make -j16
$ sudo make install
openssl安裝完成后,頭文件所在目錄:/usr/include/openssl,庫(kù)文件所在目錄:/usr/lib64/
6. 下載Android源碼
這里先簡(jiǎn)要說明一下。如果需要,再單獨(dú)說明一下通過google官方渠道或者國(guó)內(nèi)鏡像進(jìn)行下載的操作步驟。
Android源碼比較多,在公司內(nèi)網(wǎng)下載,需要20分鐘左右的時(shí)間;如果是公網(wǎng),主要看網(wǎng)速及穩(wěn)定性,幾個(gè)小時(shí)、十幾個(gè)小時(shí)不等。
$ mkdir -p ~/source/android
$ cd ~/source/android
# 以下是下載repo和驗(yàn)證過程
$ export REPO=$(mktemp /tmp/repo.1112222333)
$ curl -o ${REPO} https://storage.googleapis.com/git-repo-downloads/repo
$ gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65
$ curl -s https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ${REPO} && install -m 755 ${REPO} /usr/local/bin/repo
# 初始化repo
$ repo init -u https://android.googlesource.com/platform/manifest
# 更新代碼
# 可用-j參數(shù)指定線程數(shù),不能超過服務(wù)器端的配置上限
$ repo sync
7. 安裝所需開發(fā)工具軟件
根據(jù)開發(fā)需要和個(gè)人習(xí)慣安裝一些工具軟件,只列出一些通用的,默認(rèn)系統(tǒng)沒有安裝的軟件:
1)vim-gtk
帶UI的vim,在圖形界面下使用方便一點(diǎn),不用專門開一個(gè)終端。
$ sudo apt install vim-gtk
2)vs code
主頁:https://code.visualstudio.com/
Ubuntu上dep安裝包下載連接:https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64
我下載的版本是:code_1.75.0-1675266613_amd64.deb
使用dpkg命令安裝:
sudo dpkg -i code_1.75.0-1675266613_amd64.deb
安裝后選裝需要的extension或者通過登錄微軟賬號(hào)自動(dòng)同步vs code配置。
3)google chrome (或者chromium)
(1) install chrome browser by wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
(2) install chrome browser by ppa
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c ‘echo “deb http://dl.google.com/linux/chrome/deb/ stable main” >> /etc/apt/sources.list.d/google-chrome.list’
sudo apt update
sudo apt install google-chrome
(3) install chromium browser (chromium is open source and can not login google account or sync data)
sudo apt install chromium-browser
4)搜狗輸入法,sogou pinyin
(1) download: https://shurufa.sogou.com/linux
(2) Ubuntu安裝搜狗輸入法
sudo apt-get install fcitx libgsettings-qt1 libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2
sudo apt -f install
sudo apt purge ibus
設(shè)置fcitx開機(jī)自啟動(dòng)
在終端執(zhí)行sudo cp /usr/share/applications/fcitx.desktop /etc/xdg/autostart/
5)android studio, sdk, ndk
(1) android studio
https://developer.android.google.cn/studio/
https://developer.android.google.cn/studio/preview
(2) ndk
https://developer.android.google.cn/ndk/downloads
6)WPS
https://linux.wps.cn/
https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11698/wps-office_11.1.0.11698_amd64.deb
sudo dpkg -i wps-office_11.1.0.11698_amd64.deb
7)WindTerm(或者terminator)
WindTerm download
https://master.dl.sourceforge.net/project/windterm.mirror/2.5.0/WindTerm_2.5.0_Linux_Portable_x86_64.tar.gz?viasf=1
sudo apt install terminator
8)docker
9)Clion
(1) Clion
https://www.jetbrains.com.cn/en-us/clion/download/#section=linux
(2) IntelliJ IDEA Ultimate
https://www.jetbrains.com.cn/idea/download/?section=linux
(3) goland
https://www.jetbrains.com.cn/en-us/go/download/#section=linux
(4) pycharm
https://www.jetbrains.com.cn/en-us/pycharm/download/?section=linux
10)minicom
sudo apt install minicom
minicom安裝、配置和使用
dingtalk:
https://page.dingtalk.com/wow/z/dingtalk/simple/ddhomedownload#/文章來源:http://www.zghlxwxcb.cn/news/detail-456813.html
lvm
sudo apt install lvm2文章來源地址http://www.zghlxwxcb.cn/news/detail-456813.html
到了這里,關(guān)于從頭搭建Android源碼編譯環(huán)境(Ubuntu 18.04 / 20.04 / 22.04)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!