1. 安裝軟件
1.1. 安裝 git
A.git官網下載:https://git-scm.com/downloads/
安裝git到如下路徑
C:/Program Files/Git
B.圖形化工具:https://tortoisegit.org/
1.2. 安裝 Python
python官網下載:https://www.python.org/downloads/
安裝python到如下路徑
C:/Program Files/python
2. 下載源碼
2.1. 克隆源代碼倉庫
在 E 盤創建如下文件夾(沒有E盤也可以)
mkdir E:/android_source/
打開 Git Bash,用下面命令下載代碼倉庫
cd E:/android_source/
git clone https://android.googlesource.com/platform/manifest.git
如果無法訪問google,使用清華源
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
2.2. 切換到Android Q對應的版本
先查詢想要下載的android Q版本
cd manifest git branch -a
當前 android q 版本如下,使用最新的 android-q-preview-2.5
git checkout android-q-preview-2.5
3. 執行Python腳本進行源代碼下載
在E盤創建android_q的源碼目錄
cd E:/android_source/ mkdir android_q cd android_q
復制下面的代碼保存到本地,命令為download.py
import xml.dom.minidom import os from subprocess import call # 1. 修改為源碼要保存的路徑 rootdir = "E:/android_source/android_q" # 2. 設置 git 安裝的路徑 git = "C:/Program Files/Git/bin/git.exe" # 3. 修改為第一步中 manifest 中 default.xml 保存的路徑 dom = xml.dom.minidom.parse("E:/android_source/manifest/default.xml") root = dom.documentElement prefix = git + " clone https://android.googlesource.com/" # 4. 沒有梯子使用清華源下載 # prefix = git + " clone https://aosp.tuna.tsinghua.edu.cn/" suffix = ".git" if not os.path.exists(rootdir): os.mkdir(rootdir) for node in root.getElementsByTagName("project"): os.chdir(rootdir) d = node.getAttribute("path") last = d.rfind("/") if last != -1: d = rootdir + "/" + d[:last] if not os.path.exists(d): os.makedirs(d) os.chdir(d) cmd = prefix + node.getAttribute("name") + suffix call(cmd)
同步代碼,執行下面的命令后坐等代碼下完即可
python download.py
MAC 下源碼流程、編譯和刷機教程傳送門:https://www.cnblogs.com/larack/p/9722954.html