无法在 docker 中获取 gradle 构建工具 - Apple M1
我最近切换到 Apple M1,并且在创建最终在 Buildkite Linux CI 上运行的 docker 映像时遇到问题。相同的代码在我的配备 Intel 芯片的 MacBook 上运行得很好,并成功创建了 docker 镜像。
当 sdkmanager
尝试使用最新的 commandlinetools
引入 build-tools;${ANDROID_BUILD_TOOLS_VERSION}
时,会出现此问题,失败并显示以下错误:
Warning: Dependant package with key emulator not found!
Warning: Unable to compute a complete list of dependencies.ates...
我能找到的最接近的问题是安装构建工具:找不到模拟器 和 android sdk 出错,两者没有任何决议。另请注意,我已运行 sdkmanager --list
,并且 emulator
不作为可用包存在(仅在 M1 上)。
这是我的 Dockerfile(我不经常使用 docker,所以如果代码不是最干净的,请原谅):
FROM gradle:7.4-jdk11
ENV SDK_URL="https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip" \
ANDROID_HOME="/usr/local/android-sdk" \
ANDROID_VERSION=32 \
ANDROID_BUILD_TOOLS_VERSION=32.0.0
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --update \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platform-tools" "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_VERSION}" \
&& apt-get update \
&& apt-get install -y build-essential file apt-utils curl gnupg \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get -y install nodejs \
&& npm install -g firebase-tools -y \
&& rm -rf /var/lib/apt/lists/*
旁注;我必须将 Android 构建代理的 jdk8 使用升级到 jdk11,之前的实现是引入 sdk-tools-linux-3859397.zip
而不是 commandlinetools-linux-8092744_latest.zip< /code>,并且能够通过
sdkmanager
引入 build-tools
就可以了M1 也创建了一个 docker 镜像。
鉴于它是基于 Intel 构建的,我的任务在技术上已经完成,但从长远来看,它在 M1 上运行会容易得多。有什么想法吗?或者有人可以建议提出这个问题的正确地点是什么?您认为这是 google 命令行工具问题还是 docker 问题?
I recently switched to Apple M1 and am having a problem creating a docker image that eventually runs on a Buildkite linux CI. The same code runs just fine on my MacBook with an Intel chip and successfully creates a docker image.
The problem happens when sdkmanager
tries to pull in build-tools;${ANDROID_BUILD_TOOLS_VERSION}
with the latest commandlinetools
, it fails with the following errors:
Warning: Dependant package with key emulator not found!
Warning: Unable to compute a complete list of dependencies.ates...
The closest issues I can find are Install build-tools: emulator not found and Error with android sdk, both without any resolutions. Also note that I have run sdkmanager --list
, and emulator
is not present as an available package there (just on M1).
Here is my Dockerfile
(I don't work with docker too often so please excuse if the code is not the cleanest):
FROM gradle:7.4-jdk11
ENV SDK_URL="https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip" \
ANDROID_HOME="/usr/local/android-sdk" \
ANDROID_VERSION=32 \
ANDROID_BUILD_TOOLS_VERSION=32.0.0
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --update \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platform-tools" "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_VERSION}" \
&& apt-get update \
&& apt-get install -y build-essential file apt-utils curl gnupg \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get -y install nodejs \
&& npm install -g firebase-tools -y \
&& rm -rf /var/lib/apt/lists/*
Side note; I had to upgrade usage of jdk8 to jdk11 for the Android build agent, the previous implementation was pulling in sdk-tools-linux-3859397.zip
instead of commandlinetools-linux-8092744_latest.zip
, and that was able to pull in build-tools
via the sdkmanager
just fine on the M1 as well and created a docker image.
Given that it builds on Intel, my task is technically complete, but it's going to be much easier in the long run that it runs on M1. Any ideas? Or can anyone suggest what the right place would be to raise this? Do you reckon it is a google command line tool issue or docker issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在 M1 Pro 上遇到了同样的问题,这为我解决了这个问题。
简而言之:
模拟器
在 Arm (M1) 上尚不可用,因此您需要手动安装。您可以按照官方指南进行操作,但简而言之,这对我有用模拟器< /code> 用于 Apple Silicon (示例 或者您可以在[官方指南]( https://developer.android.com/studio/emulator_archive
SKD/emulator
文件夹)SDK/emulator/package.xml
文件,其中包含 内容来自此处并更新 xml 的最后部分31 1 4
与您下载的版本I just had the same problem on M1 Pro and this solved the issue for me.
In short:
emulator
is not available on Arm (M1) yet so you need to install it manually. You can follow the official guide but in short, this worked for meemulator
for Apple Silicon (example or you find more links in the [official guide](https://developer.android.com/studio/emulator_archiveSKD/emulator
folder with files inside)SDK/emulator/package.xml
file with content from here and update the last part of the xml<revision><major>31</major><minor>1</minor><micro>4</micro></revision>
with the version you downloadedSpoiler Alert: I'm still not able to fully build on M1 because, during the actual build, I get the error
我有同样的问题。我认为 linux/armv8 没有 android“模拟器”包。因此您将无法将 docker 与本机映像一起使用。
我尝试配置 docker-compose 文件以使用 linux/x86_64 而不是 linux/armv8,但还有其他问题。
我在 docker-compose.yaml 中添加了这一行:
像这样:
但是我遇到了很多网络问题。该架构上的网络层似乎有问题,有时会卡住随机下载图像或组件......
有没有办法让它与一种或其他架构一起工作?
I have same issue. I think there is no android 'emulator' package for linux/armv8 . So you won't be able to use docker with native images.
I tried to configure docker-compose file in order to use linux/x86_64 instead of linux/armv8 but there are others issues.
I add this line in docker-compose.yaml :
like this :
But I get a lot of issue with network. It seems that network layer on this architecture is buggy and sometimes it is stuck downloading an image or a component randomly...
Is there a way to make it work with one or other architecture ?