├── Makefile ├── entrypoint.sh ├── LICENSE ├── README.md └── Dockerfile /Makefile: -------------------------------------------------------------------------------- 1 | DOCKER = docker 2 | IMAGE = divadsn/android-build 3 | TAG = $(shell git rev-parse --abbrev-ref HEAD) 4 | 5 | build: Dockerfile 6 | $(DOCKER) build -t $(IMAGE):$(TAG) . 7 | 8 | latest: Dockerfile 9 | $(DOCKER) build -t $(IMAGE):latest . 10 | 11 | .PHONY: build 12 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Modify this here to automate the building process. 5 | # This can include auto syncing the manifest, cleaning unused makefiles or setting up ccache. 6 | if [ ! "$(ccache -s|grep -E 'max cache size'|awk '{print $4}')" = "120.0" ] 7 | then 8 | ccache -M 120G 9 | fi 10 | 11 | exec bash -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 David Sn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-android-build 2 | A all-in-one Docker ready image to build Android locally. Requires Linux or macOS with Docker. 3 | 4 | ### Deploying and running our container 5 | To create and run our container, we can use the following command syntax: 6 | ``` 7 | docker run -it --name --hostname -v :/repo -v :/tmp/ccache --rm divadsn/android-build:latest 8 | ``` 9 | 10 | Now you are probably wondering what those arguments mean, right? Let me explain. 11 | 12 | | Argument | Description | 13 | |---------------------------|-----------------------------------------------------------------| 14 | | `-it` | Allows docker to allocate a tty for the container process | 15 | | `--name ` | Identification name for our container | 16 | | `--hostname ` | Sets the specified name as containers hostname | 17 | | `-v src:dest` | Mounts `src` path on host or volume to `dest` path on container | 18 | | `--rm` | Cleans up the container and removes after exit | 19 | 20 | Example when using volumes: 21 | ``` 22 | docker run -it --name build --hostname buildbot -v build_repo:/repo -v build_ccache:/tmp/ccache --rm divadsn/android-build:latest 23 | ``` 24 | 25 | Example when using bind mounts: 26 | ``` 27 | docker run -it --name build --hostname buildbot -v /home/${USER}/build/repo:/repo -v /home/${USER}/build/ccache:/tmp/ccache --rm divadsn/android-build:latest 28 | ``` 29 | 30 | After the container has been created, you should be greeted with a message about sudo access and you should be able to execute commands as user `docker` in directory `/repo`. Now you can go ahead and initialize your local repository using `repo init` and sync the sources, everything is setup to be ready to use. 31 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | LABEL maintainer="David Sn " 3 | 4 | ENV DEBIAN_FRONTEND=noninteractive \ 5 | USER=docker \ 6 | USE_CCACHE=1 \ 7 | CCACHE_DIR=/tmp/ccache \ 8 | CCACHE_EXEC=/usr/bin/ccache 9 | 10 | # Install required dependencies 11 | RUN apt-get update && \ 12 | apt-get install --no-install-recommends -y \ 13 | adb autoconf automake axel bc bison build-essential \ 14 | ccache clang cmake expat fastboot flex g++ \ 15 | g++-multilib gawk gcc gcc-multilib git gnupg gperf \ 16 | htop imagemagick lib32ncurses5-dev lib32z1-dev libtinfo5 libc6-dev libcap-dev \ 17 | libexpat1-dev libgmp-dev '^liblz4-.*' '^liblzma.*' libmpc-dev libmpfr-dev libncurses5-dev \ 18 | libsdl1.2-dev libssl-dev libtool libxml2 libxml2-utils '^lzma.*' lzop \ 19 | maven ncftp ncurses-dev patch patchelf pkg-config pngcrush \ 20 | pngquant python2.7 python-all-dev re2c schedtool squashfs-tools subversion \ 21 | texinfo unzip w3m xsltproc zip zlib1g-dev lzip \ 22 | libxml-simple-perl apt-utils \ 23 | libncurses5 curl python-is-python3 sudo ssh rsync && \ 24 | apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 25 | 26 | # Install repo binary (thanks akheel) 27 | RUN curl --create-dirs -L -o /usr/local/bin/repo -O -L https://github.com/akhilnarang/repo/raw/master/repo && \ 28 | chmod a+x /usr/local/bin/repo 29 | 30 | # Create seperate build user 31 | RUN groupadd -g 1000 -r ${USER} && \ 32 | useradd -u 1000 --create-home -r -g ${USER} ${USER} && \ 33 | mkdir -p /tmp/ccache /repo && \ 34 | chown -R ${USER}: /tmp/ccache /repo 35 | 36 | # Allow sudo without password for build user 37 | RUN echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-docker-build && \ 38 | usermod -aG sudo ${USER} 39 | 40 | # Setup volumes for persistent data 41 | USER ${USER} 42 | VOLUME ["/tmp/ccache", "/repo"] 43 | 44 | # Create gitconfig for build user 45 | RUN git config --global user.name ${USER} && git config --global user.email ${USER}@${HOSTNAME}.local && \ 46 | git config --global color.ui auto 47 | 48 | # Work in the build directory, repo is expected to be init'd here 49 | WORKDIR /repo 50 | 51 | # This is where the magic happens~ 52 | ENTRYPOINT ["/bin/bash"] 53 | --------------------------------------------------------------------------------