首页 > 代码库 > 使用docker创建aosp编译环境
使用docker创建aosp编译环境
如果只需要编译一个版本的aosp,那么如果在主机上架建环境即可,可写的程序如果要在各个aosp版本中编译,那在主机上架建多个aosp编译环境可以会比较麻烦,github上找到一个openstf用docker架建aosp环境的代码,地址:https://github.com/openstf/docker-aosp
创建Dockerfile
aosp主要涉及三种环境jdk6,jdk7,jdk8,根据aosp的版本不同可以选择不同的Dockerfile
FROM ubuntu:14.04MAINTAINER asmrobot asmrobot@hotmail.comADD sources.list /sources.listRUN mv /sources.list /etc/apt/sources.list# UpdateRUN export DEBIAN_FRONTEND=noninteractive && dpkg --add-architecture i386 && apt-get update && \ apt-get -y install software-properties-common# Install AOSP dependenciesRUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install build-essential && apt-get -y install git gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z1-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc libreadline6-dev lib32readline-gplv2-dev libncurses5-dev bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev squashfs-tools pngcrush schedtool dpkg-dev && ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so# Install JDKRUN export DEBIAN_FRONTEND=noninteractive && add-apt-repository ppa:webupd8team/java && apt-get update && echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections && echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections && apt-get -y install oracle-java6-installer oracle-java6-set-default# Install repo toolADD repo /usr/local/bin/repoRUN chmod +x /usr/local/bin/repo# Set up workspaceRUN git config --global user.email "asmrobot@hotmail.com" && git config --global user.name "asmrobot" && git config --global color.ui auto# Volumes for AOSP sourceVOLUME ["/aosp"]VOLUME ["/mirror"]# Build commands must be run in the AOSP source treeWORKDIR /aosp# Volume for external app sourceVOLUME ["/app"]# Volume for build artifactsVOLUME ["/artifacts"]# Set up entrypoint while working around docker/hub-feedback#811ADD aosp.sh /usr/local/bin/aosp.shRUN chmod +x /usr/local/bin/aosp.shRUN ln -s /usr/local/bin/aosp.sh /aosp.sh# Show help by defaultCMD ["/aosp.sh", "--help"]
FROM ubuntu:14.04MAINTAINER asmrobot asmrobot@hotmail.comADD sources.list /sources.listRUN mv /sources.list /etc/apt/sources.list# UpdateRUN export DEBIAN_FRONTEND=noninteractive && dpkg --add-architecture i386 && apt-get update# Install AOSP dependenciesRUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install build-essential && apt-get -y install git gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z1-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc libreadline6-dev lib32readline-gplv2-dev libncurses5-dev bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev squashfs-tools pngcrush schedtool dpkg-dev && ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so# Install JDKRUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install openjdk-7-jdk# Install repo toolADD repo /usr/local/bin/repoRUN chmod +x /usr/local/bin/repo# Set up workspaceRUN git config --global user.email "asmrobot@hotmail.com" && git config --global user.name "asmrobot" && git config --global color.ui auto# Volumes for AOSP sourceVOLUME ["/aosp"]VOLUME ["/mirror"]# Build commands must be run in the AOSP source treeWORKDIR /aosp# Volume for external app sourceVOLUME ["/app"]# Volume for build artifactsVOLUME ["/artifacts"]# Set up entrypoint while working around docker/hub-feedback#811ADD aosp.sh /usr/local/bin/aosp.shRUN chmod +x /usr/local/bin/aosp.shRUN ln -s /usr/local/bin/aosp.sh /aosp.sh# Show help by defaultCMD ["/aosp.sh", "--help"]
FROM ubuntu:16.04MAINTAINER asmrobot asmrobot@hotmail.comADD sources.list /sources.listRUN mv /sources.list /etc/apt/sources.list# Install AOSP dependenciesRUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get -y install 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# Install JDKRUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install openjdk-8-jdk# Install repo toolADD repo /usr/local/bin/repoRUN chmod +x /usr/local/bin/repo# Set up workspaceRUN git config --global user.email "asmrobot@hotmail.com" && git config --global user.name "asmrobot" && git config --global color.ui auto# Volumes for AOSP sourceVOLUME ["/aosp"]VOLUME ["/mirror"]# Build commands must be run in the AOSP source treeWORKDIR /aosp# Volume for external app sourceVOLUME ["/app"]# Volume for build artifactsVOLUME ["/artifacts"]# Set up entrypoint while working around docker/hub-feedback#811ADD aosp.sh /usr/local/bin/aosp.shRUN chmod +x /usr/local/bin/aosp.shRUN ln -s /usr/local/bin/aosp.sh /aosp.sh# Show help by defaultCMD ["/aosp.sh", "--help"]
三个版本中大部分代码都是一样的,只是每种环境安装的相应软件不同。在openstf之上改变的有
1.ubuntu的source.list,jdk6,7为163的源地址,jdk8为aliyun的。
2.repo中aosp的源码下载地址改为清华的repo:https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
3.移除了原版中创建镜像的代码,减少了点参数。。。。参数太少看着眩晕,如果想创建私有aosp源可以在网上找资源
镜像默认命令文件为/aosp.sh
支持三种操作:
编译aosp前的准备
1.构建docker容器
//切换到dockerfile目录
cd /var/aosp-docker/jdk6
//以dockerfile创建aosp/jdk6镜像
sudo docker build -t aosp/jdk6 .
2.checkout出你需要的aosp源码
sudo docker run --rm -ti -v /var/aosp-4.4.2:/aosp aosp/jdk6 /aosp.sh checkout-branch https://aosp.tuna.tsinghua.edu.cn/platform/manifest android-4.4.2_r2
这里的源使用的清华的镜像,如果你有私用镜像改上下面镜像地址即可。
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS) APP_STL := stlport_staticLOCAL_SRC_FILES:= test.cpp LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) LOCAL_CFLAGS += -std=c++11 LOCAL_MODULE:= testLOCAL_MODULE_TAGS := optionalinclude $(BUILD_EXECUTABLE)
#include <stdio.h>int main(int argc, char **argv){ printf("hello world!~"); return 0;}
docker run -ti --rm -v /var/aosp-4.4.2:/aosp -v /home/xxxx/test:/app -v /home/xxxx/test-bin:/artifacts aosp/jdk6 /aosp.sh build aosp_arm-eng test
编译成功后出现:
编译好的程序就在挂载/artifacts的目录中,我的是:/home/xxxx/test-bin
把test 用adb push 到手机上运行,如图:
使用docker创建aosp编译环境