下载Android源代码时,出现这个错误php
Traceback (most recent call last): File "E:\LocalProject\Oreo\.repo\repo/main.py", line 538, in <module> _Main(sys.argv[1:]) File "E:\LocalProject\Oreo\.repo\repo/main.py", line 512, in _Main result = repo._Run(argv) or 0 File "E:\LocalProject\Oreo\.repo\repo/main.py", line 185, in _Run result = cmd.Execute(copts, cargs) File "E:\LocalProject\Oreo\.repo\repo\subcmds\sync.py", line 823, in Execute project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync) File "E:\LocalProject\Oreo\.repo\repo\project.py", line 1335, in Sync_LocalHalf self._InitWorkTree(force_sync=force_sync) File "E:\LocalProject\Oreo\.repo\repo\project.py", line 2502, in _InitWorkTree raise GitError("cannot initialize work tree") error.GitError: cannot initialize work tree
从log来看,.repo/repo/project.py是要关注的地方,能够定位到脚本:
raise GitError("cannot initialize work tree")
其所在的函数为_InitWorkTreejava
_InitWorkTree完整的代码以下:linux
def _InitWorkTree(self, force_sync=False): dotgit = os.path.join(self.worktree, '.git') print("dotgit is {0}".format(dotgit)) print(self.gitdir) init_dotgit = not os.path.exists(dotgit) try: if init_dotgit: os.makedirs(dotgit) self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True, copy_all=False) try: self._CheckDirReference(self.gitdir, dotgit, share_refs=True) except GitError as e: if force_sync: try: shutil.rmtree(dotgit) return self._InitWorkTree(force_sync=False) except: raise e raise e if init_dotgit: _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId()) cmd = ['read-tree', '--reset', '-u'] cmd.append('-v') cmd.append(HEAD) if GitCommand(self, cmd).Wait() != 0: raise GitError("cannot initialize work tree") self._CopyAndLinkFiles() except Exception: if init_dotgit: shutil.rmtree(dotgit) raise
可是此处并不能给咱们什么有效信息,因此咱们要进一步继续分析android
用 repo --trace sync -cdf 将repo的全部动做详细输出(这个过程可能会很长,须要咱们耐心等待),会发如今这里出错致使:git
: cd E:\LocalProject\Oreo\external\kmod : git read-tree --reset -u -v HEAD 1>| 2>| error: unable to create symlink testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb: File exists
至此,咱们就定位到了问题。github
固然,在不熟悉repo命令的时候,咱们也能够添加log来了解当前卡在了哪里。为了找到当前出错时,git正在处理哪一个目录,我在_InitWorkTree
函数中加了2句log信息:apache
print("dotgit is {0}".format(dotgit)) print(self.gitdir)
def _InitWorkTree(self, force_sync=False): dotgit = os.path.join(self.worktree, '.git') print("dotgit is {0}".format(dotgit)) print(self.gitdir) init_dotgit = not os.path.exists(dotgit) try: if init_dotgit: os.makedirs(dotgit) ... ... ...
打印出来的log以下:segmentfault
dotgit is E:\LocalProject\Oreo\external\kmod\.git E:/LocalProject/Oreo/.repo/projects/external/kmod.git
能够看出当前是在处理E:\LocalProject\Oreo\external\kmod时出了问题。可是因为log有限,咱们其实并不能真正的了解到当前发生了什么。windows
前面的log是说file没法建立。缘由是是要建立的文件名字叫usb:btusb,这种命名是明显违反Windows命名规则的。因此实际上是无解的。
因此我打算先绕过这个问题,先把源码的其余部分下载下来,对于这个问题,之后再解决。既然这个项目有问题,那我就先不下载了,不能因小失大嘛。
打开.repo/manifest/default.xmlapp
<!--<project path="external/kmod" name="platform/external/kmod" groups="pdk" />-->
在网上搜了一圈,好像不少网友在windows下下载代码都遇到了"cannot initialize work tree"的问题。连Microsoft提供的win10下linux子系统的repo都有问题(最后参考连接里边有该问题的解决方案)。也是路径名称的问题。有兴趣的网友能够本身爬楼研究下。
Microsoft:https://github.com/Microsoft/...
我此次下载中还遇到了两次"cannot initialize work tree"这样的问题
下载“platform/libcore”出错
error: unable to create file luni/src/test/resources/org/apache/harmony/tests/java/lang/test?.properties: Invalid argument
“test?.properties”这个也是违反了Windows文件命名问题
下载“external/libunwind”出错
fatal: cannot create directory at 'aux': Invalid argument
这个是文件夹命名为“aux”出错,“aux”是Windows设备名文件夹。DOS上使用AUX,是auxiliary device的缩写,辅助设备,在DOS系统手册有声明这是系统标识符的。AUX默认是异步端口的流名字,一般与Console连在一块儿,属于标准命名设备,因此不容许你建立使用了系统保留名字的文件,由于文件也属于流设备。
若是你们想体验下这个问题,能够单独下载这三个项目试试 git clone url
下载单个项目的方法 https://segmentfault.com/a/11...
$ git clone https://aosp.tuna.tsinghua.edu.cn/platform/external/libunwind Cloning into 'libunwind'... remote: Counting objects: 16490, done. remote: Compressing objects: 100% (5188/5188), done. remote: Total 16490 (delta 11521), reused 15746 (delta 11246) Receiving objects: 100% (16490/16490), 4.18 MiB | 4.01 MiB/s, done. Resolving deltas: 100% (11521/11521), done. fatal: cannot create directory at 'aux': Invalid argument warning: Clone succeeded, but checkout failed. You can inspect what was checked out with 'git status' and retry the checkout with 'git checkout -f HEAD'
$ git clone https://aosp.tuna.tsinghua.edu.cn/platform/external/kmod Cloning into 'kmod'... remote: Counting objects: 6864, done. remote: Compressing objects: 100% (1851/1851), done. remote: Total 6864 (delta 4941), reused 6514 (delta 4746) Receiving objects: 100% (6864/6864), 5.51 MiB | 420.00 KiB/s, done. Resolving deltas: 100% (4941/4941), done. error: unable to stat just-written file testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb: No such file or directory fatal: unable to checkout working tree warning: Clone succeeded, but checkout failed. You can inspect what was checked out with 'git status' and retry the checkout with 'git checkout -f HEAD'
$ git clone https://aosp.tuna.tsinghua.edu.cn/platform/libcore Cloning into 'libcore'... remote: Counting objects: 245949, done. remote: Compressing objects: 100% (474/474), done. remote: Total 245949 (delta 263), reused 83 (delta 32) Receiving objects: 100% (245949/245949), 86.37 MiB | 3.97 MiB/s, done. Resolving deltas: 100% (157977/157977), done. error: unable to create file luni/src/test/resources/org/apache/harmony/tests/java/lang/test?.properties: Invalid argument Checking out files: 100% (6121/6121), done. fatal: unable to checkout working tree warning: Clone succeeded, but checkout failed. You can inspect what was checked out with 'git status' and retry the checkout with 'git checkout -f HEAD'
我下载的是android_8.1.0_r17版本的代码:
repo init -u https://aosp.tuna.tsinghua.ed... -b android_8.1.0_r1
repo的trace选项的做用
You can trace what really happens with repo
系统
Windows7
repo和Git的关系 https://blog.csdn.net/qugenam...
WSL https://github.com/Microsoft/...
FixDownloadAnrdoid https://github.com/NyaSik/Fix...
repo sync error: cannot initialize work tree https://blog.csdn.net/ly89070...
出现error: unable to create file tests/P_str_escape/str\escape.rs的解决办法 https://blog.csdn.net/u013553...
不能在 win7 下创建命为 aux 的文件夹? http://bbs.bccn.net/m.thread....