53 lines
2.1 KiB
Bash
Executable File
53 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install just enough Android SDK to build this app, idempotently.
|
|
#
|
|
# Used by CI, and usable by hand on a fresh machine. Everything lands in
|
|
# $ANDROID_HOME (default /opt/android-sdk), so pointing a cache or a volume at
|
|
# that directory makes the whole thing a no-op on later runs.
|
|
#
|
|
# Two package names are worth knowing:
|
|
#
|
|
# * `platforms;android-37.0` — Android's new minor-version scheme. Plain
|
|
# `android-37` does not exist and sdkmanager will not tell you why.
|
|
# * `build-tools;37.0.0` — needed for `apksigner`, which is how a release job
|
|
# proves what key it actually signed with.
|
|
set -euo pipefail
|
|
|
|
SDK_ROOT="${ANDROID_HOME:-/opt/android-sdk}"
|
|
COMPILE_SDK="$(sed -n 's/^compileSdk = "\(.*\)"/\1/p' "$(dirname "$0")/../gradle/libs.versions.toml")"
|
|
BUILD_TOOLS="${BUILD_TOOLS:-${COMPILE_SDK}.0.0}"
|
|
CMDLINE_VERSION="13114758" # cmdline-tools 17.0, the one that knows about minor platforms
|
|
|
|
mkdir -p "$SDK_ROOT"
|
|
|
|
if [ ! -x "$SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" ]; then
|
|
echo "==> fetching cmdline-tools"
|
|
tmp="$(mktemp -d)"
|
|
curl -fsSL -o "$tmp/tools.zip" \
|
|
"https://dl.google.com/android/repository/commandlinetools-linux-${CMDLINE_VERSION}_latest.zip"
|
|
unzip -q "$tmp/tools.zip" -d "$tmp"
|
|
mkdir -p "$SDK_ROOT/cmdline-tools"
|
|
rm -rf "$SDK_ROOT/cmdline-tools/latest"
|
|
mv "$tmp/cmdline-tools" "$SDK_ROOT/cmdline-tools/latest"
|
|
rm -rf "$tmp"
|
|
fi
|
|
|
|
export PATH="$SDK_ROOT/cmdline-tools/latest/bin:$PATH"
|
|
|
|
echo "==> licences"
|
|
# `yes` writes forever; once sdkmanager has read every licence it exits and
|
|
# `yes` dies of SIGPIPE. With `pipefail` that becomes exit 141 and fails the
|
|
# job, so the pipeline is judged on sdkmanager's status alone. Real failures
|
|
# (no network, bad SDK root) still fail it.
|
|
set +o pipefail
|
|
yes | sdkmanager --sdk_root="$SDK_ROOT" --licenses >/dev/null
|
|
set -o pipefail
|
|
|
|
echo "==> platform-tools, platforms;android-${COMPILE_SDK}.0, build-tools;${BUILD_TOOLS}"
|
|
sdkmanager --sdk_root="$SDK_ROOT" \
|
|
"platform-tools" \
|
|
"platforms;android-${COMPILE_SDK}.0" \
|
|
"build-tools;${BUILD_TOOLS}" >/dev/null
|
|
|
|
echo "==> $SDK_ROOT is ready"
|