Skip to content

Instantly share code, notes, and snippets.

@tiann
Created January 20, 2022 05:32
Show Gist options
  • Save tiann/4d2180875dd7a12bc83d3231dfed6298 to your computer and use it in GitHub Desktop.
Save tiann/4d2180875dd7a12bc83d3231dfed6298 to your computer and use it in GitHub Desktop.
Build AOSP with docker using Ubuntu
FROM ubuntu:14.04
ARG userid
ARG groupid
ARG username
RUN apt-get update && apt-get install -y git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip python openjdk-7-jdk
RUN curl -o jdk8.tgz https://android.googlesource.com/platform/prebuilts/jdk/jdk8/+archive/master.tar.gz \
&& tar -zxf jdk8.tgz linux-x86 \
&& mv linux-x86 /usr/lib/jvm/java-8-openjdk-amd64 \
&& rm -rf jdk8.tgz
RUN curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo \
&& chmod a+x /usr/local/bin/repo
RUN groupadd -g $groupid $username \
&& useradd -m -u $userid -g $groupid $username \
&& echo $username >/root/username \
&& echo "export USER="$username >>/home/$username/.gitconfig
COPY gitconfig /home/$username/.gitconfig
RUN chown $userid:$groupid /home/$username/.gitconfig
ENV HOME=/home/$username
ENV USER=$username
ENTRYPOINT chroot --userspec=$(cat /root/username):$(cat /root/username) / /bin/bash -i
FROM ubuntu:16.04
ARG userid
ARG groupid
ARG username
RUN apt-get update && apt-get install -y git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip openjdk-8-jdk python bc
RUN curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo \
&& chmod a+x /usr/local/bin/repo
RUN groupadd -g $groupid $username \
&& useradd -m -u $userid -g $groupid $username \
&& echo $username >/root/username \
&& echo "export USER="$username >>/home/$username/.gitconfig
COPY gitconfig /home/$username/.gitconfig
RUN chown $userid:$groupid /home/$username/.gitconfig
ENV HOME=/home/$username
ENV USER=$username
ENTRYPOINT chroot --userspec=$(cat /root/username):$(cat /root/username) / /bin/bash -i
@tiann
Copy link
Author

tiann commented Jan 20, 2022

The Dockerfile in this directory sets up an Ubuntu Trusty image ready to build a variety of Android branches (>= Lollipop). It's particulary useful to build older branches that required 14.04 if you've upgraded to something newer.

First, build the image:

Copy your host gitconfig, or create a stripped down version

$ cp ~/.gitconfig gitconfig
$ docker build --build-arg userid=$(id -u) --build-arg groupid=$(id -g) --build-arg username=$(id -un) -t android-build-trusty .
Then you can start up new instances with:

$ docker run -it --rm -v $ANDROID_BUILD_TOP:/src android-build-trusty

cd /src; source build/envsetup.sh
lunch aosp_arm-eng
m -j50

reference: http://aospxref.com/android-11.0.0_r21/xref/build/tools/docker/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment