1 #===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===----------------------------------------------------------------------===##
11 RUN apt-get update && apt-get install -y \
17 && rm -rf /var/lib/apt/lists/*
19 ENV ANDROID_HOME /opt/android/sdk
21 RUN curl -sL https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip -o cmdline-tools.zip && \
22 mkdir -p ${ANDROID_HOME} && \
23 unzip cmdline-tools.zip -d ${ANDROID_HOME}/cmdline-tools && \
24 mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest && \
26 ENV PATH="${ANDROID_HOME}/cmdline-tools/latest/bin:${PATH}"
28 RUN yes | sdkmanager --licenses
29 RUN sdkmanager --install emulator
30 ENV PATH="${ANDROID_HOME}/emulator:${PATH}"
33 RUN sdkmanager --install "platforms;android-${API}"
35 ARG TYPE # one of: default, google_apis, or google_apis_playstore
36 ARG ABI # e.g. armeabi-v7a, x86
37 ENV EMU_PACKAGE_NAME="system-images;android-${API};${TYPE};${ABI}"
38 RUN sdkmanager --install "${EMU_PACKAGE_NAME}"
40 COPY ./emulator-entrypoint.sh /opt/emulator/bin/emulator-entrypoint.sh
41 COPY ./emulator-wait-for-ready.sh /opt/emulator/bin/emulator-wait-for-ready.sh
42 ENV PATH="/opt/emulator/bin:${PATH}"
43 ENV PATH="${ANDROID_HOME}/platform-tools:${PATH}"
45 # Setup password-less sudo so that /dev/kvm permissions can be changed. Run the
46 # emulator in an unprivileged user for reliability (and it might require it?)
47 RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
48 RUN useradd --create-home emulator
50 WORKDIR /home/emulator
52 # Size of emulator /data partition in megabytes.
53 ENV EMU_PARTITION_SIZE=8192
57 HEALTHCHECK CMD emulator-wait-for-ready.sh 5
59 ENTRYPOINT ["emulator-entrypoint.sh"]