1#!/usr/bin/env bash
Install the Android SDK packages the build needs into $ANDROID_HOME, with sdkmanager. Idempotent: a package already there is not fetched again.
mise run android:sdk
Environment (mise.toml sets all of it; set them yourself to run this without mise): ANDROID_HOME the SDK directory (the android-sdk tool's own, under mise) WHISKERS_ANDROID_PLATFORM API level of the platform, e.g. 37.0 (the sdkmanager package android-37.0) WHISKERS_ANDROID_BUILD_TOOLS e.g. 36.0.0 WHISKERS_ANDROID_NDK e.g. 29.0.14206865 sdkmanager (the command-line tools) and a JDK must be on PATH.
On NixOS the downloaded NDK and build tools are ordinary dynamically linked programs: they need nix-ld
(programs.nix-ld.enable) or the repository's nix develop .#fhs shell.
16set -euo pipefail 17: "${ANDROID_HOME:?set ANDROID_HOME to the SDK directory (mise sets it from the android-sdk tool)}" 18: "${WHISKERS_ANDROID_PLATFORM:?}" "${WHISKERS_ANDROID_BUILD_TOOLS:?}" "${WHISKERS_ANDROID_NDK:?}" 19command -v sdkmanager >/dev/null || { echo "sdkmanager is not on PATH: install the Android command-line tools (mise install) or add them to PATH" >&2; exit 1; }
21need=() 22[ -d "$ANDROID_HOME/platforms/android-$WHISKERS_ANDROID_PLATFORM" ] || need+=("platforms;android-$WHISKERS_ANDROID_PLATFORM") 23[ -d "$ANDROID_HOME/build-tools/$WHISKERS_ANDROID_BUILD_TOOLS" ] || need+=("build-tools;$WHISKERS_ANDROID_BUILD_TOOLS") 24[ -d "$ANDROID_HOME/ndk/$WHISKERS_ANDROID_NDK" ] || need+=("ndk;$WHISKERS_ANDROID_NDK") 25[ -d "$ANDROID_HOME/platform-tools" ] || need+=("platform-tools") 26if [ ${#need[@]} -eq 0 ]; then 27 echo "android-sdk: already installed in $ANDROID_HOME" 28 exit 0 29fi 30echo "android-sdk: installing ${need[*]}"
sdkmanager asks questions on stdin; answer them. yes ends with SIGPIPE, hence the subshell.
32(yes 2>/dev/null || true) | sdkmanager --sdk_root="$ANDROID_HOME" --install "${need[@]}"