名词解释
repo引导脚本: 单独下载的一个repo文件,是repo工具集的入口。通常会将其放在/home/<用户>/bin/
repo工具集: 是一个名叫repo的目录,包含了repo所有功能的脚本集合,由repo引导脚本调用,其位置在项目的.repo里。
一. repo init相关
1. python版本不匹配repo引导脚本
报错:Python 3 support is currently experimental. YMMV. Please use Python 2.7 instead.
sun@sun-pc:~/project/AOSP$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
warning: Python 3 support is currently experimental. YMMV.
Please use Python 2.7 instead.
Traceback (most recent call last):
File "/home/sun/bin/repo", line 917, in <module>
main(sys.argv[1:])
File "/home/sun/bin/repo", line 879, in main
_Init(args, gitc_init=(cmd == 'gitc-init'))
File "/home/sun/bin/repo", line 360, in _Init
_CheckGitVersion()
File "/home/sun/bin/repo", line 419, in _CheckGitVersion
ver_act = ParseGitVersion(ver_str)
File "/home/sun/bin/repo", line 389, in ParseGitVersion
if not ver_str.startswith('git version '):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
解决方法: 参照Linux系列讲解 —— 切换程序到不同版本(python为例).切换到python2.7后,再执行一遍repo init即可。
2. python版本不匹配repo工具集
File “/home/sun/project/AOSP/.repo/repo/main.py”, line 79
file=sys.stderr)
^
SyntaxError: invalid syntax
解决方法: 和python的版本有关,python2.7不支持参数里使用"="赋值,可以切换到python更高版本。
3. 缺少依赖库
报错:cModuleNotFoundError: No module named ‘_ctypes’
sun@ubuntu:~/projects/AOSP2$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
Traceback (most recent call last):
File "/home/sun/projects/AOSP2/.repo/repo/main.py", line 39, in <module>
import event_log
File "/home/sun/projects/AOSP2/.repo/repo/event_log.py", line 163, in <module>
_EVENT_ID = multiprocessing.Value('i', 1)
File "/home/sun/.program/pyenv/versions/3.9.1/lib/python3.9/multiprocessing/context.py", line 134, in Value
from .sharedctypes import Value
File "/home/sun/.program/pyenv/versions/3.9.1/lib/python3.9/multiprocessing/sharedctypes.py", line 10, in <module>
import ctypes
File "/home/sun/.program/pyenv/versions/3.9.1/lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
解决方法: 这里可能有两个原因,依据实际情况进行使用
原因一:缺少libffi-dev库,安装即可
sun@ubuntu:~/projects/AOSP2$ sudo apt-get install libffi-dev
原因二:使用的python版本不匹配,去报错的main.py中查看一下适用的版本,例如下图所示,最低要求是python3.6,那切换到python3.6即可。
4. 服务器或网络原因导致失败
报错:error.GitError: manifests ls-remote: usage: git ls-remote [–heads]error.GitError: manifests ls-remote: usage: git ls-remote [–heads]…
sun@ubuntu:~/projects/AOSP2$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
Downloading manifest from https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
Traceback (most recent call last):
File "/home/sun/projects/AOSP2/.repo/repo/main.py", line 651, in <module>
_Main(sys.argv[1:])
File "/home/sun/projects/AOSP2/.repo/repo/main.py", line 627, in _Main
result = run()
File "/home/sun/projects/AOSP2/.repo/repo/main.py", line 620, in <lambda>
run = lambda: repo._Run(name, gopts, argv) or 0
File "/home/sun/projects/AOSP2/.repo/repo/main.py", line 286, in _Run
result = cmd.Execute(copts, cargs)
File "/home/sun/projects/AOSP2/.repo/repo/subcmds/init.py", line 534, in Execute
self._SyncManifest(opt)
File "/home/sun/projects/AOSP2/.repo/repo/subcmds/init.py", line 201, in _SyncManifest
default_branch = m.ResolveRemoteHead()
File "/home/sun/projects/AOSP2/.repo/repo/project.py", line 1975, in ResolveRemoteHead
output = self.bare_git.ls_remote('-q', '--symref', '--exit-code', name, 'HEAD')
File "/home/sun/projects/AOSP2/.repo/repo/project.py", line 3143, in runner
raise GitError('%s %s: %s' %
error.GitError: manifests ls-remote: usage: git ls-remote [--heads] [--tags] [--upload-pack=<exec>]
[-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]]
解决方法: 最后一行提示执行命令git ls-remote
时候出错。大概是碰到了服务器掉线或者是网络问题,可以尝试重新执行repo init
5. 服务器未在本机受信任列表,导致连接失败
Get ssh://In_engineer@192.168.1.66:29418/repo
remote: Counting objects: 4180, done
remote: Finding sources: 100% (4180/4180)
packet_write_wait: Connection to 192.168.1.66 port 29418: Broken pipe
fatal: The remote end hung up unexpectedly
fatal: 过早的文件结束符(EOF)
fatal: index-pack 失败
fatal: cloning the git-repo repository failed, will remove ‘.repo/repo’
解决方法: 这个暂时还不清楚什么原因,不过我命令行使用ssh登录服务器的时候,将服务器添加到受信任主机列表,然后就好使了。
sun@sun-pc:~/project/8970_A11_AP$ ssh In_engineer@192.168.1.66
The authenticity of host '192.168.1.66 (192.168.1.66)' can't be established.
ECDSA key fingerprint is SHA256:9/bxxxxxxS5nbDHOyyyyyyj8FrXbbbbOARYWPaaaaaa.
Are you sure you want to continue connecting (yes/no)? yes //这里选择yes后,自动将192.168.1.66服务器添加到受信任主机列表中
Warning: Permanently added '192.168.1.66' (ECDSA) to the list of known hosts.
...
二. repo sync相关
1. python版本不匹配repo工具集
TypeError: a bytes-like object is required, not ‘str’
sun@sun-pc:~/code/AOSP$ repo sync AOSP/frameworks/base
Fetching project AOSP/frameworks/base
Traceback (most recent call last):
File "/home/sun/code/AOSP/.repo/repo/main.py", line 547, in <module>
_Main(sys.argv[1:])
File "/home/sun/code/AOSP/.repo/repo/main.py", line 522, in _Main
result = repo._Run(argv) or 0
File "/home/sun/code/AOSP/.repo/repo/main.py", line 184, in _Run
result = cmd.Execute(copts, cargs)
File "/home/sun/sata/home/sun/project/AOSP/.repo/repo/subcmds/sync.py", line 840, in Execute
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
File "/home/sun/sata/home/sun/project/AOSP/.repo/repo/project.py", line 1496, in Sync_LocalHalf
if self.IsDirty(consider_untracked=False):
File "/home/sun/sata/home/sun/project/AOSP/.repo/repo/project.py", line 784, in IsDirty
if self.work_git.DiffZ('diff-files'):
File "/home/sun/sata/home/sun/project/AOSP/.repo/repo/project.py", line 2698, in DiffZ
out = iter(out[:-1].split('\0'))
TypeError: a bytes-like object is required, not 'str'
调查分析:
1.报错是在repo工具集中的project.py的2698行,提示split方法的对象应该是bytes,而不是’str’
2.已知机器安装了python2.7和python3.6,在python2.7语法中split的对象为’str’,而python3.6要求的是bytes-like object,所以通过错误可知,这里工具集用的是python3.6
3.如下源码所示,虽然repo工具集用的是python2.7,但是repo引导脚本用的是python3.6,所以repo执行的一开始用的就是python3.6
repo引导脚本:/home/sun/bin/repo
repo工具集中repo脚本:/home/sun/code/AOSP/.repo/repo/repo
解决方法:
方法一:使用python2.7环境
将/home/sun/code/AOSP/.repo/repo/repo
拷贝覆盖/home/sun/bin/repo
(记得做备份),然后将python环境切换到python2.7
方法二:使用python3.6环境
现在发布的最新的repo工具集是使用python3.6的,执行下面命令下载,然后将下载好的repo目录整个拷贝到/home/sun/code/AOSP/.repo/repo
中,最后将python环境切换到python3.6
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest --repo-url=https://aosp.tuna.tsinghua.edu.cn/git-repo