Skip to content

Commit

Permalink
Merge pull request #4 from heralight/main
Browse files Browse the repository at this point in the history
fix accel - add docker-compose - fix keys
  • Loading branch information
HQarroum authored Feb 20, 2024
2 parents 7a3b901 + 92c5038 commit eccae59
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 57 deletions.
86 changes: 86 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
keys
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,powershell
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,powershell

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### PowerShell ###
# Exclude packaged modules
*.zip

# Exclude .NET assemblies from source
*.dll

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,powershell
52 changes: 27 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
FROM adoptopenjdk/openjdk11:alpine-jre
FROM openjdk:18-jdk-slim

ENV DEBIAN_FRONTEND noninteractive

#WORKDIR /
#=============================
# Install Dependenices
#=============================
SHELL ["/bin/bash", "-c"]

RUN apt update && apt install -y curl \
sudo wget unzip bzip2 libdrm-dev \
libxkbcommon-dev libgbm-dev libasound-dev libnss3 \
libxcursor1 libpulse-dev libxshmfence-dev \
xauth xvfb x11vnc fluxbox wmctrl libdbus-glib-1-2 socat \
virt-manager


# Docker labels.
LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
LABEL description "A Docker image allowing to run an Android emulator"
LABEL version "1.0.0"

# Installing required packages.
RUN apk update && \
apk upgrade && \
apk add --no-cache \
bash \
unzip \
wget \
libvirt-daemon \
dbus \
polkit \
socat \
virt-manager && \
# Cleanup APK.
rm -rf /tmp/* /var/tmp/* /var/cache/apk/*

# Arguments that can be overriden at build-time.
ARG INSTALL_ANDROID_SDK=1
Expand All @@ -31,15 +33,15 @@ ARG GPU_ACCELERATED=false

# Environment variables.
ENV ANDROID_SDK_ROOT=/opt/android \
ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL" \
PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}" \
API_LEVEL=$API_LEVEL \
DEVICE_ID=$DEVICE_ID \
ARCHITECTURE=$ARCHITECTURE \
ABI=${IMG_TYPE}/${ARCHITECTURE} \
GPU_ACCELERATED=$GPU_ACCELERATED \
QTWEBENGINE_DISABLE_SANDBOX=1 \
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10
ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL" \
PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}" \
API_LEVEL=$API_LEVEL \
DEVICE_ID=$DEVICE_ID \
ARCHITECTURE=$ARCHITECTURE \
ABI=${IMG_TYPE}/${ARCHITECTURE} \
GPU_ACCELERATED=$GPU_ACCELERATED \
QTWEBENGINE_DISABLE_SANDBOX=1 \
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10

# Exporting environment variables to keep in the path
# Android SDK binaries and shared libraries.
Expand All @@ -60,7 +62,7 @@ RUN mkdir /root/.android/ && \
touch /root/.android/repositories.cfg

# Exporting ADB keys.
COPY keys/* /root/.android/
#COPY keys/* /root/.android/

# The following layers will download the Android command-line tools
# to install the Android SDK, emulator and system images.
Expand Down
59 changes: 30 additions & 29 deletions Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
FROM nvidia/cuda:12.1.0-base-ubuntu22.04
FROM nvidia/cuda:12.3.1-base-ubuntu22.04

# Docker labels.
LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
LABEL description "A Docker image allowing to run an Android emulator"
LABEL version "1.1.0"
LABEL version "1.2.0"
ENV DEBIAN_FRONTEND noninteractive

# Installing required packages.
RUN apt update -y && \
DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
bash \
unzip \
wget \
libvirt-daemon \
dbus \
openjdk-11-jdk \
virt-manager \
libvulkan1 \
xvfb \
libgl1-mesa-glx \
libgl1-mesa-dri \
socat \
iproute2 && \
rm -rf /var/lib/apt/lists/*
apt install -y --no-install-recommends \
bash \
unzip \
wget \
libvirt-daemon \
dbus \
openjdk-18-jre-headless \
virt-manager \
libvulkan1 \
xvfb \
libgl1-mesa-glx \
libgl1-mesa-dri \
socat \
htop \
iproute2 && \
rm -rf /var/lib/apt/lists/*

# Arguments that can be overriden at build-time.
ARG INSTALL_ANDROID_SDK=1
Expand All @@ -34,15 +36,15 @@ ARG GPU_ACCELERATED=true

# Environment variables.
ENV ANDROID_SDK_ROOT=/opt/android \
ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL" \
PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}" \
API_LEVEL=$API_LEVEL \
DEVICE_ID=$DEVICE_ID \
ARCHITECTURE=$ARCHITECTURE \
ABI=${IMG_TYPE}/${ARCHITECTURE} \
GPU_ACCELERATED=$GPU_ACCELERATED \
QTWEBENGINE_DISABLE_SANDBOX=1 \
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10
ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL" \
PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}" \
API_LEVEL=$API_LEVEL \
DEVICE_ID=$DEVICE_ID \
ARCHITECTURE=$ARCHITECTURE \
ABI=${IMG_TYPE}/${ARCHITECTURE} \
GPU_ACCELERATED=$GPU_ACCELERATED \
QTWEBENGINE_DISABLE_SANDBOX=1 \
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10

# Exporting environment variables for keeping in the path
# Android SDK binaries and shared libraries.
Expand All @@ -60,10 +62,10 @@ EXPOSE 5554 5555

# Initializing the required directories.
RUN mkdir /root/.android/ && \
touch /root/.android/repositories.cfg
touch /root/.android/repositories.cfg

# Exporting ADB keys.
COPY keys/* /root/.android/
#COPY keys/* /root/.android/

# The following layers will download the Android command-line tools
# to install the Android SDK, emulator and system images.
Expand All @@ -76,6 +78,5 @@ RUN /opt/install-sdk.sh
COPY scripts/start-emulator.sh /opt/
COPY scripts/emulator-monitoring.sh /opt/
RUN chmod +x /opt/*.sh

# Set the entrypoint
ENTRYPOINT ["/opt/start-emulator.sh"]
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,38 @@ Without SDK and emulator | 414 MB | 138 MB |

By default, a build will bundle the Android SDK, platform tools and emulator with the image.

with docker-compose:

```bash
docker compose up android-emulator
```

or with GPU acceleration
```bash
docker compose up android-emulator-cuda
```

or for example with GPU acceleration and google playstore
```bash
docker compose up android-emulator-cuda-store
```

with only docker


```bash
docker build -t android-emulator .
```

## Keys

To run google_apis_playstore image, you need to have same adbkey between emulator and client.

You can generate one by running `adb keygen adbkey`, that generates 2 files - adbkey and adbkey.pub.

override them inside ./keys directory.


### Running the container

Once the image is built, you can mount your KVM driver on the container and expose its ADB port.
Expand Down Expand Up @@ -113,6 +141,17 @@ docker build \
--tag android-emulator .
```

### Variables

#### Disable animation
DISABLE_ANIMATION=false

#### Disable hidden policy
DISABLE_HIDDEN_POLICY=true

#### skip adb authentication
SKIP_AUTH=false

### Mount an external drive in the container

It might be sometimes useful to have the entire Android SDK folder outside of the container (stored on a shared distributed filesystem such as NFS for example), to significantly reduce the size and the build time of the image.
Expand Down
Loading

0 comments on commit eccae59

Please sign in to comment.