Android 的 repo 工具使用 python2 失败

问题描述

我的 Dockerfile 有 Xamarin.Messaging.Ssh.Exceptions.AgentInstallationException: An error occurred while installing broker 16.8.000.260 ---> Xamarin.Messaging.Exceptions.MessagingException: Unable to copy file 'c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\xamarin.visualstudio\broker.zip' to '/tmp/broker-16.8.000.260-2054e5d0-1d43-4a3a-bb31-ba1092028c66' ,我得到:

python3

如果我安装 RUN repo init -u https://android.googlesource.com/platform/manifest ---> Running in f3adc38c2aac /usr/bin/env: 'python': No such file or directory ,我会收到这个错误

python

Repo 是这样下载的:

Step 6/7 : RUN repo init -u https://android.googlesource.com/platform/manifest
 ---> Running in 9c03e1b95c0f
repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
Traceback (most recent call last):
  File "/home/project/aosp/.repo/repo/main.py",line 56,in <module>
    from subcmds.version import Version
  File "/home/project/aosp/.repo/repo/subcmds/__init__.py",line 38,in <module>
    ['%s' % name])
  File "/home/project/aosp/.repo/repo/subcmds/upload.py",line 27,in <module>
    from hooks import RepoHook
  File "/home/project/aosp/.repo/repo/hooks.py",line 472
    file=sys.stderr)
        ^
SyntaxError: invalid Syntax

解决方法

https://storage.googleapis.com/git-repo-downloads/repo 至少需要 Python 3.6。

要将 python3 与刚刚下载的 repo 一起使用,您需要修复 shebang 行:

sed -i '1s/python/python3/' /android_tools/repo