1+ #! /bin/bash
2+
3+ # Check for NDK_TOOLCHAIN environment variable and abort if it is not set.
4+ if [[ -z " ${NDK_TOOLCHAIN} " ]]; then
5+ echo " Please specify the Android NDK environment variable \" NDK_TOOLCHAIN\" ."
6+ exit 1
7+ fi
8+
9+ # Prerequisites.
10+ sudo apt install \
11+ golang \
12+ ninja-build \
13+ autogen \
14+ autoconf \
15+ libtool \
16+ build-essential \
17+ -y || exit 1
18+
19+ root=" $( pwd) "
20+
21+ # Install protobuf compiler.
22+ cd " src/protobuf" || exit 1
23+ ./autogen.sh
24+ ./configure
25+ make -j" $( nproc) "
26+ sudo make install
27+ sudo ldconfig
28+
29+ # Go back.
30+ cd " $root " || exit 1
31+
32+ # Apply patches.
33+ git apply patches/incremental_delivery.patch --whitespace=fix
34+ git apply patches/libpng.patch --whitespace=fix
35+ git apply patches/selinux.patch --whitespace=fix
36+ git apply patches/protobuf.patch --whitespace=fix
37+ git apply patches/aapt2.patch --whitespace=fix
38+ git apply patches/boringssl.patch --whitespace=fix
39+
40+ # Define all the compilers, libraries and targets.
41+ api=" 30"
42+ architecture=$1
43+ declare -A compilers=(
44+ [x86_64]=x86_64-linux-android
45+ [x86]=i686-linux-android
46+ [arm64-v8a]=aarch64-linux-android
47+ [armeabi-v7a]=armv7a-linux-androideabi
48+ )
49+ declare -A lib_arch=(
50+ [x86_64]=x86_64-linux-android
51+ [x86]=i686-linux-android
52+ [arm64-v8a]=aarch64-linux-android
53+ [armeabi-v7a]=arm-linux-androideabi
54+ )
55+ declare -A target_abi=(
56+ [x86_64]=x86_64
57+ [x86]=x86
58+ [arm64-v8a]=aarch64
59+ [armeabi-v7a]=arm
60+ )
61+
62+ build_directory=" build"
63+ aapt_binary_path=" $root /$build_directory /cmake/aapt2"
64+ # Build all the target architectures.
65+ bin_directory=" $root /dist/$architecture "
66+
67+ # switch to cmake build directory.
68+ [[ -d dir ]] || mkdir -p $build_directory && cd $build_directory || exit 1
69+
70+ # Define the compiler architecture and compiler.
71+ compiler_arch=" ${compilers[$architecture]} "
72+ c_compiler=" $compiler_arch$api -clang"
73+ cxx_compiler=" ${c_compiler} ++"
74+
75+ # Copy libc.a to libpthread.a.
76+ lib_path=" $NDK_TOOLCHAIN /sysroot/usr/lib/${lib_arch[$architecture]} /$api /"
77+ cp -n " $lib_path /libc.a" " $lib_path /libpthread.a"
78+
79+ # Run make for the target architecture.
80+ compiler_bin_directory=" $NDK_TOOLCHAIN /bin/"
81+ cmake -GNinja \
82+ -DCMAKE_C_COMPILER=" $compiler_bin_directory$c_compiler " \
83+ -DCMAKE_CXX_COMPILER=" $compiler_bin_directory$cxx_compiler " \
84+ -DCMAKE_BUILD_WITH_INSTALL_RPATH=True \
85+ -DCMAKE_BUILD_TYPE=Release \
86+ -DANDROID_ABI=" $architecture " \
87+ -DTARGET_ABI=" ${target_abi[$architecture]} " \
88+ -DPROTOC_PATH=" /usr/local/bin/protoc" \
89+ -DCMAKE_SYSROOT=" $NDK_TOOLCHAIN /sysroot" \
90+ .. || exit 1
91+
92+ ninja || exit 1
93+
94+ " $NDK_TOOLCHAIN /bin/llvm-strip" --strip-unneeded " $aapt_binary_path "
95+
96+ # Create bin directory.
97+ mkdir -p " $bin_directory "
98+
99+ # Move aapt2 to bin directory.
100+ mv " $aapt_binary_path " " $bin_directory "
0 commit comments