Android Open Source Project Docker Build Environment
Minimal build environment for AOSP with handy automation wrapper scripts.
Developers can use the Docker image to build directly while running the
distribution of choice, without having to worry about breaking the delicate
AOSP build due to package updates as is sometimes common on bleeding edge
rolling distributions like Arch Linux.
Production build servers and integration test servers should also use the same
Docker image and environment. This eliminates most surprise breakages by
by empowering developers and production builds to use the exact same
environment. The devs will catch the issues with build environment first.
This works well on Linux. Running this via
boot2docker (and friends) will
result in a very painful performacne hit due to VirtualBox's
folder service which works terrible for very large file shares like AOSP.
It might work, but consider yourself warned. If you're aware of another way to
get around this, send a pull request!
For the terribly impatient.
- Make a directory to work and go there.
- Export the current directory as the persistent file store for the
Run a self contained build script, which does:
- Attempts to fetch the
aospwrapper if not found locally.
- Runs the
aospwrapper with an extra argument for the docker binary and
hints to the same script that when run later it's running in the docker
- The aosp wrapper then does it's magic which consists of fetching the
docker image if not found and forms all the necessary docker run
- The docker container runs the other half the build script which
initializes the repo, fetches all source code, and builds.
In parallel you are expected to be drinking because I save you some time.
mkdir nougat ; cd nougat export AOSP_VOL=$PWD curl -O https://raw.githubusercontent.com/kylemanna/docker-aosp/master/tests/build-nougat.sh bash ./build-nougat.sh
This takes about 2 hours to download and build on i5-2500k with 100Mb/s network connection.
- Attempts to fetch the
How it Works
The Dockerfile contains the minimal packages necessary to build Android based
on the main Ubuntu base image.
aosp wrapper is a simple wrapper to simplify invocation of the Docker
image. The wrapper ensures that a volume mount is accessible and has valid
permissions for the
aosp user in the Docker image (this unfortunately
requires sudo). It also forwards an ssh-agent in to the Docker container
so that private git repositories can be accessed if needed.
The intention is to use
aosp to prefix all commands one would run in the
Docker container. For example to run
repo sync in the Docker container:
aosp repo sync -j2
aosp wrapper doesn't work well with setting up environments, but with
some bash magic, this can be side stepped with short little scripts. See
tests/build-nougat.sh for an example of a complete fetch and build of AOSP.
A Docker Compose file is provided in the root of this repository, you can tweak it as need be:
version: "2" services: aosp: image: kylemanna/aosp:latest volumes: - /tmp/ccache:/ccache - ~/aosp:/aosp
docker-compose run --rm aosp repo sync -j4 -- your android build directory will be in
There are some known issues with using Docker Toolbox on macOS and current
virtualization technologies resulting in unusual user ID assignments and very
poor performing virtualization file sharing implementations with things like
VirtualBox. It's recommended to run this image completely in a virtual machine
with enough space to fit the entire build (80GB+) as opposed to mapping the
build to the local macOS file system via VirtualBox or similar.
- Android Kitkat
- Android Lollipop
- Android Marshmallow
- Android Nougat
lxzhMac:tests a1239848066$ export AOSP_VOL=/Volume/Android/
lxzhMac:tests a1239848066$ sudo bash ./build-nougat.sh
- '[' '' = docker ']'
- args='bash run.sh docker'
+++ dirname ./build-nougat.sh
++ cd .
++ pwd -P
++ basename ./build-nougat.sh
- export 'AOSP_EXTRA_ARGS=-v /Volumes/Android/aosp/tests/build-nougat.sh:/usr/local/bin/run.sh:ro'
- AOSP_EXTRA_ARGS='-v /Volumes/Android/aosp/tests/build-nougat.sh:/usr/local/bin/run.sh:ro'
- export AOSP_IMAGE=kylemanna/aosp:7.0-nougat
- '[' -n '' ']'
- '[' -x ../utils/aosp ']'
- ../utils/aosp bash run.sh docker
aosp: Checking if /Users/a1239848066/aosp-root/aosp exists
aosp: Checking if /Users/a1239848066/aosp-root/aosp exists - ok
aosp: Checking if /Users/a1239848066/aosp-root/ccache exists
aosp: Checking if /Users/a1239848066/aosp-root/ccache exists - ok
docker_entrypoint: Creating user UID/GID [1000/1000]
docker_entrypoint: Creating user UID/GID [1000/1000] - done
docker_entrypoint: Copying .gitconfig and .ssh/config to new user home
docker_entrypoint: Copying .gitconfig and .ssh/config to new user home - done
docker_entrypoint: Creating /tmp/ccache and /aosp directory
chown: changing ownership of '/tmp/ccache': Operation not permitted
chown: changing ownership of '/aosp': Operation not permitted
How can i do with this error?
thanks for the work! But this will only build image for emulator, right? To build for 6P, we need to change the wrapper script.