一.源碼獲取途徑
? ? ? ? Android源碼獲取途徑大致分為三種:
1.芯片廠商
????????谷歌發(fā)布新版本源碼之后,芯片廠商會(huì)根據(jù)自己的芯片特性進(jìn)行適配。如高通、瑞芯微等廠商。
2.方案公司
? ? ? ? 方案公司從芯片廠商獲得已適配版本,并在其基礎(chǔ)上做一些定制化的修改。
3.谷歌網(wǎng)站
? ? ? ?前兩種途徑需要適配時(shí)間,周期較長(zhǎng)。如果想更早的獲取到 Android 源碼,可以直接下載谷歌官方的源碼。
? ? ? ?本文以第3種途徑為例講解Android源碼的下載方法。
二.安裝repo工具
2.1 什么是repo
?????????Repo是我們?cè)贕it之上構(gòu)建的一個(gè)工具。Repo幫助我們管理許多Git存儲(chǔ)庫。Repo并不是要取代Git,只是為了在Android環(huán)境下更容易使用Git。repo命令是一個(gè)可執(zhí)行的Python腳本,您可以將其放在路徑中的任何位置。
2.2 下載repo
2.2.1 創(chuàng)建repo保存目錄
? ? ? ? 例如,保存在~/bin目錄中:
mkdir ~/bin
2.2.2 下載?
?1.從谷歌網(wǎng)站下載
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
? ? ? ? 由于墻的原因,可能會(huì)出現(xiàn)如下錯(cuò)誤:
curl: (7) Failed to connect to storage.googleapis.com port 443: Connection refused
2.使用國(guó)內(nèi)代理服務(wù)器下載
curl -sSL 'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
3.直接從國(guó)內(nèi)mirror網(wǎng)站下載
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
2.2.3 環(huán)境變量配置
1.讓repo腳本具有可執(zhí)行權(quán)限
chmod a+x ~/bin/repo
2.repo路徑添加到PATH變量中
(1)臨時(shí)生效
export PATH=~/bin/:$PATH
(2)永久生效
? ? ? ? 在~/.bashrc文件末尾添加以下語句:
export PATH=~/bin/:$PATH
? ? ? ? 然后執(zhí)行以下命令即可生效。
source ~/.bashrc
? ? ? ? 或者,重新打開一個(gè)終端。
2.2.4 更新
???????repo的運(yùn)行過程中會(huì)嘗試訪問官方的git源更新自己,由于墻的原因,可能會(huì)導(dǎo)致更新失敗。因此,建議指定國(guó)內(nèi)的mirror源進(jìn)行更新。
????????可以將如下內(nèi)容復(fù)制到你的~/.bashrc里。?
export REPO_URL='http://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
? ? ? ? 注意:如果此處使用“https”協(xié)議,可能會(huì)報(bào)如下錯(cuò)誤:
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
fatal: Cannot get https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/clone.bundle
fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
fatal: double check your --repo-rev setting.
fatal: cloning the git-repo repository failed, will remove '.repo/repo'
? ? ? ? 將https協(xié)議改為http協(xié)議,即可解決此問題。
三. Android源碼下載
3.1 初始化倉庫
????????下載 repo 倉庫,并指定 android 版本:
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-4.0.1_r1
3.2 同步源碼樹
? ? ? ? 下載Android源碼。默認(rèn)4線程下載,也可通過-j選項(xiàng)指定線程數(shù)。文章來源:http://www.zghlxwxcb.cn/news/detail-858430.html
repo sync
? ? ? ? 若出現(xiàn)同步錯(cuò)誤,可嘗試使用以下指令:文章來源地址http://www.zghlxwxcb.cn/news/detail-858430.html
repo sync -j1 --fail-fast
到了這里,關(guān)于Android源碼下載方法詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!