# scrcpy-android test image.
#
# Bundles JDK 17, Android cmdline-tools, platform 35, build-tools 35,
# emulator, and an x86_64 default API-35 system image (for e2e).
# Project is mounted at /work; runs in --rm mode.

FROM debian:bookworm-slim

ARG SDK_VER=11076708
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
        openjdk-17-jdk-headless \
        curl unzip ca-certificates \
        libpulse0 libxkbcommon0 libgl1 libnss3 libasound2 libdbus-1-3 \
        qemu-system-x86 qemu-utils \
        procps \
        ffmpeg \
 && rm -rf /var/lib/apt/lists/*

ENV ANDROID_SDK_ROOT=/opt/android-sdk
ENV ANDROID_HOME=$ANDROID_SDK_ROOT

RUN mkdir -p $ANDROID_SDK_ROOT/cmdline-tools \
 && curl -fsSL "https://dl.google.com/android/repository/commandlinetools-linux-${SDK_VER}_latest.zip" \
        -o /tmp/clt.zip \
 && unzip -q /tmp/clt.zip -d $ANDROID_SDK_ROOT/cmdline-tools \
 && mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest \
 && rm /tmp/clt.zip

ENV PATH=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH

COPY sdk-packages.txt /tmp/sdk-packages.txt
RUN yes | sdkmanager --licenses >/dev/null \
 && sdkmanager $(tr '\n' ' ' < /tmp/sdk-packages.txt) >/dev/null \
 && chmod -R a+rwX "$ANDROID_SDK_ROOT"

# Pre-create the default AVD location and let gradle put its cache here.
ENV GRADLE_USER_HOME=/work/.tools/gradle-home
ENV ANDROID_AVD_HOME=/work/.tools/avd

WORKDIR /work
