These Docker and Vagrant (and supporting) files allow one to create a fully self-contained Android development environment. All the necessary software is downloaded and configured, making set-up easy.
Within this (Fedora 21) environment, the following features are available:
- Android Studio (1.1.0), with IdeaVIM plugin (hey, we've all got our editing biases!)
- Java downloaded and installed (Currently, Oracle Java 8u45)
- Accelerated Android Emulator (assuming VTX is available)
- Access to connected Android devices through the container
- All the necessary Fedora packages for the above
- All GUIs are run leveraging your local X server (ie, no VNC'ing or ssh'ing to run programs like Android Studio).
- The environment uses Docker volumes to map a directory that will be used as the dev user's home directory. It's in this directory where you can store persistent data (Android studio settings, code, etc).
NOTE: Vagrant makes it easy to package up extra Docker configuration. It's also supposed to allow you to set up Docker under non-Linux environments. However, I have not tested this. (See Limitations section.)
-
Download and install Vagrant. Note: Tested with 1.7.2
-
Download and install Docker. (Make sure the docker service is running) Note: Tested with 1.6.0-2
-
Retrieve the docker-dev-android files.
https://github.com/hasuf/docker-dev-android.git
-
There are some things you might want to consider before launching Vagrant:
-
User and Group ID. To make things easy on you and allow you to interoperate with files both inside and outside the container, you might want to edit the id's of the user and its
group. ie, in the Dockerfile, edit the lines:# Create user and group for devuser using specific id's export GROUPID=1000 ; export USERID=600 \
so that the id's for the group and user match your own in your local environment. You can determine your own user and group id by running the following commands in your local environment:
$ # determine my user id $ id -u 681 $ # determine my group id $ id -g 1048
Replace the 1000 and 600 with your own group id and user id, respectively. eg (from the above example):
# Create user and group for devuser using specific id's export GROUPID=1048 ; export USERID=681 \
Once this is done, anytime you edit files in the container, you'll by default have the same ownership as your normal user outside the container.
-
DEVDIR. Determine where, on your filesystem, you want to designate the dev user's home directory. eg, you may want to designate
/home/myaccount/work
as your android development path. This results in the ability to persist data between your local environment and the container. NOTE that the path must already exist. -
Give you permission for the containerized GUIs to access your X server:
$ xhost +local:
(You might want to consider adding that to your .bashrc file.)
-
Launch Vagrant. The Vagrantfile requires setting that the DEVDIR be passed as an environment variable. If DEVDIR is not set, you'll get an error.
For example:
sudo DEVDIR=/home/myaccount/work vagrant up
Note, that on first launch, when Docker needs to set up the container, setup can take tens of minutes. However, after that, starting up the container with Vagrant should be quick.
-
When you fire up the Docker environment, and after all the software is downloaded, installed, and configured (it will take a while to download and configure everything), you're presented with a simple launcher that allows you to either start up Android Studio, launch a terminal window (from within the container's context), or exit the container.
You can launch as many terminals as you like, but you can only launch the Android Studio once.
The launcher is just an XDialog running in a loop. Selecting anything besides Exit will bring the launcher up again. Just minimize it to get it out of the way.
Exiting will cause the Docker session to end (therefore, it's a good idea to make sure you don't have any processes like Android Studio with unsaved data).
A Note on the Terminal Just for kicks, I install and use Terminology for the containerized terminal. (For one, it helps me distinguish between my regular Konsole terminal icons and the container-based Terminology ones.) If you prefer using a different terminal emulator, change these lines in the Dockerfile to use your favorite terminal program instead of terminology:
# install a good terminal
terminology \
...
# give the name of the terminal program to run
CMD /usr/bin/bash /usr/local/bin/init.sh terminology
As mentioned in the introduction, one of the intents for this project was to have a single environment set up for any platform (Linux, Mac, etc). Vagrant should automatically launch Docker in a container-supported OS within VirtualBox. However, I have not tested this, nor am I yet certain how to enable things like access to an attached device. Running GUIs using X should be doable, as noted in the References section.
- Setting up a development environment using Docker and Vagrant, Blog Zenika, 2014-10-07
- Running GUI apps with Docker, Fábio Rehm, 2014-09-11
- Running GUIs on OSX
- How to run a Linux GUI application on OSX using Docker, Tim Sutton, 2015-04-14
- Fiji Docker Docs, "On OSX" Section
- Setting up acceleration for Android emulator
- GitHub project: qemu-docker, Kevin Wallace
- GitHub project: jenkins-android-docker, Clément Plantier