如果只需要编译一个版本的aosp,那么如果在主机上架建环境即可,可写的程序如果要在各个aosp版本中编译,那在主机上架建多个aosp编译环境可以会比较麻烦,github上找到一个openstf用docker架建aosp环境的代码,地址:https://github.com/openstf/docker-aosp
创建Dockerfile
aosp主要涉及三种环境jdk6,jdk7,jdk8,根据aosp的版本不同可以选择不同的Dockerfile
FROM ubuntu:14.04
MAINTAINER asmrobot [email protected] ADD sources.list /sources.list
RUN mv /sources.list /etc/apt/sources.list # Update
RUN export DEBIAN_FRONTEND=noninteractive && \
dpkg --add-architecture i386 && \
apt-get update && \
apt-get -y install software-properties-common # Install AOSP dependencies
RUN 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. \
/usr/lib/i386-linux-gnu/libGL.so # Install JDK
RUN export DEBIAN_FRONTEND=noninteractive && \
add-apt-repository ppa:webupd8team/java && \
apt-get update && \
echo debconf shared/accepted-oracle-license-v1- select true | \
sudo debconf-set-selections && \
echo debconf shared/accepted-oracle-license-v1- seen true | \
sudo debconf-set-selections && \
apt-get -y install oracle-java6-installer oracle-java6-set-default # Install repo tool
ADD repo /usr/local/bin/repo
RUN chmod +x /usr/local/bin/repo # Set up workspace
RUN git config --global user.email "[email protected]" && \
git config --global user.name "asmrobot" && \
git config --global color.ui auto # Volumes for AOSP source
VOLUME ["/aosp"]
VOLUME ["/mirror"] # Build commands must be run in the AOSP source tree
WORKDIR /aosp # Volume for external app source
VOLUME ["/app"] # Volume for build artifacts
VOLUME ["/artifacts"] # Set up entrypoint while working around docker/hub-feedback#
ADD aosp.sh /usr/local/bin/aosp.sh
RUN chmod +x /usr/local/bin/aosp.sh
RUN ln -s /usr/local/bin/aosp.sh /aosp.sh # Show help by default
CMD ["/aosp.sh", "--help"]
jdk6
FROM ubuntu:14.04
MAINTAINER asmrobot [email protected] ADD sources.list /sources.list
RUN mv /sources.list /etc/apt/sources.list # Update
RUN export DEBIAN_FRONTEND=noninteractive && \
dpkg --add-architecture i386 && \
apt-get update # Install AOSP dependencies
RUN 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. \
/usr/lib/i386-linux-gnu/libGL.so # Install JDK
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install openjdk--jdk # Install repo tool
ADD repo /usr/local/bin/repo
RUN chmod +x /usr/local/bin/repo # Set up workspace
RUN git config --global user.email "[email protected]" && \
git config --global user.name "asmrobot" && \
git config --global color.ui auto # Volumes for AOSP source
VOLUME ["/aosp"]
VOLUME ["/mirror"] # Build commands must be run in the AOSP source tree
WORKDIR /aosp # Volume for external app source
VOLUME ["/app"] # Volume for build artifacts
VOLUME ["/artifacts"] # Set up entrypoint while working around docker/hub-feedback#
ADD aosp.sh /usr/local/bin/aosp.sh
RUN chmod +x /usr/local/bin/aosp.sh
RUN ln -s /usr/local/bin/aosp.sh /aosp.sh # Show help by default
CMD ["/aosp.sh", "--help"]
jdk7
FROM ubuntu:16.04
MAINTAINER asmrobot [email protected] ADD sources.list /sources.list
RUN mv /sources.list /etc/apt/sources.list # Install AOSP dependencies
RUN 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 JDK
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install openjdk--jdk # Install repo tool
ADD repo /usr/local/bin/repo
RUN chmod +x /usr/local/bin/repo # Set up workspace
RUN git config --global user.email "[email protected]" && \
git config --global user.name "asmrobot" && \
git config --global color.ui auto # Volumes for AOSP source
VOLUME ["/aosp"]
VOLUME ["/mirror"] # Build commands must be run in the AOSP source tree
WORKDIR /aosp # Volume for external app source
VOLUME ["/app"] # Volume for build artifacts
VOLUME ["/artifacts"] # Set up entrypoint while working around docker/hub-feedback#
ADD aosp.sh /usr/local/bin/aosp.sh
RUN chmod +x /usr/local/bin/aosp.sh
RUN ln -s /usr/local/bin/aosp.sh /aosp.sh # Show help by default
CMD ["/aosp.sh", "--help"]
jdk8
三个版本中大部分代码都是一样的,只是每种环境安装的相应软件不同。在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_static LOCAL_SRC_FILES:= \
test.cpp LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) LOCAL_CFLAGS += -std=c++ LOCAL_MODULE:= test
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
Android.mk
#include <stdio.h> int main(int argc, char **argv)
{
printf("hello world!~");
return ;
}
test.cpp
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 到手机上运行,如图: