Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM debian

LABEL maintainer "Viktor Adam <rycus86@gmail.com>"
LABEL contributor="Chuba Oraka"

RUN apt-get update && apt-get install --no-install-recommends -y \
gcc git openssh-client less curl ca-certificates zip unzip \
libxtst-dev libxext-dev libxrender-dev libfreetype6-dev \
libfontconfig1 libgtk2.0-0 libxslt1.1 libxxf86vm1 \
lib32stdc++6 libmagic1 libpulse0 \
libglu1-mesa libgl1-mesa-dri mesa-utils libpci3 pciutils usbutils file \
&& apt-get remove openjdk* \
&& apt-get purge --auto-remove openjdk* \
&& apt-get -y install openjdk-11-jdk \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -ms /bin/bash developer \
# required for the developer user to access /dev/kvm
&& adduser developer root

ARG studio_source=https://dl.google.com/dl/android/studio/ide-zips/3.4.1.0/android-studio-ide-183.5522156-linux.tar.gz
ARG studio_local_dir=AndroidStudio3.4
ARG studio_source=https://dl.google.com/dl/android/studio/ide-zips/2020.3.1.26/android-studio-2020.3.1.26-linux.tar.gz
ARG studio_local_dir=AndroidStudio2020.3

WORKDIR /opt/android-studio

Expand Down
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ Docker container to run Android Studio (https://developer.android.com/studio/ind

## Usage

```
docker run --rm \
Run Android Studio with the files in the working directory by typing the following command:[^1]
```bash
docker run -d --rm \
--privileged \
-e DISPLAY=${DISPLAY} \
--device /dev/dri \
Expand All @@ -13,22 +14,50 @@ docker run --rm \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /dev/bus/usb:/dev/bus/usb \
-v /usr/share/X11/xkb:/usr/share/X11/xkb:ro \
-v ~/.AndroidStudio:/home/developer/.AndroidStudio \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the reason behind these changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the changes are reflective of how the Android Studio binaries are located in my local installation, e.g. -v ~/.AndroidStudio.sdk:/home/developer/Android/Sdk, so you may overlook or rename accordingly. I found some of the mounts to be unnecessary, like -v ~/.AndroidStudio:/home/developer/.AndroidStudio and -v ~/.AndroidStudio.android:/home/developer/.android. The most important volume mount is -v ~/.AndroidStudio.config:/home/developer/.config, I noticed that it makes the configuration after first startup more persistent.

-v ~/.AndroidStudio.android:/home/developer/.android \
-v ~/.AndroidStudio.java:/home/developer/.java \
-v ~/.AndroidStudio.gradle:/home/developer/.gradle \
-v ~/.AndroidStudio.sdk:/home/developer/Android/Sdk \
-v ~/Project:/home/developer/Project \
--name androidstudio-$(head -c 4 /dev/urandom | xxd -p)-$(date +'%Y%m%d-%H%M%S') \
rycus86/androidstudio:3.4
-v ~/.AndroidStudio.config:/home/developer/.config \
Copy link
Author

@ChubaOraka ChubaOraka Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line makes the initial configuration of the IDE persistent across restarts.

  -v ~/.AndroidStudio.config:/home/developer/.config \

-v ~/.gradle:/home/developer/.gradle \
-v ~/Android/:/home/developer/Android/Sdk \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use your own local directory names

Suggested change
-v ~/Android/:/home/developer/Android/Sdk \
-v ~/.AndroidStudio.sdk:/home/developer/Android/Sdk \

-v "$PWD:/home/developer/Project" \
--name androidstudio-$(head -c 4 /dev/urandom | xxd -p)-$(date +'%Y%m%d-%H%M%S') \
chubaoraka/docker-androidstudio
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to point this at your DockerHub account?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because I uploaded the Arctic Fox image on my account.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'd perhaps propose archiving this repo with some pointers to your repo if you'd be interested in maintaining this image? I no longer do Android dev, so it's unlikely I'll bump this often...

What do you think? If you're happy with that, perhaps replace this PR with one that changes the Readme only to clearly point to your repo, and we could get that in (and then I could archive this repo)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

```

Explanation:

- `--privileged` - to have access to USB devices connected to the host .AndroidStudio* folders to keep the data on the host between different instances (like SDK tools, AVDs, etc.)
- Local project directories need to be mounted into the container
- The name can be anything - I used something random to be able to start multiple instances if needed
- The `DISPLAY` variable has to be set before running the previous `docker run ...` command withn one of the following commands:[^2]

>```bash
>export DISPLAY=host.docker.internal$SCREEN
>```

>or

>```bash
>export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')$SCREEN
>```

>or

>```bash
>export DISPLAY=$(ip route | grep default | awk '{print $3}')$SCREEN
>```

- The `SCREEN` variable above depends on the platform on which the command is run. It can be set a using command similar to one of the following (the actual integer value after the colon may defer depending on your setup):


>```bash
>SCREEN=:0 # Linux
>SCREEN=:0 # WSL on Windows with Xming installed
>SCREEN=:0.0 # WSL on Windows with VcXsrv installed
>```

## Notes

The container has Git installed. It also has Kotlin installed. The container runs as a non-root user but that user is part of the root group to be able to use KVM. When Android Studio starts for the first time it might display a warning about KVM not working but it does actually.

[^1]: More about setting the `DISPLAY` variable further in the document.
[^2]: More about setting the `SCREEN` variable further in the document.