From d9ab242e360182d0c530fa5e90de12e6c24ed977 Mon Sep 17 00:00:00 2001 From: mingchik Date: Tue, 14 Dec 2021 01:35:21 -0700 Subject: [PATCH] add android headless simulator (#60) --- .../Dockerfile.android_headless_emulator | 43 +++++++++++++++++++ cirque/resources/android_headless_init.sh | 33 ++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 cirque/resources/Dockerfile.android_headless_emulator create mode 100755 cirque/resources/android_headless_init.sh diff --git a/cirque/resources/Dockerfile.android_headless_emulator b/cirque/resources/Dockerfile.android_headless_emulator new file mode 100644 index 0000000..72f082d --- /dev/null +++ b/cirque/resources/Dockerfile.android_headless_emulator @@ -0,0 +1,43 @@ +FROM ubuntu:18.04 + +ARG TZ +ENV TIMEZONE=${TZ:-America/Los_Angeles} +USER root + +RUN apt-get update && apt-get install -y \ + dnsmasq \ + iproute2 \ + net-tools \ + iputils-ping \ + openjdk-8-jdk \ + tzdata \ + wget \ + unzip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone + +RUN wget 'https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip' -P /tmp && \ + unzip -d /opt/android /tmp/sdk-tools-linux-4333796.zip && \ + rm -v /tmp/sdk-tools-linux-4333796.zip && \ + yes Y | /opt/android/tools/bin/sdkmanager --install \ + "platform-tools" \ + "system-images;android-30;google_apis;x86" \ + "platforms;android-30" \ + "emulator" && \ + yes Y | /opt/android/tools/bin/sdkmanager --licenses && \ + echo "no" | /opt/android/tools/bin/avdmanager --verbose create avd --force \ + --name "emulator" \ + --device "pixel" \ + --package "system-images;android-30;google_apis;x86" \ + --tag "google_apis" \ + --abi "x86" + +COPY android_headless_init.sh / + +ENV ANDROID_HOME=/opt/android +ENV PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH +ENV LD_LIBRARY_PATH=$ANDROID_HOME/emulator/lib64:$ANDROID_HOME/emulator/lib64/qt/lib:$LD_LIBRARY_PATH +ENV QT_DEBUG_PLUGINS=1 + +ENTRYPOINT ["/android_headless_init.sh"] diff --git a/cirque/resources/android_headless_init.sh b/cirque/resources/android_headless_init.sh new file mode 100755 index 0000000..e2b13d7 --- /dev/null +++ b/cirque/resources/android_headless_init.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +ip_addr=`ifconfig eth0 | awk '/inet / {print $2}'` +base_ipaddr=`echo $ip_addr | cut -d"." -f1-3` +network=$base_ipaddr.0 + +ip tuntap add dev tap0 mode tap user $(whoami) +ip link add br0 type bridge +ip link set tap0 master br0 +ip link set eth0 master br0 +ip addr flush dev eth0 +ip link set tap0 up +ip link set br0 up +ifconfig eth0 0.0.0.0 promisc +ifconfig tap0 0.0.0.0 promisc +ip addr add $ip_addr/24 dev br0 +route add default gw $base_ipaddr.1 br0 +sysctl -w net.ipv4.ip_forward=1 + +cat <> /etc/dnsmasq.conf +interface=br0 +bind-interfaces +dhcp-option=3,$base_ipaddr.1 +dhcp-option=6,8.8.8.8,8.8.4.4 +dhcp-range=$base_ipaddr.5,$base_ipaddr.9,255.255.255.0,12h +no-hosts +EOT + +/etc/init.d/dnsmasq restart + +emulator -avd emulator -no-boot-anim -no-audio -net-tap tap0 -no-accel -no-window + +sleep infinity