3

I'm trying to build an Alpine image containing the Android SDK - specifically, the platform-tools package.

My Dockerfile does the following:

  1. Installs Java and sets JAVA_HOME (needed for Android).
  2. Downloads the Android SDK tools from Google.
  3. Unzips the package.
  4. Sets ANDROID_HOME. Also sets PATH so the sdkmanager executable can be used.
  5. Installs platform-tools using sdkmanager.
  6. Adds platform-tools to PATH.

platform-tools contains an executable named adb, but for some reason it cannot be seen. Running adb returns:

bash: /android-sdk/platform-tools/adb: No such file or directory

Here is my Dockerfile:

FROM alpine:latest

# Install bash and java
RUN apk update
RUN apk add bash openjdk8
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
ENV PATH="$PATH:$JAVA_HOME/bin"

# Download Android SDK and set PATH
RUN mkdir /android-sdk
RUN wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip && unzip *.zip -d /android-sdk && rm *.zip
ENV ANDROID_HOME="/android-sdk"
ENV PATH="$PATH:$ANDROID_HOME/tools/bin"

# Install platform-tools
RUN yes | sdkmanager "platform-tools"
ENV PATH="$PATH:$ANDROID_HOME/platform-tools"
RUN adb version # throws error: adb not found

I've looked at this question but the problem should be fixed with platform-tools v24.0 and higher.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
Jason
  • 409
  • 2
  • 6
  • 10

3 Answers3

4

Alpine uses musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements.

adb is compiled with glibc, so it won't be able to run in Alpine, which usually results in the error: No such file or directory.

You can verify that a file is compiled with glibc by running file <path to file> | grep "interpreter /lib64/ld-linux-x86-64.so.2".

pierlo
  • 91
  • 3
2

This may help, although the Gradle daemon randomly crashes for me on Alpine Linux when using the compatibility layer.

gcompat is the go-to compatibility layer for Alpine users.

apk add gcompat

After that you run your binaries as normal.

Source: https://wiki.alpinelinux.org/wiki/Running_glibc_programs

var47
  • 422
  • 3
  • 6
-1

You can install android-tools like so:

RUN apk add \
    android-tools \
    --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

The key is to set the --repository as shown, as it's only in the edge testing repo.

I don't think it includes the whole SDK, so may need to download and unzip as well for other tools. I don't know if this will handle everything you want, but adb prints a help document at least.

Noah
  • 4,601
  • 9
  • 39
  • 52
  • Why is this answer ignored, its true you can add the 'android-tools' package ([source](https://pkgs.alpinelinux.org/package/edge/community/x86/android-tools)) using `apk add android-tools` – Mr.O Apr 25 '23 at 12:55