构建Android编译环境

准备工作

我采用Android的编译环境是在 Docker Atlas 部署,通过 从Dockerfile构建Docker镜像 创建一个CentOS 8纯净环境,然后从初始环境安装必要的编译工具链来构建Android编译环境。

  • 在本地创建一个 studio 目录,进入这个目录,然后 - 如果你只是编译android系统,则存放以下名为 android-build 的Dockerfile - 如果你想开发android系统,则存放以下名为 android-studio 的Dockerfile

android-build
 1# Build Android Studio image with ssh:
 2# ------------------------------------
 3# docker build - < android-studio
 4
 5# create container:
 6# -----------------
 7# docker run -itd --hostname android-studio --name android-studio local:android-studio
 8
 9# create container with volume:
10# -----------------------------
11# docker volume create data
12# docker run -itd --hostname android-studio --name android-studio -v data:/data local:android-studio
13
14# create container with volume and static ip:
15# -------------------------------------------
16# docker volume create data
17# docker network create --subnet=172.18.0.0/16 data-net
18# docker run -itd --hostname android-studio --name android-studio -v data:/data \
19#   --net data-net --ip 172.18.0.252 local:android-studio
20
21# create container with volume and static ip, then limit resource and map port:
22# -----------------------------------------------------------------------------
23# docker volume create data
24# docker network create --subnet=172.18.0.0/16 data-net
25# docker run -itd --hostname android-studio --name android-studio -v data:/data \
26#   --net data-net --ip 172.18.0.252 --memory=2048M --cpus="1.5" \
27#   -p 2222:22 -p 8080:80 local:android-studio
28
29FROM docker.io/centos:8
30MAINTAINER vincent huatai <vincent@huatai.me>
31
32RUN dnf clean all
33RUN dnf install epel-release
34RUN dnf install dnf-plugins-core
35RUN dnf config-manager --set-enabled PowerTools
36RUN dnf -y update
37RUN dnf -y install which sudo openssh-clients openssh-server initscripts nmon nmap-ncat mlocate net-tools rsyslog file wget tar bzip2 screen sysstat unzip nfs-utils parted lsof man bind-utils gcc gcc-c++ make telnet flex autoconf automake ncurses-devel crontabs zlib-devel git
38
39# Prepare sshd host key
40RUN ssh-keygen -A
41
42# add account "admin" and give sudo privilege
43RUN groupadd -g 505 admin
44RUN useradd -g 505 -u 505 -d /home/admin -m admin
45RUN usermod -aG wheel admin
46RUN echo "%wheel        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
47
48# Add ssh public key for login
49RUN mkdir -p /home/admin/.ssh
50COPY authorized_keys /home/admin/.ssh/authorized_keys
51RUN chown -R admin:admin /home/admin/.ssh
52RUN chmod 600 /home/admin/.ssh/authorized_keys
53RUN chmod 700 /home/admin/.ssh
54RUN mv /var/run/nologin /var/run/nologin.bak
55
56# run service when container started - sshd
57EXPOSE 22:2222
58#CMD ["/usr/sbin/sshd", "-D"]
59
60# ----------
61# WANT run sshd and get a bash
62# ENTRYPOINT will not be override by commandline
63# ----------
64ENTRYPOINT /usr/sbin/sshd && /bin/bash
android-studio
 1# Build Android Studio image with ssh:
 2# ------------------------------------
 3# docker build - < android-studio
 4
 5# create container:
 6# -----------------
 7# docker run -itd --hostname android-studio --name android-studio local:android-studio
 8
 9# create container with volume:
10# -----------------------------
11# docker volume create data
12# docker run -itd --hostname android-studio --name android-studio -v data:/data local:android-studio
13
14# create container with volume and static ip:
15# -------------------------------------------
16# docker volume create data
17# docker network create --subnet=172.18.0.0/16 data-net
18# docker run -itd --hostname android-studio --name android-studio -v data:/data \
19#   --net data-net --ip 172.18.0.252 local:android-studio
20
21# create container with volume and static ip, then limit resource and map port:
22# -----------------------------------------------------------------------------
23# docker volume create data
24# docker network create --subnet=172.18.0.0/16 data-net
25# docker run -itd --hostname android-studio --name android-studio -v data:/data \
26#   --net data-net --ip 172.18.0.252 --memory=2048M --cpus="1.5" \
27#   -p 2222:22 -p 8080:80 local:android-studio
28
29FROM docker.io/centos:8
30MAINTAINER vincent huatai <vincent@huatai.me>
31
32RUN dnf clean all
33RUN dnf install epel-release
34RUN dnf install dnf-plugins-core
35RUN dnf config-manager --set-enabled PowerTools
36RUN dnf -y update
37RUN dnf -y install which sudo openssh-clients openssh-server initscripts nmon nmap-ncat mlocate net-tools rsyslog file wget tar bzip2 screen sysstat unzip nfs-utils parted lsof man bind-utils gcc gcc-c++ make telnet flex autoconf automake ncurses-devel crontabs zlib-devel git
38
39# Prepare sshd host key
40RUN ssh-keygen -A
41
42# add account "admin" and give sudo privilege
43RUN groupadd -g 505 admin
44RUN useradd -g 505 -u 505 -d /home/admin -m admin
45RUN usermod -aG wheel admin
46RUN echo "%wheel        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
47
48# Add ssh public key for login
49RUN mkdir -p /home/admin/.ssh
50COPY authorized_keys /home/admin/.ssh/authorized_keys
51RUN chown -R admin:admin /home/admin/.ssh
52RUN chmod 600 /home/admin/.ssh/authorized_keys
53RUN chmod 700 /home/admin/.ssh
54RUN mv /var/run/nologin /var/run/nologin.bak
55
56# run service when container started - sshd
57EXPOSE 22:2222
58#CMD ["/usr/sbin/sshd", "-D"]
59
60# ----------
61# WANT run sshd and get a bash
62# ENTRYPOINT will not be override by commandline
63# ----------
64ENTRYPOINT /usr/sbin/sshd && /bin/bash