repo是什么?
官方的定義:Repo是谷歌用python腳本寫的呼叫git的一個腳本,可以實作管理多個git庫,
Android的源代碼使用Repo 命令列工具來管理多個git倉庫,大概有百多個,要想克隆和管理百多個 Git 倉庫,不是一件簡單的事情,Repo 命令列工具對 Git 部分命令封裝,將百多個 Git 庫有效的進行組織,
Linux下安裝Repo
linux下的Repo安裝,稍簡單些,
$ curl http://android.git.kernel.org/repo >~/bin/repo $ chmod a+x ~/bin/repo $ export PATH=$PATH:~/bin
Windows下Repo安裝
repo原本是谷歌搞的一個方便下載AOSP的工具基于git,但由于種種原因不能直接在Windows上使用,但好在有windows版本以用,Repo的Windows版本:
https://github.com/esrlabs/git-repo
鏈接地址:GitHub - esrlabs/git-repo: repo - The multiple repository tool (also works on MS Windows!)
如果按照網上搜到的方法,安裝會遇到不少問題,這里介紹下一個一定能成功的方法,
網上的方法:
一、環境準備:
1.安裝Git for Windows,360軟體管家里可以直接搜到64位的git for windows,
2.安裝Python 2.7,360軟體管家里可以直接搜到Python 2.7,
3.配置系統環境變數,Git 和python加入到環境變數,
二、安裝Repo:
1.在任意處打開 Git Bash 命令列,注意必須是Git的git bash命令列,
mkdir ~/bin
curl https://raw.githubusercontent.com/esrlabs/git-repo/stable/repo > ~/bin/repo
curl https://raw.githubusercontent.com/esrlabs/git-repo/stable/repo.cmd > ~/bin/repo.cmd
chmod a+rx ~/bin/repo
2.下載Android的AOSP源代碼,新建aosp目錄,cd aosp進入目錄,
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r25 --repo-url=https://github.com/esrlabs/git-repo.git
3.上一步repo init執行成功后,執行repo sync開始正式下載源代碼,
遇到的問題:
Could not resolve host: raw.githubusercontent.com
這個地址可能被墻了,即使手動改hosts檔案也不一定管用,
一定能夠成功的辦法
1.打開github上的git-repo倉庫,把倉庫代碼clone或者zip包下載下來,
https://github.com/esrlabs/git-repo
把repo和repo.cmd復制一份放置在C:\Users\Administrator\bin
注意環境不同可能不一定是這個路徑,這個位置是前幾步mkdir ~/bin創建的目錄,可以在git bash下進入到bin目錄通過pwd命令查看路徑,
2.在需要下載android原始碼的aosp目錄下,新建個.repo檔案夾,在.repo檔案夾下再建個repo檔案夾,把下載的git-repo倉庫內的原始碼放在repo檔案夾下,

或者省略這步,直接把下載的 git-repo倉庫放到git bash的~/bin下應該也可以,
3.下載Android 原始碼,
清華大學開源軟體鏡像站
https://mirrors.tuna.tsinghua.edu.cn/
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r25
最后, repo sync命令,即開始最終的代碼下載,
LineageOS 14.1下載
Lineage OS 系統介紹
大伙還記得 CyanogenMod 嗎?給安卓手機刷過機的用戶基本都知道 CyanogenMod 的ROM,其實國內很多第三方的ROM都是基于 CyanogenMod 的ROM修改優化的,最近Cyanogen 團隊重新以Lineage OS的新專案來出發,繼續為眾多安卓手機開發完備獨居特色的作業系統,
該系統ROM相當的純凈,也就幾百兆大小,運行自然也流暢,可以拿一些老舊手機刷機來練練手,對LineageOS刷機感興趣的可關注論壇,有詳細的刷機教程:LineageOS中文論壇 - Powered by Discuz!
LineageOS 14.1基于android7.1,
下載程序:
新建檔案夾lineageOS,在lineageOS檔案夾內新建.repo檔案夾,在.repo檔案夾內,拷貝進去repo那個代碼倉庫,接下來:
repo init -u git://github.com/lineageos/android.git -b cm-14.1
repo sync -c
即可下載,為了加快下載速度,可把 .repo里面的manifests檔案夾修改里面的default.xml檔案,修改如下,使用國內鏡像https://github.com.cnpmjs.org/替換github.com
<remote name="github"
fetch="https://github.com.cnpmjs.org/"
review="https://github.com.cnpmjs.org/" />
https://android.googlesource.com 鏡像使用如下替換:
<remote name="aosp"
fetch="http://aosp.tuna.tsinghua.edu.cn/android/"
review="http://aosp.tuna.tsinghua.edu.cn/android/"
revision="refs/tags/android-7.1.2_r36" />
repo相關知識介紹
.repo/manifests是個被git管理的倉庫,這里放的是所有的manifest檔案(*.xml),
因為被git管理,固然有分支,-b可以切換到你想要的分支然后再下載相關的xml檔案,當然具體下載那個xml還要看-m引數了,所以如果你僅僅指定-b而沒有-m的話,就是下載-b指定分支下的default.xml檔案,
如果不指定-b引數,那么會默認使用master分支,
repo sync [project-list]
下載最新本地作業檔案,更新成功,這本地檔案和repository 中的代碼是一樣的, 可以指定需要更新的project , 如果不指定任何引數,會同步整個所有的專案,
如果是第一次運行 repo sync , 則這個命令相當于 git clone ,會把 repository 中的所有內容都拷貝到本地,
如果不是第一次運行 repo sync , 則相當于 git remote update ; git rebase origin/branch . repo sync 會更新 .repo 下面的檔案,
如果在merge 的程序中出現沖突, 這需要手動運行 git rebase --continue
repo默認會同步git庫的所有遠程分支的代碼,但實際開發程序中,用到的分支是有限的,使用sync的-c引數,可以只下載manifest中設定的分支,這會節省代碼下載時間以及本地的磁盤空間,
在repo init的時候,會從遠程下載manifests和repo這兩個git庫,默認情況下這兩個git庫的地址都是寫死在repo這個python腳本里面的,
對于AOSP而言,這兩個git庫的地址顯然是google提供的, 但由于google訪問受限的緣故,會導致init時,無法下載manifests和repo,這時候,可以使用init的-u和–repo-url引數,自定義這兩個庫的地址,輔以–no-repo-verify來繞過代碼檢查,最后,想要快速下載android的源代碼的話,可以試下這個操作,
github的國內訪問太慢了,使用國內鏡像源吧,記住這個地址github的國內鏡像源:
https://github.com.cnpmjs.org/
在本地得到.repo檔案夾,進去會看到manifests檔案夾,修改里面的default.xml檔案 ,
把里面的fetch="https://github.com/",review="https://github.com/"替換為:"https://github.com.cnpmjs.org/"
<remote name="github"
fetch="https://github.com.cnpmjs.org/"
review="https://github.com.cnpmjs.org/" />
參考
- git-repo
- Microsoft Windows Details
- windows環境下repo下載Android源代碼
- window7下配置下載android原始碼環境,安裝Repo
- Windows安裝repo的真正解決方案_倚竹幽篁-CSDN博客
- Repo介紹_nwpushuai的博客-CSDN博客_repo
- Windows 平臺repo下載及使用repo下載代碼_xidiankk的專欄-CSDN博客_windows 使用repo
- Windows安裝repo的真正解決方案,看完直接跪服_m0_61418377的博客-CSDN博客
- windows 10 git repo下載Android原始碼更換為國內源的方法_ok138ok的博客-CSDN博客
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307342.html
標籤:其他
