Docker Android

Docker中配置Android编译环境

Posted by LXG on November 8, 2020

安装Docker


$ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

编译Image

使用github的方式比较简单

源码

/build/tools/docker/-androidxref


# 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 .

github-kylemanna-docker-aosp

docker-aosp-github


$ make aosp
$ cd aosp
$ export AOSP_VOL=$PWD
$ curl -O https://raw.githubusercontent.com/kylemanna/docker-aosp/master/tests/build-nougat.sh
$ bash ./build-nougat.sh

导入镜像


docker load < compile.tar

挂载容器


$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              31efdd4ea934        5 days ago          1.1GB

& docker run -d -it --mount type=bind,source=/home/lxg/code/,target=/aosp/ 31efdd4ea934

root用户问题


$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              31efdd4ea934        5 days ago          1.1GB

$ id
uid=1000(lxg) gid=1000(lxg) 组=1000(lxg),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare),998(docker)

$ docker run -it -d --net=host --user 1000:1000 -v /etc/passwd:/etc/passwd:ro -v /etc/shadow:/etc/shadow:ro -v /etc/group:/etc/group:ro --entrypoint=/bin/bash --mount type=bind,source=/home/lxg/code/,target=/aosp/ 31efdd4ea934

进入容器


$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
56663213f9a9        31efdd4ea934        "/bin/bash"         4 days ago          Exited (0) 2 minutes ago                       happy_brattain

$ docker start 56663213f9a9
56663213f9a9

$ docker exec -it 56663213f9a9 /bin/bash
lxg@56663213f9a9:/aosp$ 

退出


$ exit

$ docker stop 56663213f9a9

FAQ

问题一


FAILED: out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack
/bin/bash -c "(mkdir -p out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack.tmpjill.res ) && (unzip -qo prebuilts/sdk/16/android.jar -d out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack.tmpjill.res ) && (find out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack.tmpjill.res -iname \"*.class\" -delete ) && (JACK_VERSION=4.31.CANDIDATE out/host/linux-x86/bin/jack @build/core/jack-default.args    -D jack.import.resource.policy=keep-first -D jack.import.type.policy=keep-first -D jack.android.min-api-level=16 --import prebuilts/sdk/16/android.jar --import-resource out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack.tmpjill.res --output-jack out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack ) && (rm -rf out/target/common/obj/JAVA_LIBRARIES/sdk_v16_intermediates/classes.jack.tmpjill.res )"
out/host/linux-x86/bin/jack: line 80: USER: unbound variable

解决方法:

$ export USER=$(whoami)

问题二


Notice file: system/extras/ext4_utils/NOTICE -- out-E8909/target/product/msm8909/obj/NOTICE_FILES/src//system/lib/libext4_utils_static.a.txt
/bin/bash: mkisofs: command not found

解决方法:

$ sudo apt-get update
$ sudo apt-get install mkisofs
$ sudo apt-get install genisoimage

问题三


/tmp/tmp.i3X3uQIvsx/bin/brillo_update_payload: line 368: xxd: command not found
/tmp/tmp.i3X3uQIvsx/bin/brillo_update_payload: line 378: cgpt: command not found
brillo_update_payload: error: Couldn't detect the image format of /aosp/project/dev/L2s_dev_backup/android/out/dist/merged-qssi_bengal-target_files.zip

xxd is in vim common

解决方法:

1. sudo apt-get install cgpt
2. sudo apt-get install vim-common