篇头
最近写文章,反复多次折腾AOSP代码,因通过网络repo sync aosp代码,能一次顺利下载的概率很低,以前就经常遇到,但从未总结,导致自己也要回头检索方法,所以觉得可以总结一下,涉及下载最新、各分支AOSP代码的方法,以及如何处理所遇到的同步错误及其解决方法,现分享给大家~
一、下载源码包及repo
- 包含 aosp-latest.tar 和 repo程序
- 下载TAG包,可以节约很多时间
(1)下载初始化包,约 60GB 数据,建议复制地址,直接使用迅雷下载
szhou@bc-R01:~/works$curl -OC - https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar (2)解压
szhou@bc-R01:~/works$ mkdir aosp
szhou@bc-R01:~/works$ tar -xvf aosp-latest.tar -C aosp/(3)下载repo
szhou@bc-R01:~/works/aosp$ mkdir bin
szhou@bc-R01:~/works/aosp$ curl https://storage.googleapis.com/git-repo-downloads/repo > bin/reposzhou@bc-R01:~/works/aosp$ curl https://storage.googleapis.com/git-repo-downloads/repo > bin/repo % Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
100 48143 100 48143 0 0 48336 0 --:--:-- --:--:-- --:--:-- 48287(4)部署repo
szhou@bc-R01:~/works/aosp$ chmod a+x bin/repo
szhou@bc-R01:~/works/aosp$ sudo cp bin/repo /usr/bin/
[sudo] password for szhou:
szhou@bc-R01:~/works/aosp$
二、代码更新
2.1 目录情况
- 解压后,在aosp目录下,只有.repo目录,还需要同步代码和检出代码
szhou@bc-R01:~/works/aosp/aosp$ ls -al
total 12
drwxr-xr-x 3 szhou szhou 4096 10月 1 00:00 .
drwxrwxr-x 4 szhou szhou 4096 12月 24 00:39 ..
drwxr-xr-x 7 szhou szhou 4096 10月 1 00:45 .repo
szhou@bc-R01:~/works/aosp/aosp$
2.2 更新.repo/repo 程序
- 第一次更新AOSP源码,记得执行此步骤,可以减少后续repo sync错误
szhou@bc-R01:~/works/aosp/aosp$ ls -al
total 12
drwxr-xr-x 3 szhou szhou 4096 10月 1 00:00 .
drwxrwxr-x 4 szhou szhou 4096 12月 24 00:39 ..
drwxr-xr-x 7 szhou szhou 4096 10月 1 00:45 .repo
szhou@bc-R01:~/works/aosp/aosp$ cd .repo/repo/
szhou@bc-R01:~/works/aosp/aosp/.repo/repo$ git pull
remote: Enumerating objects: 263, done.
remote: Counting objects: 100% (191/191), done.
remote: Compressing objects: 100% (138/138), done.
remote: Total 263 (delta 152), reused 55 (delta 53), pack-reused 72
Receiving objects: 100% (263/263), 264.03 KiB | 11.00 MiB/s, done.
Resolving deltas: 100% (158/158), completed with 12 local objects.
From https://mirrors.tuna.tsinghua.edu.cn/git/git-repo1e9f7b9..4c80921 stable -> origin/stable83c66ec..b1d1ece main -> origin/main* [new tag] v2.40 -> v2.40* [new tag] v2.38 -> v2.38* [new tag] v2.39 -> v2.39
Updating 1e9f7b9..4c80921
Fast-forward.github/workflows/close-pull-request.yml | 22 +++.github/workflows/test-ci.yml | 5 +-color.py | 4 +-
…… 略……tests/test_wrapper.py | 2 +-tox.ini | 7 +-60 files changed, 3043 insertions(+), 2389 deletions(-)create mode 100644 .github/workflows/close-pull-request.ymlcreate mode 100644 git_trace2_event_log_base.py
szhou@bc-R01:~/works/aosp/aosp/.repo/repo$
操作如下图所示
2.3 查看可用分支
- 可见13的最新版本为:remotes/origin/android-13.0.0_r82, 即r82版本
- 通过修改grep后的过滤条件,也可以查看其他版本情况
szhou@bc-R01:~/works/aosp/aosp/.repo/manifests.git$ git branch -av | grep android-13remotes/origin/android-13.0.0_r1 0f42cde46 Manifest for Android 13.0.0 Release 1 (TP1A.220624.014)remotes/origin/android-13.0.0_r10 e64b26003 Manifest for Android 13.0.0 Release 10
…… 略 ……remotes/origin/android-13.0.0_r80 4ca496b8e Manifest for Android 13.0.0 Release 80remotes/origin/android-13.0.0_r81 259db423b Manifest for Android 13.0.0 Release 81remotes/origin/android-13.0.0_r82 ed487956f Manifest for Android 13.0.0 Release 82remotes/origin/android-13.0.0_r9 0bac787fd Manifest for Android 13.0.0 Release 9
szhou@bc-R01:~/works/aosp/aosp/.repo/manifests.git$
操作如下图所示
2.4 配置Python
- 当前AOSP代码需要Python 3.6以上版本,才可正常使用
2.4.1 Python版本导致的repo sync错误
szhou@bc-R01:~/works/aosp/aosp/.repo/manifests.git$ cd ../..
szhou@bc-R01:~/works/aosp/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r82File "/usr/bin/repo", line 51def print(self, *args, **kwargs):^
SyntaxError: invalid syntax
szhou@bc-R01:~/works/aosp/aosp$ python --version
Python 2.7.18
szhou@bc-R01:~/works/aosp/aosp$
2.4.2 查看可用的Python版本
- 常用Python,至少需安装2.7和3.6以上,两个版本
sudo apt-get install python2.7
(1)查看已安装的Python有哪些版本
szhou@bc-R01:~/works/aosp/aosp$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 24 12月 10 20:34 /usr/bin/python -> /etc/alternatives/python
lrwxrwxrwx 1 root root 9 3月 13 2020 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3662032 7月 1 2022 /usr/bin/python2.7
lrwxrwxrwx 1 root root 33 7月 1 2022 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 3月 13 2020 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 12月 10 08:57 /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 5465880 11月 22 18:22 /usr/bin/python3.8
lrwxrwxrwx 1 root root 33 11月 22 18:22 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root 16 3月 13 2020 /usr/bin/python3-config -> python3.8-config
-rwxr-xr-x 1 root root 384 1月 25 2023 /usr/bin/python3-futurize
-rwxr-xr-x 1 root root 388 1月 25 2023 /usr/bin/python3-pasteurize
lrwxrwxrwx 1 root root 14 4月 15 2020 /usr/bin/python-config -> python2-config
szhou@bc-R01:~/works/aosp/aosp$
2.4.3 配置多Python版本支持
- 本人系统中已安装2.7和3.8两个版本
(1)配置多版本支持
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2(2)执行 --config python后,选择Python3.8, 编号为2
szhou@bc-R01:~/works/aosp/aosp$ sudo update-alternatives --config python
[sudo] password for szhou:
There are 2 choices for the alternative python (providing /usr/bin/python).Selection Path Priority Status
------------------------------------------------------------0 /usr/bin/python3.8 2 auto mode
* 1 /usr/bin/python2.7 1 manual mode2 /usr/bin/python3.8 2 manual modePress <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python3.8 to provide /usr/bin/python (python) in manual mode
szhou@bc-R01:~/works/aosp/aosp$ (3)查看版本设置情况
szhou@bc-R01:~/works/aosp/aosp$ python --version
Python 3.8.10
szhou@bc-R01:~/works/aosp/aosp$
2.5 repo init 初始化分支
- 为了节约repo sync时间,我们可以选定只同步目标分支:android-13.0.0_r82
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r82
2.6 repo sync
- 加上 -c 参数,仅同步当前android-13.0.0_r82分支,节约下载时间
szhou@bc-R01:~/works/aosp/aosp$ repo sync -c
三、解决repo sync 错误
3.1 Python 版本引起的错误
- 解决办法: 建议切换到3.8及以上版本
- 多版本支持,请查看本文第2.4.1节
szhou@bc-R01:~/works/aosp/aosp/.repo/manifests.git$ cd ../..
szhou@bc-R01:~/works/aosp/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r82File "/usr/bin/repo", line 51def print(self, *args, **kwargs):^
SyntaxError: invalid syntax
szhou@bc-R01:~/works/aosp/aosp$ python --version
Python 2.7.18
szhou@bc-R01:~/works/aosp/aosp$
3.2 repo脚本偏旧导致的错误
- 解决办法:切换到aosp/.repo/repo目录下,执行git pull
szhou@oa-R630:~/works/aosp$ /home/szhou/Downloads/aosp/bin/repo sync -c
Fetching: 100% (1146/1146), done in 11m43.689s
info: A new version of repo is available
repo: Updating release signing keys to keyset ver 2.3
warning: repo is not tracking a remote branch, so it will not receive updates
================================================================================
Repo command failed: RepoUnhandledExceptionError
szhou@oa-R630:~/works/aosp$
szhou@oa-R630:~/works/aosp/.repo/repo$ git pull
3.3 repo sync 数据错误
3.3.1 类型1:error: in sync -lc
: revision refs xxx
- 解决办法:
- (1)找到事故目标: .repo/projects/device 或 .repo/projects/device /google/raviole-kernel
- (2)删除 rm -rf .repo/projects/device
- (3)更准确点:rm -rf .repo/projects/device /google/raviole-kernel
- (4)继续repo sync -c 同步代码
szhou@oa-R630:~/works/aosp$ /home/szhou/Downloads/aosp/bin/repo sync -c
error: Cannot checkout device/google/raviole-kernel: ManifestInvalidRevisionError: revision refs/tags/android-13.0.0_r82 in device/google/raviole-kernel not found
error: in `sync -c`: revision refs/tags/android-13.0.0_r82 in device/google/raviole-kernel not found
szhou@oa-R630:~/works/aosp$ ls -al
total 24
drwxr-xr-x 6 szhou szhou 4096 12月 20 11:11 .
drwxrwxr-x 5 szhou szhou 4096 12月 20 10:53 ..
drwxrwxr-x 36 szhou szhou 4096 12月 20 11:11 art
drwxrwxr-x 4 szhou szhou 4096 12月 20 11:11 device
drwxrwxr-x 3 szhou szhou 4096 12月 20 11:11 external
drwxr-xr-x 7 szhou szhou 4096 12月 20 11:10 .repo
szhou@oa-R630:~/works/aosp$ cd .repo/
manifests/ manifests.git/ project-objects/ projects/ repo/
szhou@oa-R630:~/works/aosp$ cd .repo/manifests.git/
branches/ hooks/ info/ logs/ objects/ refs/
szhou@oa-R630:~/works/aosp$ cd .repo/
manifests/ manifests.git/ project-objects/ projects/ repo/
szhou@oa-R630:~/works/aosp$ cd .repo/manifests
manifests/ manifests.git/
szhou@oa-R630:~/works/aosp$ cd .repo/
manifests/ manifests.git/ project-objects/ projects/ repo/
szhou@oa-R630:~/works/aosp$ cd .repo/projects/
art.git/ build/ developers/ external/ kernel/ packages/ prebuilts/ test/
bionic.git/ cts.git/ development.git/ frameworks/ libcore.git/ pdk.git/ sdk.git/ toolchain/
bootable/ dalvik.git/ device/ hardware/ libnativehelper.git/ platform_testing.git/ system/ tools/
szhou@oa-R630:~/works/aosp$ cd .repo/projects/device
szhou@oa-R630:~/works/aosp/.repo/projects/device$ cd -
/home/szhou/works/aosp
szhou@oa-R630:~/works/aosp$ rm -rf .repo/projects/device
szhou@oa-R630:~/works/aosp$ /home/szhou/Downloads/aosp/bin/repo sync -c
3.3.1 类型2:Unable to fully sync the tree
- 如下,虽然同步完成了,但提示了一些错误
- 解决办法:
- (1)锁定Failing repos目标
- (2)逐个删除,例如 rm -rf device/generic/trusty device/generic/uml art ……
- (3)继续执行 repo sync -c, 直至无错误100%完成同步
Checking out: 100% (1145/1145), done in 10m12.341s
error: Unable to fully sync the tree
error: Checking out local projects failed.
Failing repos:
device/generic/trusty
device/generic/uml
device/generic/vulkan-cereal
art
device/google/pantah-sepolicy
device/google/raviole
Try re-running with "-j1 --fail-fast" to exit at the first error.
================================================================================
Repo command failed due to the following `SyncError` errors:
device/generic/trusty checkout 05e24c85c2a542498ccf2983d898fcf0e6f9edd2
device/generic/uml checkout 60bc18c3a72bbed9640edaba4422fec18f36d6e9
device/generic/vulkan-cereal checkout 4b79dc90f067220adcc37bc24dae8f211ebe2d17
platform/art checkout b4ac1db327a419fb87e83c8b6f9825bc5fc126c3
device/google/pantah-sepolicy checkout 28219f7c6376cd1a810517d770029439dde653d5
+1 additional errors...
szhou@oa-R630:~/works/aosp$
四、代码同步成功
- 同步成功后,画面如下所示