Make 'tauri android dev --open' find a Toolbox-installed Android Studio
cargo-mobile2 locates Studio by scanning XDG data dirs for a .desktop entry
whose Name is exactly "Android Studio", then runs its Exec line. A standalone
install writes that name; 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, failing with an ENOENT that
names every env var except the actual problem.
android-setup.sh now writes a hidden shim entry when no exact-name match
exists, reusing the Exec line Toolbox already generated rather than hardcoding
a path. Idempotent: a later run reports Studio as discoverable and rewrites
nothing.
This commit is contained in:
@@ -178,6 +178,14 @@ build fails with `failed to read missing addr file`.
|
|||||||
With the dev session running, Studio's device dropdown, Device Manager
|
With the dev session running, Studio's device dropdown, Device Manager
|
||||||
(emulator), and debugger all work normally.
|
(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
|
To build without Studio and without a dev server, use `cargo tauri android
|
||||||
build` — that path needs no addr file.
|
build` — that path needs no addr file.
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,79 @@ for t in "${RUST_TARGETS[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
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" <<DESKTOP
|
||||||
|
[Desktop Entry]
|
||||||
|
# Shim so tools that look up Android Studio by its canonical XDG name can find
|
||||||
|
# a JetBrains Toolbox install, which names its entry with the release version.
|
||||||
|
# Written by mtgc's scripts/android-setup.sh. Safe to delete.
|
||||||
|
Type=Application
|
||||||
|
Name=Android Studio
|
||||||
|
Exec=$STUDIO_EXEC
|
||||||
|
Categories=Development;IDE;
|
||||||
|
Terminal=false
|
||||||
|
StartupWMClass=jetbrains-studio
|
||||||
|
NoDisplay=true
|
||||||
|
DESKTOP
|
||||||
|
info "wrote $APPS/android-studio.desktop so 'tauri android dev --open' can find Studio"
|
||||||
|
else
|
||||||
|
warn "Android Studio not found — 'cargo tauri android dev --open' won't be able to launch it."
|
||||||
|
warn "Run 'cargo tauri android dev' and open src-tauri/gen/android in Studio yourself."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- 8. The environment the build needs ------------------------------------
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user