Skip to content

Commit

Permalink
add android headless simulator (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingchik authored Dec 14, 2021
1 parent 262ea77 commit d9ab242
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cirque/resources/Dockerfile.android_headless_emulator
Original file line number Diff line number Diff line change
@@ -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"]
33 changes: 33 additions & 0 deletions cirque/resources/android_headless_init.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOT >> /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

0 comments on commit d9ab242

Please sign in to comment.