FAQ--总结下载源码报错问题

通过查看论坛提问下载代码报错的帖子,总结如下几类:

a 类 :

a1)–权限问题

File “/snap/git-repo/18/usr/lib/python2.7/multiprocessing/synchronize.py”, line 75, in init
sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 13] Permission denied

a2)–repo版本问题

Traceback (most recent call last):
File “/home/zhang/workspace/khads/aosp/.repo/repo/main.py”, line 628, in
_Main(sys.argv[1:])
File “/home/zhang/workspace/khads/aosp/.repo/repo/main.py”, line 602, in _Main
result = run()
File “/home/zhang/workspace/khads/aosp/.repo/repo/main.py”, line 595, in
run = lambda: repo._Run(name, gopts, argv) or 0
File “/home/zhang/workspace/khads/aosp/.repo/repo/main.py”, line 264, in _Run
result = cmd.Execute(copts, cargs)
File “/home/zhang/workspace/khads/aosp/.repo/repo/subcmds/start.py”, line 117, in Execute
nb, branch_merge=branch_merge, revision=opt.revision):
File “/home/zhang/workspace/khads/aosp/.repo/repo/project.py”, line 1996, in StartBranch
self.work_git.update_ref(ref, revid)
File “/home/zhang/workspace/khads/aosp/.repo/repo/project.py”, line 3411, in runner
(self._project.name, name, p.stderr))
error.GitError: linux update-ref: fatal: update_ref failed for ref ‘refs/heads/khadas-vims-pie’: cannot update ref ‘refs/heads/khadas-vims-pie’: trying to write ref ‘refs/heads/khadas-vims-pie’ with nonexistent object 7a2b95478b169a0ff113a570836dbae4324205a0
Traceback (most recent call last):
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/main.py", line 628, in <module>
    _Main(sys.argv[1:])
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/main.py", line 602, in _Main
    result = run()
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/main.py", line 595, in <lambda>
    run = lambda: repo._Run(name, gopts, argv) or 0
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/main.py", line 264, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/subcmds/sync.py", line 982, in Execute
    self._Checkout(all_projects, opt, err_event, err_results)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/subcmds/sync.py", line 567, in _Checkout
    self._CheckoutWorker(**kwargs)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/subcmds/sync.py", line 447, in _CheckoutWorker
    return self._CheckoutOne(opt, project, *args, **kwargs)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/subcmds/sync.py", line 481, in _CheckoutOne
    project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/project.py", line 1623, in Sync_LocalHalf
    self._InitWorkTree(force_sync=force_sync, submodules=submodules)
  File "/home/sword/Amlogic-Android-source/khadas-aosp/test/.repo/repo/project.py", line 3135, in _InitWorkTree
    raise GitError('Cannot initialize work tree for ' + self.name)
hlm@Server:/users/hlm/khadas$ ../repo/repo sync -j4
repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
Traceback (most recent call last):
  File "/users/hlm/repo/main.py", line 56, in <module>
    from subcmds.version import Version
  File "/users/hlm/repo/subcmds/__init__.py", line 38, in <module>
    ['%s' % name])
  File "/users/hlm/repo/subcmds/upload.py", line 27, in <module>
    from hooks import RepoHook
  File "/users/hlm/repo/hooks.py", line 472
    file=sys.stderr)
        ^
SyntaxError: invalid syntax
hlm@Server:/users/hlm/khadas$
repo sync vendor/amlogic/common/external/ffmpeg
Skipped fetching project android_vendor_amlogic_external_ffmpeg (already have persistent ref)

fatal: unable to access 'https://gerrit.googlesource.com/git-repo/': Failed to connect to gerrit.googlesource.com port 443: time out

a类问题都可以下载 repo 来解决,若无法下载,请链接: https://pan.baidu.com/s/1GybJm7ByhsL5lcFVnJD1Vw 提取码: hnj5,解压后直接引用,.repo/repo/repo sync -j40

b 类 :

repo init -u https://aosp.tuna.tsinghua.edu.cn/khadas/android_manifest.git -b khadas-vims-pie

用的链接不对, 修改清华源参考如下步骤:

比如要下载Edge android 10.0代码:
$repo init -u https://github.com/khadas/android_manifest.git -b khadas-edge-Qt
$若修改清华源在这一步里
$repo sync -j40
$repo start <BRANCH_NAME> --all

比如要下载VIM3 android 9.0代码:
$repo init -u https://github.com/khadas/android_manifest.git -b khadas-vims-pie
$若修改清华源在这一步里
$repo sync -j40
$repo start <BRANCH_NAME> --all

补充:

最近清华源网站证书过期了,使用清华源前请先执行如下命令关闭证书校验,否则连接清华源失败:

export  GIT_SSL_NO_VERIFY=1

c 类:

heaven7@heaven7-os:~/study/aosp_vim3$ python repo init -u
https://github.com/khadas/android_manifest.git -b khadas-vim3-pie
Downloading manifest from https://github.com/khadas/android_manifest.git
fatal: Couldn’t find remote ref refs/heads/khadas-vim3-pie
manifests:
fatal: Couldn’t find remote ref refs/heads/khadas-vim3-pie

分支名称不对,vim1, vim2, vim3, vim3l 的android 9.0 SDK用的分支名都是khadas-vims-pie

d 类:

d 类问题报的比较多,由于github在国外,国内没有VPN的话,下载速度比较慢,网络也不太稳定,这就导致在下载过程容易出错,即使改用清华的源,也只是对谷歌的原生代码生效,我们修改的部分代码最终还是得从github上拉下来,如下图所示包含两个仓库地址:

Fetching project android_device_rockchip_rk3399
fatal: Couldn’t find remote ref refs/heads/c44fe0b18eae500811a0bafc733ef3f0ffac9e38
fatal: Couldn’t find remote ref refs/heads/087d19389776d16f7c58f5c085aebadd0f726ef2
fatal: Couldn’t find remote ref refs/heads/1e2bdf693b57314ff24e96b00eb81c17f9a14f2f
fatal: Couldn’t find remote ref refs/heads/c44fe0b18eae500811a0bafc733ef3f0ffac9e38
fatal: Couldn’t find remote ref refs/heads/398454d914257e95f8387fea50af7d8353281ff2
fatal: Couldn’t find remote ref refs/heads/087d19389776d16f7c58f5c085aebadd0f726ef2
error: Cannot fetch android_RKDocs_rk3399 from https://github.com/khadas/android_RKDocs_rk3399
fatal: Couldn’t find remote ref refs/heads/087d19389776d16f7c58f5c085aebadd0f726ef2
fatal: Couldn’t find remote ref refs/heads/087d19389776d16f7c58f5c085aebadd0f726ef2
error: Cannot fetch android_device_rockchip_rk3399 from https://github.com/khadas/android_device_rockchip_rk3399
error: Exited sync due to fetch errors
error: Cannot fetch android_system_extras (GitError: --force-sync not enabled; cannot overwrite a local work tree. If you’re comfortable with the possibility of losing the work tree’s git metadata, use repo sync --force-sync system/extras to proceed.)
error: Cannot fetch android_frameworks_base from https://github.com/khadas/android_frameworks_base
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly

针对以上某某个目录报错,可能是网络不稳定,拉的过程中导致仓库被破坏或者仓库不规范变更导致冲突,解决方案执行如下命令:

repo sync --force-sync -j4 RKDocs/rk3399
repo sync --force-sync -j4 device/rockchip/rk3399
repo sync --force-sync -j4 system/extras
repo sync --force-sync -j4 frameworks/base

即 repo sync --force-sync -j4 + 对应报错目录,"–force-sync"代表强制覆盖本地仓库。

remote: Enumerating objects: 65, done.
remote: Counting objects: 100% (65/65), done.
remote: Compressing objects: 100% (58/58), done.
error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function.
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

另外拉代码过程中,可能会报大量上图错误,说明网络不太稳定,需要多次同步代码。
如果是首次拉代码,建议用如下脚本拉取,因为网络不太稳定,拉取过程中容易报错而停止。
如果需要退出此脚本,请同时按这3个键Ctrl-\

#!/bin/bash

.repo/repo/repo sync --force-sync -c
while [ $? = 1 ]; do
	echo "Sync failed, repeat again:"
	.repo/repo/repo sync --force-sync -c
done 

同步完代码,是需要进行搜索关键词“error”确认是否有报错的地方。否则会遇到如下问题:

很多人同步完代码后,执行新建分支命令:

repo start <BRANCH_NAME> --all

会报错,那都是因为同步代码有问题导致。
还有一种情况是编译报错,也可能是因为同步代码有问题导致。