Verifies the Android dev environment (JDK/SDK/cmdline-tools/Gradle), suggests runnable commands for anything missing without installing, and generates a minimal Kotlin+Compose skeleton that passes ./gradlew build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
96 lines
4.4 KiB
Bash
Executable file
96 lines
4.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# doctor.sh — inspect the Android/Gradle/JDK dev environment WITHOUT installing anything.
|
|
# Prints a report and, where a tool is missing, prints copy-pasteable commands the USER can run.
|
|
# Exit code: 0 if a usable environment was found (SDK + JDK 17+), 1 otherwise.
|
|
set -uo pipefail
|
|
|
|
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; }
|
|
warn() { printf ' \033[33m!\033[0m %s\n' "$1"; }
|
|
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; }
|
|
hdr() { printf '\n\033[1m%s\033[0m\n' "$1"; }
|
|
|
|
FAIL=0
|
|
|
|
# ---------------------------------------------------------------------------
|
|
hdr "JDK"
|
|
if command -v java >/dev/null 2>&1; then
|
|
JV=$(java -version 2>&1 | head -1)
|
|
JMAJOR=$(java -version 2>&1 | head -1 | sed -E 's/.*version "([0-9]+).*/\1/')
|
|
if [ "${JMAJOR:-0}" -ge 17 ] 2>/dev/null; then
|
|
ok "java: $JV"
|
|
[ -n "${JAVA_HOME:-}" ] && ok "JAVA_HOME=$JAVA_HOME" || warn "JAVA_HOME is unset (fine if 'java' works, but Gradle prefers it set)"
|
|
else
|
|
bad "java is $JV — Android Gradle Plugin needs JDK 17+"
|
|
FAIL=1
|
|
fi
|
|
else
|
|
bad "java not found on PATH"
|
|
echo " Look for a JDK 17 here, then export JAVA_HOME + add to PATH:"
|
|
echo " ls /usr/lib/jvm/ 2>/dev/null; ls /Library/Java/JavaVirtualMachines/ 2>/dev/null"
|
|
echo " # export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"
|
|
echo " # export PATH=\"\$JAVA_HOME/bin:\$PATH\""
|
|
FAIL=1
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
hdr "Android SDK"
|
|
SDK=""
|
|
for cand in "${ANDROID_HOME:-}" "${ANDROID_SDK_ROOT:-}" \
|
|
"$HOME/Android/Sdk" "$HOME/Library/Android/sdk" \
|
|
"/usr/lib/android-sdk" "/opt/android-sdk"; do
|
|
[ -n "$cand" ] && [ -d "$cand" ] && { SDK="$cand"; break; }
|
|
done
|
|
|
|
if [ -n "$SDK" ]; then
|
|
ok "SDK root: $SDK"
|
|
[ -n "${ANDROID_HOME:-}" ] && ok "ANDROID_HOME set" || warn "ANDROID_HOME unset — 'export ANDROID_HOME=$SDK'"
|
|
else
|
|
bad "No Android SDK found in ANDROID_HOME / ANDROID_SDK_ROOT or common locations."
|
|
echo " Search for one (do NOT download unless the user asks):"
|
|
echo " find \$HOME /opt /usr/lib -maxdepth 4 -type d -name platform-tools 2>/dev/null"
|
|
echo " If found at <dir>/platform-tools, set:"
|
|
echo " export ANDROID_HOME=<dir>; export PATH=\"\$ANDROID_HOME/platform-tools:\$ANDROID_HOME/cmdline-tools/latest/bin:\$PATH\""
|
|
FAIL=1
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
hdr "SDK command-line tools"
|
|
for tool in adb sdkmanager avdmanager; do
|
|
P=$(command -v $tool 2>/dev/null)
|
|
if [ -n "$P" ]; then ok "$tool: $P"
|
|
elif [ -n "$SDK" ]; then
|
|
HIT=$(find "$SDK" -name "$tool" -type f 2>/dev/null | head -1)
|
|
[ -n "$HIT" ] && warn "$tool present but not on PATH: $HIT" || warn "$tool not found (sdkmanager can install it)"
|
|
else warn "$tool not found"; fi
|
|
done
|
|
|
|
# ---------------------------------------------------------------------------
|
|
hdr "Installed platforms & build-tools"
|
|
if [ -n "$SDK" ]; then
|
|
PLATS=$(ls "$SDK/platforms" 2>/dev/null | tr '\n' ' ')
|
|
BT=$(ls "$SDK/build-tools" 2>/dev/null | tr '\n' ' ')
|
|
[ -n "$PLATS" ] && ok "platforms: $PLATS" || warn "no platforms installed — e.g. 'sdkmanager \"platforms;android-34\"'"
|
|
[ -n "$BT" ] && ok "build-tools: $BT" || warn "no build-tools installed — e.g. 'sdkmanager \"build-tools;34.0.0\"'"
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
hdr "Gradle (for generating the wrapper)"
|
|
GRADLE_BIN=""
|
|
if command -v gradle >/dev/null 2>&1; then
|
|
GRADLE_BIN=$(command -v gradle); ok "gradle on PATH: $GRADLE_BIN ($(gradle --version 2>/dev/null | awk '/^Gradle/{print $2}'))"
|
|
else
|
|
warn "gradle not on PATH — searching disk for a cached distribution..."
|
|
for g in /opt/gradle-*/bin/gradle "$HOME"/.gradle/wrapper/dists/gradle-*/*/gradle-*/bin/gradle; do
|
|
[ -x "$g" ] && { echo " found: $g"; GRADLE_BIN="$g"; }
|
|
done
|
|
if [ -n "$GRADLE_BIN" ]; then
|
|
ok "Use one of the above to bootstrap the wrapper, e.g.: \"$GRADLE_BIN\" wrapper --gradle-version <ver>"
|
|
else
|
|
bad "No gradle binary found. Once a skeleton with a committed wrapper exists, ./gradlew self-bootstraps."
|
|
echo " If you have NO wrapper and NO gradle, ask the user to install one or copy a gradle-wrapper.jar."
|
|
fi
|
|
fi
|
|
|
|
hdr "Result"
|
|
if [ "$FAIL" -eq 0 ]; then ok "Environment looks usable for an Android build."; else bad "Blockers above must be resolved (or flagged to the user) before scaffolding."; fi
|
|
exit $FAIL
|