Running Android emulator in docker container Running Android emulator in docker container docker docker

Running Android emulator in docker container


So,

Is it possible to run the (Android) emulator through Docker? yes.

I don't know much about Fastlane|wix/Detox, but I made this in a e2e/Appium project

If so, how?Do you need a hardware that support virtualization

  1. In Linux find out if CPU Support Intel VT/AMD-V Virtualization For KVM

    lscpu | grep Virtualization

Virtualization: VT-x (if 'Intel VT-x' or 'VT-x' feature supported)

or

Virtualization: full (if 'full' not supported)

On AWS, you need a bare metal instance (supported x86) like c5.metal
  1. Android Emulator Container Scripts

https://github.com/google/android-emulator-container-scripts

  1. Follow this git, create an image with google API (I my case, 27-google-x86) and put in docker repo, like AWS ECR.

  2. And, I created an image too to Appium (I believe with is possible with wix/detox)

  3. To SDK

Dockerfile

FROM ubuntu:20.04ENV DEBIAN_FRONTEND=noninteractive# Installs i386 architecture required for running 32 bit Android toolsRUN dpkg --add-architecture i386 && \    apt-get update && \    apt-get dist-upgrade -y && \    apt-get install -y --no-install-recommends openjdk-8-jdk && \    apt-get install -y --no-install-recommends git wget unzip curl make && \    rm -rf /var/lib/apt/lists/* && \    apt-get autoremove -y && \    apt-get cleanENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre" \    PATH=$PATH:$JAVA_HOME/bin# Installs Android SDKENV ANDROID_HOME=/android-sdkENV ANDROID_SDK_HOME $ANDROID_HOMEARG ANDROID_SDK_VERSION=6514223ARG ANDROID_BUILD_TOOLS_VERSION=27.0.0ARG ANDROID_PLATFORM_VERSION="android-27"RUN mkdir -p ${ANDROID_SDK_HOME}/cmdline-tools && \    wget -q https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \    unzip *tools*linux*.zip -d ${ANDROID_SDK_HOME}/cmdline-tools && \    rm *tools*linux*.zipENV PATH ${PATH}:${ANDROID_SDK_HOME}/tools:${ANDROID_SDK_HOME}/platform-toolsRUN mkdir -p ~/.android && \    touch ~/.android/repositories.cfg && \    echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager --licenses && \    echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "platform-tools" && \    echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" && \    echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "platforms;$ANDROID_PLATFORM_VERSION"# Installs NodeARG NODE_VERSION=12.xRUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | bashRUN apt-get install --yes nodejs
  1. Finally, I orchestrated everything a Jenkinsfile


This is what worked in the end BUT required bare metal machine

# reactnativecommunity/react-native-android:4.0FROM reactnativecommunity/react-native-android@sha256:c3ad9b8ed5caac0718b1c1b8f10469eb75b0ac77c86143c94f9616ee46b80b4bARG IMAGE="system-images;android-31;google_apis;x86_64"RUN sdkmanager --install "${IMAGE}"RUN echo no | avdmanager create avd --name emulator_for_e2e_testing -k "${IMAGE}"ENTRYPOINT adb start-server && emulator -avd emulator_for_e2e_testing -no-audio -no-window -no-boot-anim