You may want to consider using Android Studio snap package instead of this project.
- The Linux version of Android Studio is tested by Google on Ubuntu 14.04 LTS.
To be on the safe side, you'll want to run it on Ubuntu as well, even if you do the rest of your work using a different Linux distribution.
Given this, I have good experience running Android Studio on Ubuntu 18.04. - Android Studio also requires a GNOME or KDE desktop, and you may want to use a more lightweight desktop for other work.
- You may need different versions of JDK or other packages for your Android Studio work.
The scripts in the repository build two Docker images. One is for running Android Studio, and the other - for running Android Cordova builds.
In the following description, yourdir
is where you install androiddocker
.
Once you have installed androiddocker in your system, yourdir
has three subdirectories as follows.
yourdir/androiddocker/androiddocker
- files for building the Docker images and containers as well as running them and performing various operations. This subdirectory is not visible from inside the containers.yourdir/androiddocker/androidstudio
- is where the Android Studio files are located. This subdirectory is visible from inside the containers as/AndroidStudio
.yourdir/androiddocker/androidprojects
- is for your projects. This subdirectory is visible from inside the containers as/projects
.
You need to avoid soft links to files outside ofyourdir/androiddocker/androidprojects
because it would make those files inaccessible from inside the containers.
You may want to have a separate sub-subdirectory for each project.
- The containers are meant to run only on the same machine on which the image was built. This is in contrast to the general Docker philosophy.
- The containers are meant to access Android Studio and your project files from mounted host system directories. This design allows you to upgrade Android Studio without having to freeze images, as well as letting you use your favorite text editor to edit your project files from outside of the containers. You also won't lose data if you have to rebuild containers.
In order for the Android Emulator in Android Studio to run at hardware accelerated speeds, you need to ensure that your system has libvirt packages installed and that libvirtd daemon is running.
- In Debian based systems, install using:
sudo apt-get install qemu-kvm libvirt-daemon-system bridge-utils
sudo adduser `id -un` libvirt
sudo adduser `id -un` libvirt-qemu
sudo adduser `id -un` kvm
- Verify that libvirt is working:
virsh -c qemu:///system list
- Ensure that the libvirtd daemon is running:
systemctl status libvirtd
.
If it is not running, enable it:sudo systemctl enable libvirtd
. - The following is not related to Android Emulator but will allow Android Studio to work with real devices connected to your computer via USB.
If necessary, edit the fileyourdir/androiddocker/androiddocker/51-android.rules
and add rules covering your devices (lsusb
can be used to find your devices' vendor ID and product ID).
Ensure that you have the rules inyourdir/androiddocker/androiddocker/51-android.rules
defined also in a file in your host system's/etc/udev/rules.d
. You may accomplish this bysudo cat yourdir/androiddocker/androiddocker/51-android.rules >> /etc/udev/rules.d/51-android.rules
.
- Clone or unzip this repository (tddpirate/androiddocker) into a directory in your computer. This directory is referred to below (and above) as
yourdir
. - Download Android Studio for Linux from http://developer.android.com/sdk/index.html and save it in another directory (referred to below as
asdownload
). cd yourdir/androiddocker/androiddocker
./build_androidstudio_image.sh asdownload/android-studio-ide-*-linux.zip
- If this is not the first time you are installing, you will be asked if you want to rebuild the contents of
yourdir/androiddocker/androidstudio/home
which contains the Android Studio files. Usually you'll not want to rebuild the subdirectory's contents, so enterno
and hit ENTER. - The script auto-detects your user's uid and gid in the host system, and also the gids of the special users
video
andkvm
. By default, the user in the container (developer
) is given your uid and gid, but you have the option of selecting different uid and/or gid fordeveloper
inside the container.
Therefore, the next question is whether you want to use different uid/gid for the user in the container.
Enterno
and hit ENTER. - When asked for image name, accept the default (
tddpirate/androidstudio:1.4
) by hitting ENTER. - Your computer will need few minutes to build the image.
- When image building is completed, you'll see the message
Successfully tagged tddpirate/androidstudio:1.4
. - You'll be prompted for a container name. Accept the default (
android-studio
) by hitting ENTER. - Few moments later, Android Studio will start. Configure it to your taste and start working.
- When you exit the Android Studio, the corresponding container stops execution.
- You can restart the container using:
yourdir/androiddocker/androiddocker/start_androidstudio.sh
. You may want to define a short alias for this command.
If you want to build the Android Cordova container:
- Exit the Android Studio, closing the android-studio container.
cd yourdir/androiddocker/androiddocker
if you are not already at the correct directory../build_androidcordova_image.sh
- A list of existing Android Studio images is shown (normally, there will be only one image) followed by request to confirm usage of the selected image. Hit ENTER.
- You will be asked to select a name for the new image (Android Cordova). Accept the default by hitting ENTER.
- Then you'll be prompted for a container name. Accept the default of
android-cordova
by hitting ENTER. - The image and container build process will last for several seconds.
- When the image and container build process ends, the container is started, providing you with a command line where you run the various
cordova
commands. - Create your Cordova projects in subdirectories of
/projects
(corresponding toyourdir/androiddocker/androidprojects
outside the container).
If the container was stopped, you can restart it by means of yourdir/androiddocker/androiddocker/start_androidcordova.sh
.
Normally, the Android Studio container stops running when you exit Android Studio. This behavior is problematic when upgrading Android Studio and the upgrade process requires it to close.
Therefore, the Android Studio container supports the following procedure to keep the container running as necessary to finish Android Studio upgrade.
docker exec -it android-studio /bin/bash
- Outside of the container:
touch yourdir/androiddocker/androidprojects/upgrade
(or alternativelytouch /projects/upgrade
inside the container). - Exit Android Studio.
- Start the Android Studio upgrade process.
- Once the upgrade process ends, execute the command
ps ax
and find the PID of the process runningtail -f /dev/null
kill $PID
to kill the above process. This will cause the container to exit.- Next time you restart the container, you'll run the new version of Android Studio.
- Debian Stretch with Docker version 17.05.0-ce, build 89658be, installed from https://apt.dockerproject.org/repo.
- Installation instructions for systems running a Linux distribution not based upon Debian.
- Installation instructions for systems without systemd.
- Fix paths to allow the Android emulator to run properly in android-cordova.
- Modify android-cordova build script to ask all questions at beginning and then run unattended.
- Fix android-cordova restart method to get it to stop as soon as the user exits it.
- Documentation was revised.
- A script file was modified to simplify instructions to run it.
- Support for running the Android Emulator in hardware accelerated speeds.
- The dockerfile for building the Android Cordova development environment now follows the actual tag of the Android Studio image.
- The image is based upon Ubuntu 18.04 instead of Ubuntu 14.04.
- Android Studio is now started from a script which optionally keeps the Docker container running after closing Android Studio when it is necessary to exit Android Studio for upgrading it.
- The Cordova support is currently broken. I will fix it when I have the time and/or need for it.
Thanks to @opyate for his work on testing the scripts and giving feedback. Thanks to all those who gave stars (12 at the time of writing) to this repository in GitHub. You gave me the encouragement to polish the project description and installation instructions.