Skip to content

Commit 746da13

Browse files
committed
Allow different Android versions for Docker images.
Allow different Android NDK, SDK, and Android versions to be used. Also simplifies the build process and future-proofs it slightly, since it removes the Python dependency for the Android NDK build script, and plans for the deprecation of the Makefile build process for the Android system build script.
1 parent ba030a6 commit 746da13

8 files changed

+65
-34
lines changed

docker/Dockerfile.aarch64-linux-android

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm64 28
18+
RUN /android-ndk.sh arm64
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -20,7 +24,7 @@ RUN /android-system.sh arm64
2024
COPY qemu.sh /
2125
RUN /qemu.sh aarch64
2226

23-
RUN cp /android-ndk/sysroot/usr/lib/aarch64-linux-android/28/libz.so /system/lib/
27+
RUN cp /android-ndk/sysroot/usr/lib/aarch64-linux-android/$ANDROID_SDK/libz.so /system/lib/
2428

2529
COPY android-runner /
2630

docker/Dockerfile.arm-linux-androideabi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
18+
RUN /android-ndk.sh arm
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -20,7 +24,7 @@ RUN /android-system.sh arm
2024
COPY qemu.sh /
2125
RUN /qemu.sh arm
2226

23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
27+
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/$ANDROID_SDK/libz.so /system/lib/
2428

2529
COPY android-runner /
2630

docker/Dockerfile.armv7-linux-androideabi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
18+
RUN /android-ndk.sh arm
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -20,7 +24,7 @@ RUN /android-system.sh arm
2024
COPY qemu.sh /
2125
RUN /qemu.sh arm
2226

23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
27+
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/$ANDROID_SDK/libz.so /system/lib/
2428

2529
COPY android-runner /
2630

docker/Dockerfile.i686-linux-android

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh x86 28
18+
RUN /android-ndk.sh x86
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -27,7 +31,7 @@ RUN /android-system.sh x86
2731
COPY qemu.sh /
2832
RUN /qemu.sh i386
2933

30-
RUN cp /android-ndk/sysroot/usr/lib/i686-linux-android/28/libz.so /system/lib/
34+
RUN cp /android-ndk/sysroot/usr/lib/i686-linux-android/$ANDROID_SDK/libz.so /system/lib/
3135

3236
COPY android-runner /
3337

docker/Dockerfile.thumbv7neon-linux-androideabi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
18+
RUN /android-ndk.sh arm
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -20,7 +24,7 @@ RUN /android-system.sh arm
2024
COPY qemu.sh /
2125
RUN /qemu.sh arm
2226

23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
27+
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/$ANDROID_SDK/libz.so /system/lib/
2428

2529
COPY android-runner /
2630

docker/Dockerfile.x86_64-linux-android

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
ARG ANDROID_NDK=r21d
14+
ARG ANDROID_SDK=28
15+
ARG ANDROID_VERSION=9.0.0_r1
16+
1317
COPY android-ndk.sh /
14-
RUN /android-ndk.sh x86_64 28
18+
RUN /android-ndk.sh x86_64
1519
ENV PATH=$PATH:/android-ndk/bin
1620

1721
COPY android-system.sh /
@@ -21,7 +25,7 @@ RUN /android-system.sh x86_64
2125
COPY qemu.sh /
2226
RUN /qemu.sh x86_64
2327

24-
RUN cp /android-ndk/sysroot/usr/lib/x86_64-linux-android/28/libz.so /system/lib/
28+
RUN cp /android-ndk/sysroot/usr/lib/x86_64-linux-android/$ANDROID_SDK/libz.so /system/lib/
2529

2630
COPY android-runner /
2731

docker/android-ndk.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@ set -euo pipefail
66
# shellcheck disable=SC1091
77
. lib.sh
88

9-
NDK_URL=https://dl.google.com/android/repository/android-ndk-r21d-linux-x86_64.zip
9+
NDK_PLATFORM=linux-x86_64
10+
NDK_FILENAME="android-ndk-${ANDROID_NDK}-${NDK_PLATFORM}.zip"
11+
NDK_URL="https://dl.google.com/android/repository/${NDK_FILENAME}"
1012

1113
main() {
12-
local arch="${1}" \
13-
api="${2}"
14+
local arch="${1}"
1415

15-
install_packages curl unzip python
16+
install_packages curl unzip
1617

1718
local td
1819
td="$(mktemp -d)"
1920

2021
pushd "${td}"
2122
curl --retry 3 -sSfL "${NDK_URL}" -O
22-
unzip -q android-ndk-*.zip
23-
rm android-ndk-*.zip
24-
pushd android-ndk-*
25-
./build/tools/make_standalone_toolchain.py \
26-
--install-dir /android-ndk \
27-
--arch "${arch}" \
28-
--api "${api}"
23+
unzip -q "${NDK_FILENAME}"
24+
rm "${NDK_FILENAME}"
25+
pushd "android-ndk-${ANDROID_NDK}"
26+
mv "toolchains/llvm/prebuilt/${NDK_PLATFORM}" /android-ndk
2927

3028
# clean up unused toolchains to reduce image size
3129
local triple

docker/android-system.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ set -euo pipefail
88

99
main() {
1010
local arch="${1}"
11+
local version="${ANDROID_VERSION}"
12+
local gcc_version=4.9
13+
local glibc_version=glibc2.15-4.8
14+
# FIXME: android is currently migrating from make to soong, so
15+
# `platform/build/make` may be missing from a future version of
16+
# android. version-gate this when make is removed.
17+
# latest tested version with make: 13.0.0_r6
18+
local has_make=1
19+
1120
local td
1221
td="$(mktemp -d)"
1322
pushd "${td}"
1423

1524
# fake java and javac, it is not necessary for what we build, but the build
16-
# script ask for it
25+
# script asks for it
1726
cat << EOF > /usr/bin/java
1827
#!/usr/bin/env bash
1928
echo "java version \"1.7.0\""
@@ -53,11 +62,13 @@ EOF
5362

5463
# this is the minimum set of modules that are need to build bionic
5564
# this was created by trial and error
56-
python3 ./repo init -u https://android.googlesource.com/platform/manifest -b android-9.0.0_r1
65+
python3 ./repo init -u "https://android.googlesource.com/platform/manifest" -b "android-${version}"
5766

5867
python3 ./repo sync -c art
5968
python3 ./repo sync -c bionic
60-
python3 ./repo sync -c build/make
69+
if [[ "${has_make}" == 1 ]]; then
70+
python3 ./repo sync -c build/make
71+
fi
6172
python3 ./repo sync -c build/blueprint
6273
python3 ./repo sync -c build/soong
6374
python3 ./repo sync -c external/clang
@@ -81,9 +92,7 @@ EOF
8192
python3 ./repo sync -c prebuilts/build-tools
8293
python3 ./repo sync -c prebuilts/clang/host/linux-x86
8394
python3 ./repo sync -c prebuilts/clang-tools
84-
#python3 ./repo sync -c prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
85-
#python3 ./repo sync -c prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9
86-
python3 ./repo sync -c prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8
95+
python3 ./repo sync -c "prebuilts/gcc/linux-x86/host/x86_64-linux-${glibc_version}"
8796
python3 ./repo sync -c prebuilts/go/linux-x86
8897
python3 ./repo sync -c prebuilts/misc
8998
python3 ./repo sync -c prebuilts/sdk
@@ -93,17 +102,17 @@ EOF
93102

94103
case "${arch}" in
95104
arm)
96-
python3 ./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9
105+
python3 ./repo sync "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-${gcc_version}"
97106
;;
98107
arm64)
99-
python3 ./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9
100-
python3 ./repo sync prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
108+
python3 ./repo sync "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-${gcc_version}"
109+
python3 ./repo sync "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-${gcc_version}"
101110
;;
102111
x86)
103-
python3 ./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9
112+
python3 ./repo sync "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-${gcc_version}"
104113
;;
105114
x86_64)
106-
python3 ./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9
115+
python3 ./repo sync "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-${gcc_version}"
107116
;;
108117
esac
109118

0 commit comments

Comments
 (0)