#!/bin/bash # Builds uitrace.jar from UiTrace.java. Run after editing the recorder; ui-trace # also runs this by itself when the jar is missing or older than the source. set -euo pipefail cd "$(dirname "$0")" # The ambient ANDROID_HOME on this machine points at a root-owned SDK that has # no build-tools under it, so an SDK is only accepted once d8 is confirmed in it. d8="" for root in "$HOME/Android/Sdk" "${ANDROID_SDK_ROOT:-}" "${ANDROID_HOME:-}"; do [ -n "$root" ] || continue found=$(ls -d "$root"/build-tools/*/d8 2>/dev/null | sort -V | tail -1) if [ -n "$found" ]; then d8=$found platform=$(ls -d "$root"/platforms/android-* 2>/dev/null | sort -V | tail -1) break fi done if [ -z "$d8" ] || [ -z "${platform:-}" ]; then echo "ui-trace: no Android SDK with both build-tools and a platform" >&2 exit 1 fi rm -rf classes && mkdir -p classes javac --release 17 -Xlint:all -Werror -cp "$platform/android.jar" -d classes UiTrace.java "$d8" --min-api 30 --output . classes/UiTrace.class python3 -c 'import zipfile,sys; z=zipfile.ZipFile("uitrace.jar","w",zipfile.ZIP_DEFLATED); z.write("classes.dex"); z.close()' rm -rf classes classes.dex echo "built $(pwd)/uitrace.jar"