Local environment: macOS 10.12.5 Working directory: ~/android-docker/
I. Preparing case-sensitive disk images
-
Create a disk image
First, use the following command to view disk information.diskutil info /
If the File System Personality of disk information is Case-sensitive Journaled HFS+, then the current file system is case-sensitive and does not need to create a disk image. Otherwise, execute the order:
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 100g ~/android-docker/android.dmg
Create a case-sensitive disk image of 100g in the current directory. The official android document recommends creating a 40g disk image, which is not enough. It suggests creating a 100g disk image. If you want to change the image size after creating the image, you can execute the following command.
hdiutil resize -size <new-size-you-want>g ~/android-docker/android.dmg.sparseimage
-
Mount disk image
implementhdiutil attach ~/android-docker/android.dmg.sparseimage -mountpoint ~/android-docker/android-fs
Mount ~/android-docker/android.dmg.sparseimage to ~/android-docker/android-fs.
implementhdiutil detach ~/android-docker/android-fs
Unload the disk image.
In order to facilitate operation, it is recommended that you add the functions of mounting and unloading to bash. Add the following code at the end of the ~/.bash_profile file:# mount the android file image function mountAndroid { hdiutil attach ${1} -mountpoint ${2}; } # unmount the android file image function umountAndroid() { hdiutil detach ${1}; }
Implementation:
source ~/.bash_profile
Make the amendment effective. Now it can be executed
mountAndroid ~/android-docker/android.dmg.sparseimage ~/android-docker/android-fs/
To mount the image; execute.
umountAndroid ~/android-docker/android-fs/
To uninstall the image.
Download AOSP source code
-
Download repo tools:
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo chmod +x repo
repo will try to access the official git source to update itself during its operation. It is recommended to use tuna's mirror source to update itself. Copy the following into your ~/. bash_profile
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
-
Enter ~/android-docker/android-fs/, create a working directory, and then execute the following commands under the working directory to initialize the warehouse.
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android_4.4.4_r1
I'm following version 4.4.4_r1.
3. Building Docker Environment
-
Download and install docker
Download and install docker on the official website of docker. These are all foolish operations, so don't introduce them much. The version I downloaded and installed is:Version 17.03.1-ce-mac12 (17661) Channel: stable d1db12684b
-
Building docker image
Start the docker (double-click the icon with the mouse), then download the image of ubuntu 12.04 (officially recommended Android 2.3.x (Gingerbread) - Android 5.x (Lollipop) compiled using this version).docker pull ubuntu:12.04
Create the directory ~/android-docker/aosp-build/, and create a file named Dockerfile under that directory, which reads as follows:
FROM ubuntu:12.04 ADD sources.list /etc/apt/sources.list ENV DEBIAN_FRONTEND noninteractive RUN apt-get -qq update RUN apt-get install -y --no-install-recommends apt-utils RUN apt-get install -y build-essential g++-multilib RUN apt-get install -y file git gnupg flex bison gperf zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 RUN ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so RUN ln -s /usr/bin/gcc-4.6 /usr/bin/gcc RUN ln -s /usr/bin/g++-4.6 /usr/bin/g++ RUN ln -s /usr/bin/cpp-4.6 /usr/bin/cpp RUN ln -s /usr/bin/gcov-4.6 /usr/bin/gcov WORKDIR /var/aosp
Then create a new file ~/android-docker/aosp-build/sources.list, which is the software source configuration file of ubuntu. I use the mirror of Netease as follows:
deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
Execute in the ~/android-docker/aosp-build/directory:
docker build -t aosp-build .
Create an image named aosp-build. After the creation is completed, execute:
docker run -v ~/android-docker/android-fs:/var/aosp -i -t --name aosp aosp-build bash
A container named AOSP was created and started, which runs a bash shell of ubuntu 12.04 and shares the local ~/android-docker/android-fs directory with the container aosp's / var/aosp directory.
contianer aosp can be started again with the following command.docker start -i -a aosp
-
Install jdk6
Now coantianer aosp has launched a ubuntu 12.04 bash shell, but the environment is still lacking jdk, so go ahead oracle official website Download the jdk-6u45-linux-x64.bin required to compile Android 4.4.4 and download it to ~/android-docker/android-fs.
In the bash shell of ubuntu 12.04 (all subsequent commands are executed under this shell), execute the following command to increase the execution authority for jdk-6u45-linux-x64.bin.chmod u+x /var/aosp/jdk-6u45-linux-x64.bin
Execute the following command to extract JDK6 into the / var/aosp/jdk1.6.0_45 directory.
cd /var/aosp/ ./jdk-6u33-linux-i586.bin
Copy jdk1.6.0_45 to / usr/lib/jvm directory.
Add the following to the system configuration file / etc/bash/bash.rc.export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45 export PATH=$PATH:/$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib export JRE_HOME=$JAVA_HOME/jre
implement
source /etc/bash/bash.rc
Make it effective.
At this point, a complete aosp compilation environment is built.
IV. Summary
- The benefits of doing so are:
- Comparing with local compilation, it does not destroy the local development environment by configuring the compilation environment of aosp
- docker is lighter than virtual machines and does not need to install a huge virtual system
- Disadvantages:
- The compilation speed is slow and slow. I don't know if I have a problem with Docker configuration, because my working disk image is moving on the hard disk, or because my mac is out of date.