diff --git a/README.md b/README.md index ce80d32..a4404fc 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,14 @@ build fails with `failed to read missing addr file`. With the dev session running, Studio's device dropdown, Device Manager (emulator), and debugger all work normally. +> **JetBrains Toolbox users:** `--open` finds Studio by scanning XDG data dirs +> for a `.desktop` entry whose `Name` is *exactly* `Android Studio`. Toolbox +> writes a versioned name instead (e.g. `Android Studio Quail 2 2026.1.2 Patch +> 1`), so the lookup misses and the launch fails with a confusing +> `Cmd(["Android Studio"]) ... No such file or directory`. `android-setup.sh` +> drops in a hidden shim entry (`~/.local/share/applications/android-studio.desktop`) +> to fix this; delete that file to undo it. + To build without Studio and without a dev server, use `cargo tauri android build` — that path needs no addr file. diff --git a/scripts/android-setup.sh b/scripts/android-setup.sh index e6a07ef..4440fb3 100755 --- a/scripts/android-setup.sh +++ b/scripts/android-setup.sh @@ -174,7 +174,79 @@ for t in "${RUST_TARGETS[@]}"; do fi done -# --- 7. The environment the build needs ------------------------------------ +# --- 7. Make Android Studio findable by its canonical XDG name ------------- +# +# `cargo tauri android dev --open` (cargo-mobile2) locates Studio by scanning +# XDG data dirs for a .desktop entry whose Name is *exactly* "Android Studio", +# then running its Exec line. A standalone install writes that name, but +# JetBrains Toolbox writes a versioned one ("Android Studio Quail 2 2026.1.2 +# Patch 1"), so the lookup misses and it falls back to running "Android Studio" +# as a literal command — which fails with a confusing ENOENT. Drop in a hidden +# shim entry when no exact match exists. + +xdg_app_dirs() { + echo "${XDG_DATA_HOME:-$HOME/.local/share}/applications" + local IFS=: + for d in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do echo "$d/applications"; done +} + +has_studio_entry() { + local d f + while read -r d; do + [ -d "$d" ] || continue + for f in "$d"/*.desktop; do + [ -f "$f" ] || continue + # Name= must match exactly, and only within the [Desktop Entry] section. + if grep -qx 'Name=Android Studio' "$f"; then return 0; fi + done + done < <(xdg_app_dirs) + return 1 +} + +find_studio_exec() { + # Prefer an Exec line already written by Toolbox (it tracks the real path); + # otherwise fall back to well-known install locations. + local f exec_line d + for f in "${XDG_DATA_HOME:-$HOME/.local/share}"/applications/jetbrains-studio-*.desktop; do + [ -f "$f" ] || continue + exec_line="$(sed -n 's/^Exec=//p' "$f" | head -1)" + [ -n "$exec_line" ] && { echo "$exec_line"; return 0; } + done + for d in \ + "$HOME/.local/share/JetBrains/Toolbox/apps/android-studio/bin/studio" \ + "$HOME/android-studio/bin/studio.sh" \ + /opt/android-studio/bin/studio.sh + do + [ -x "$d" ] && { echo "\"$d\" %u"; return 0; } + done + return 1 +} + +if has_studio_entry; then + info "Android Studio is discoverable by name (--open will work)" +elif STUDIO_EXEC="$(find_studio_exec)"; then + APPS="${XDG_DATA_HOME:-$HOME/.local/share}/applications" + mkdir -p "$APPS" + cat > "$APPS/android-studio.desktop" <