#!/usr/bin/env bash
set -euo pipefail

repository_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
android_dir="${repository_dir}/android"
output_dir="${repository_dir}/apks"
source_apk="${android_dir}/app/build/outputs/apk/debug/app-debug.apk"
output_apk="${output_dir}/pi-car-companion-debug.apk"

mkdir -p "${output_dir}"

(
  cd "${android_dir}"
  ./gradlew --no-daemon :app:assembleDebug
)

install -m 0644 "${source_apk}" "${output_apk}"

echo "APK written to ${output_apk}"
if command -v sha256sum >/dev/null 2>&1; then
  sha256sum "${output_apk}"
fi
