From ad032ac4fa832143d7ae2ffc6c7fc7bfa6d82e6b Mon Sep 17 00:00:00 2001 From: Chuba Oraka Date: Fri, 15 Apr 2022 14:47:48 -0400 Subject: [PATCH 1/5] Modifying the `docker run ...` commmand The persistency of the Android Studio configuration is improved by mounting /home/developer/.config Source: Use volumes | Docker Documentation https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6e42e6b..32d2ebc 100644 --- a/README.md +++ b/README.md @@ -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: +```bash +docker run -d --rm \ --privileged \ -e DISPLAY=${DISPLAY} \ --device /dev/dri \ @@ -13,14 +14,13 @@ 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 \ - -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 \ + -v ~/.gradle:/home/developer/.gradle \ + -v ~/Android/:/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:3.4.1.0 ``` Explanation: From c494407c99f359ade8ccc28fad5e4a7a280517bd Mon Sep 17 00:00:00 2001 From: Chuba Oraka Date: Fri, 15 Apr 2022 14:47:48 -0400 Subject: [PATCH 2/5] Including instructions on setting the `DISPLAY` environmental variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sources: Understanding linux DISPLAY variable - Stack Overflow https://stackoverflow.com/questions/20947681/understanding-linux-display-variable https://stackoverflow.com/a/20947791 https://stackoverflow.com/questions/20947681/understanding-linux-display-variable/20947791#20947791 X Windows broken on fast ring WSL2 (?) · Issue #5106 · microsoft/WSL · GitHub https://github.com/microsoft/WSL/issues/5106 https://github.com/microsoft/WSL/issues/5106#issuecomment-616247713 https://github.com/microsoft/WSL/issues/5106#issuecomment-616278850 WSL2 GUI X-Server Using VcXsrv - Shogan.tech https://www.shogan.co.uk/how-tos/wsl2-gui-x-server-using-vcxsrv/ Xming X Server for Windows - Trouble? http://www.straightrunning.com/xmingnotes/trouble.php --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32d2ebc..f53cdb1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Docker container to run Android Studio (https://developer.android.com/studio/ind ## Usage -Run Android Studio with the files in the working directory by typing the following command: +Run Android Studio with the files in the working directory by typing the following command:[^1] ```bash docker run -d --rm \ --privileged \ @@ -28,7 +28,36 @@ 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. From 0e27e89b7099c40b79803e2a1d37148270b5ab67 Mon Sep 17 00:00:00 2001 From: Chuba Oraka Date: Sat, 16 Apr 2022 14:42:07 -0400 Subject: [PATCH 3/5] Beginning upgrade to Android Studio Arctic Fox (2020.3.1) Patch 4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The source URL now points to a different version of Android Studio. The URL from the Android Studio download archives website is slightly different, the line below would also have been valid: `ARG studio_source=https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2020.3.1.26/android-studio-2020.3.1.26-linux.tar.gz` Sources: Android Studio download archives  |  Android Developers https://developer.android.com/studio/archive --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 27a360d..590511f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ # 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 From e6e9de38c12170049502cd4e34b24011907ef883 Mon Sep 17 00:00:00 2001 From: Chuba Oraka Date: Sat, 16 Apr 2022 15:05:30 -0400 Subject: [PATCH 4/5] BugFix: Update Java from 1.8 to 11 To comply with compatibility requirements for running Android Studio Arctic Fox (2020.3.1) Patch 4, Java needs to be upgraded in the Docker image Error Message (Resolved): java - Upgrading from openJDK 8 to openJDK 11 - Stack Overflow Sources: Android Studio Error "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8" - Stack Overflow https://stackoverflow.com/questions/66980512/android-studio-error-android-gradle-plugin-requires-java-11-to-run-you-are-cur java - Upgrading from openJDK 8 to openJDK 11 - Stack Overflow https://stackoverflow.com/questions/63699194/upgrading-from-openjdk-8-to-openjdk-11 https://stackoverflow.com/a/63699326 https://stackoverflow.com/questions/63699194/upgrading-from-openjdk-8-to-openjdk-11/63699326#63699326 --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 590511f..16a9b68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ 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 From 746aa1ddad03dfc9d3614f17793d052794f1e22d Mon Sep 17 00:00:00 2001 From: Viktor Adam Date: Fri, 31 May 2019 12:35:50 +0000 Subject: [PATCH 5/5] Updating instructions on running the container and noting my contribution --- Dockerfile | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 16a9b68..e6dc8eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM debian LABEL maintainer "Viktor Adam " +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 \ diff --git a/README.md b/README.md index f53cdb1..f6d41a9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ docker run -d --rm \ -v ~/Android/:/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:3.4.1.0 +chubaoraka/docker-androidstudio ``` Explanation: