我正在尝试使用 Shippable 制作一个可用于构建 Android 项目的 docker 镜像。
问题是 android update sdk
命令,它给出了以下错误:
Installing Android SDK Tools, revision 24.2
Failed to rename directory /opt/android-sdk-linux/tools to /opt/android-sdk-linux/temp/ToolPackage.old01.
Failed to create directory /opt/android-sdk-linux/tools
我在这里找到了一些解决方案:https://stackoverflow.com/a/8839359/867099但它适用于 Windows,似乎无法解决 linux 上的问题。似乎在更新命令期间,当前目录正在使用中,因此无法重命名。
到目前为止,我使用该解决方法建议的解决方法是这样的:
RUN cp -r /opt/android-sdk-linux/tools /opt/android-sdk-linux/tools_copy
RUN cd /opt/android-sdk-linux/tools && echo 'y' | /opt/android-sdk-linux/tools_copy/android update sdk --no-ui -a --filter tools,platform-tools,build-tools-22.0.1,android-21,extra-android-support,extra-google-google_play_services --force
为了自动接受许可,我 echo 'y'
到 android 命令。
但我认为 android
命令也应该在正确的目录中运行,这就是为什么我首先 cd
进入它。
但是,它仍然失败。我很困惑如何解决这个问题,所以任何帮助都非常感谢。
-------- 更新 --------
我在没有 tools
过滤器的情况下运行 android sdk update
命令,最后,我的 gradle 构建成功。所以我不确定不更新它们是否有问题......
最佳答案
这可以通过在单个 Dockerfile 的 RUN
命令中组合所有 Android SDK 命令来解决。跟Docker的文件系统有关。
详细解释来自 a post关于 Android 开源项目的问题跟踪器:
The problem is caused when you run the SDK update in a Docker container. Docker uses a special filesystem which works like a version control system (e.g. git) and records all changes made to the filesystem. The problem is that the SDK update uses a hardlink move operation to move the 'tools' directory, which is not supported by the underlying Docker filesystem.
The solution for this is to simply run all Android SDK commands in a single 'RUN' command in Docker. That way, the hardlink move works as normal, as long as you don't use the 'hardlink move' operation between multiple RUN command (snapshots). The advantage of this is also that your Docker layers will be smaller (compared to running multiple seperate RUN commands).
Here is the line from the Dockerfile:
RUN wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz && \
tar xzf android-sdk_r24.4.1-linux.tgz && \
rm android-sdk_r24.4.1-linux.tgz && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter platform-tools,tools -a ) && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository -a) && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter build-tools-23.0.2,android-24 -a)
关于在 Docker 中安装 Android SDK 工具失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301198/