Files
ha-dashboard-studio/android/build.sh
T
veenm 297fb2a7a0 Dashboard Studio 1.14.1: Android app, phone menu button, install fix
- Android app (android/, built with build.sh): signs in to Home Assistant once, opens Dashboard Studio full screen, renews the ingress session; downloadable from Install as an app
- Phone dashboards: a round menu button brings back the top bar with Edit, Kiosk and Install as an app
- Install as an app explains what works per device (Android app, https for browser install, iPhone limits)
- Fixed: browser install failed because the manifest was fetched without the Home Assistant sign-in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 22:34:52 +01:00

39 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
# Builds the Android app without Gradle, with the Android SDK's own tools, and copies it into the
# Home Assistant app, which offers it for download (Install as an app on an Android phone).
# ./build.sh the release build, signed with ~/.android/dashboard-studio.jks (made the first time)
# ./build.sh debug a debuggable build, for testing in the emulator (Chrome can inspect its pages)
# Keep the key: Android only installs an update that is signed with the same key as the installed app.
set -e
cd "$(dirname "$0")"
SDK="${ANDROID_HOME:-$HOME/Library/Android/sdk}"
BT="$SDK/build-tools/$(ls "$SDK/build-tools" | sort -V | tail -1)"
JAR="$SDK/platforms/$(ls "$SDK/platforms" | sort -V | tail -1)/android.jar"
KEY="${DS_KEYSTORE:-$HOME/.android/dashboard-studio.jks}"
OUT=build
rm -rf "$OUT" && mkdir -p "$OUT/res" "$OUT/classes" "$OUT/gen"
DEBUG=""
[ "$1" = "debug" ] && DEBUG="--debug-mode"
"$BT/aapt2" compile --dir res -o "$OUT/res"
"$BT/aapt2" link -o "$OUT/app.unsigned.apk" -I "$JAR" --manifest AndroidManifest.xml -A assets \
--java "$OUT/gen" $DEBUG "$OUT"/res/*.flat
javac -nowarn --release 17 -classpath "$JAR" -d "$OUT/classes" $(find src "$OUT/gen" -name '*.java')
"$BT/d8" --release --min-api 24 --lib "$JAR" --output "$OUT" $(find "$OUT/classes" -name '*.class')
(cd "$OUT" && zip -q app.unsigned.apk classes.dex)
"$BT/zipalign" -f -p 4 "$OUT/app.unsigned.apk" "$OUT/app.aligned.apk"
if [ ! -f "$KEY" ]; then
mkdir -p "$(dirname "$KEY")"
keytool -genkeypair -keystore "$KEY" -storepass dashboard-studio -keypass dashboard-studio -alias app \
-keyalg RSA -keysize 4096 -validity 36500 -dname "CN=Dashboard Studio" >/dev/null
echo "Made a new signing key: $KEY (keep it, updates need the same key)"
fi
"$BT/apksigner" sign --ks "$KEY" --ks-pass pass:dashboard-studio --ks-key-alias app --out "$OUT/dashboard-studio.apk" "$OUT/app.aligned.apk"
if [ -z "$DEBUG" ]; then
cp "$OUT/dashboard-studio.apk" ../dashboard_studio/web/dashboard-studio.apk
echo "Built and copied to dashboard_studio/web/dashboard-studio.apk"
else
echo "Built $OUT/dashboard-studio.apk (debug)"
fi