-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·69 lines (60 loc) · 2.33 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·69 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
#
# Clean build helper for the Maid Native experimental app.
#
# Usage:
# ./build.sh # clean + assemble signed release APK (default)
# ./build.sh debug # clean + assemble debug APK
# ./build.sh test # clean + run unit tests
# ./build.sh install # clean + assemble release + install to a connected device
#
# Honors existing JAVA_HOME / ANDROID_HOME if already exported; otherwise falls
# back to the locations used during development.
set -euo pipefail
cd "$(dirname "$0")"
# --- Toolchain -------------------------------------------------------------
# Prefer an already-exported JAVA_HOME; else try the local JDK 21.
if [[ -z "${JAVA_HOME:-}" || ! -x "${JAVA_HOME:-}/bin/java" ]]; then
if [[ -x "$HOME/.local/jdks/jdk-21/bin/java" ]]; then
export JAVA_HOME="$HOME/.local/jdks/jdk-21"
fi
fi
# Prefer an already-exported ANDROID_HOME; else try common local locations,
# else fall back to local.properties (sdk.dir=...).
if [[ -z "${ANDROID_HOME:-}" || ! -d "${ANDROID_HOME:-}" ]]; then
if [[ -d "$HOME/android-sdk" ]]; then
export ANDROID_HOME="$HOME/android-sdk"
elif [[ -d "$HOME/Android/Sdk" ]]; then
export ANDROID_HOME="$HOME/Android/Sdk"
fi
fi
export ANDROID_SDK_ROOT="${ANDROID_HOME:-}"
if [[ -n "${JAVA_HOME:-}" ]]; then
export PATH="$JAVA_HOME/bin:${ANDROID_HOME:-}/platform-tools:$PATH"
else
export PATH="${ANDROID_HOME:-}/platform-tools:$PATH"
fi
echo "JAVA_HOME=${JAVA_HOME:-<unset>}"
echo "ANDROID_HOME=${ANDROID_HOME:-<unset (relying on local.properties)>}"
# --- Task selection --------------------------------------------------------
TARGET="${1:-release}"
case "$TARGET" in
debug) GRADLE_TASK="clean :app:assembleDebug" ;;
release) GRADLE_TASK="clean :app:assembleRelease" ;;
test) GRADLE_TASK="clean :app:testDebugUnitTest" ;;
install) GRADLE_TASK="clean :app:assembleRelease" ;;
*)
echo "Unknown target '$TARGET' (expected: debug | release | test | install)" >&2
exit 2
;;
esac
echo "==> ./gradlew $GRADLE_TASK --no-daemon"
# shellcheck disable=SC2086
./gradlew $GRADLE_TASK --no-daemon
# --- Post-build ------------------------------------------------------------
if [[ "$TARGET" == "install" ]]; then
APK="app/build/outputs/apk/release/app-arm64-v8a-release.apk"
echo "==> adb install -r $APK"
adb install -r "$APK"
fi
echo "Done."