无法在 docker 中获取 gradle 构建工具 - Apple M1

发布于 2025-01-09 13:22:20 字数 2457 浏览 0 评论 0原文

我最近切换到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2025-01-16 13:22:20

我刚刚在 M1 Pro 上遇到了同样的问题,为我解决了这个问题。

简而言之:模拟器在 Arm (M1) 上尚不可用,因此您需要手动安装。您可以按照官方指南进行操作,但简而言之,这对我有用

  1. 下载模拟器< /code> 用于 Apple Silicon (示例 或者您可以在[官方指南]( https://developer.android.com/studio/emulator_archive
  2. 解压 Android SDK 文件夹中的文件夹(它将创建一个包含文件的 SKD/emulator 文件夹)
  3. 创建SDK/emulator/package.xml 文件,其中包含 内容来自此处并更新 xml 的最后部分3114 与您下载的版本
  4. 您应该在 M1 上没有再次看到相同的错误

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 me

  1. Download emulator for Apple Silicon (example or you find more links in the [official guide](https://developer.android.com/studio/emulator_archive
  2. Unzip the folder in Android SDK folder (it will create a SKD/emulator folder with files inside)
  3. Create 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 downloaded
  4. You should not see the same error again on M1 ????

Spoiler Alert: I'm still not able to fully build on M1 because, during the actual build, I get the error

qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
2025-01-16 13:22:20

我有同样的问题。我认为 linux/armv8 没有 android“模拟器”包。因此您将无法将 docker 与本机映像一起使用。

我尝试配置 docker-compose 文件以使用 linux/x86_64 而不是 linux/armv8,但还有其他问题。
我在 docker-compose.yaml 中添加了这一行:

platform: linux/x86_64

像这样:

version: '3.7'
services:
  android:
    platform: linux/x86_64
    build:
      dockerfile: Dockerfile
      context: ./Docker
    working_dir: /app/Android/Scripts
    volumes:
      - ../:/app:rw,cached
    command: ./build_distribution.sh
#    command: sh -c "while true; do sleep 10; done"

但是我遇到了很多网络问题。该架构上的网络层似乎有问题,有时会卡住随机下载图像或组件......

有没有办法让它与一种或其他架构一起工作?

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 :

platform: linux/x86_64

like this :

version: '3.7'
services:
  android:
    platform: linux/x86_64
    build:
      dockerfile: Dockerfile
      context: ./Docker
    working_dir: /app/Android/Scripts
    volumes:
      - ../:/app:rw,cached
    command: ./build_distribution.sh
#    command: sh -c "while true; do sleep 10; done"

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文