mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Fix Android emulator app launch
Three issues prevented `run_android_emulator.sh` from launching the app:
- gradlew's shebang was a hardcoded Nix-store bash path (copied verbatim
from the nixpkgs Flutter SDK template) that breaks once that store path
is garbage-collected, surfacing as a misleading "ProcessException: No
such file or directory". The dev-shell now normalizes the gitignored
android/gradlew shebang to the portable "#!/usr/bin/env sh" on entry.
- `flutter run -d android` never matched: -d resolves a device by id/name,
not platform. Resolve the concrete id (e.g. emulator-5554) from
`flutter devices --machine` instead.
- Install raced the boot ("device is still booting"); wait for
sys.boot_completed=1 before launching.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
080222f121
commit
2817fc7cab
@@ -125,6 +125,18 @@
|
|||||||
printf '# >>> oott-nix >>>\nandroid.aapt2FromMavenOverride=%s\n# <<< oott-nix <<<\n' "$aapt2Bin" >> "$gradleProps"
|
printf '# >>> oott-nix >>>\nandroid.aapt2FromMavenOverride=%s\n# <<< oott-nix <<<\n' "$aapt2Bin" >> "$gradleProps"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Normalize the Android Gradle wrapper's shebang. The nixpkgs Flutter
|
||||||
|
# SDK ships a gradlew template whose shebang is hardcoded to a specific
|
||||||
|
# bash in the Nix store; flutter copies it verbatim into android/gradlew.
|
||||||
|
# When that store path is later garbage-collected (or Flutter updates),
|
||||||
|
# the interpreter vanishes and Gradle dies with a misleading
|
||||||
|
# "ProcessException: No such file or directory". gradlew is gitignored,
|
||||||
|
# so we rewrite it to the portable shebang on every entry.
|
||||||
|
gradlewFile="$(git rev-parse --show-toplevel 2>/dev/null || echo .)/frontend/android/gradlew"
|
||||||
|
if [ -f "$gradlewFile" ]; then
|
||||||
|
sed -i '1s|^#!.*|#!/usr/bin/env sh|' "$gradlewFile"
|
||||||
|
fi
|
||||||
|
|
||||||
DEV_SHELL=oott exec fish
|
DEV_SHELL=oott exec fish
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,15 +15,50 @@ if ! command -v flutter >/dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Print the id of the first connected Android device, or nothing if none is up.
|
||||||
|
# `flutter run -d <x>` matches a device by id/name, never by platform, so the
|
||||||
|
# literal "android" is not a usable target; we must resolve the concrete id
|
||||||
|
# (e.g. "emulator-5554") from flutter's own machine-readable device list.
|
||||||
|
android_device_id() {
|
||||||
|
flutter devices --machine 2>/dev/null | python3 -c '
|
||||||
|
import json, sys
|
||||||
|
try:
|
||||||
|
devices = json.load(sys.stdin)
|
||||||
|
except ValueError:
|
||||||
|
devices = []
|
||||||
|
for d in devices:
|
||||||
|
if str(d.get("targetPlatform", "")).startswith("android"):
|
||||||
|
print(d["id"])
|
||||||
|
break
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Block until the Android OS on the given device has finished booting. The
|
||||||
|
# device shows up in `flutter devices` as soon as adb connects, but installing
|
||||||
|
# before boot completes fails with "device is still booting", so we poll the
|
||||||
|
# sys.boot_completed property (adb shell emits CRLF, hence the trailing-\r trim).
|
||||||
|
wait_for_boot() {
|
||||||
|
local serial="$1"
|
||||||
|
adb -s "$serial" wait-for-device
|
||||||
|
until [ "$(adb -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = "1" ]; do
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Boot the emulator in the background if no Android device is connected yet.
|
# Boot the emulator in the background if no Android device is connected yet.
|
||||||
if ! flutter devices 2>/dev/null | grep -qi "android"; then
|
if [ -z "$(android_device_id)" ]; then
|
||||||
echo "No Android device detected, booting the emulator..."
|
echo "No Android device detected, booting the emulator..."
|
||||||
"$SCRIPT_DIR/run_android.sh" -no-snapshot-save &
|
"$SCRIPT_DIR/run_android.sh" -no-snapshot-save &
|
||||||
|
|
||||||
echo "Waiting for the emulator to come online..."
|
echo "Waiting for the emulator to come online..."
|
||||||
until flutter devices 2>/dev/null | grep -qi "android"; do
|
until [ -n "$(android_device_id)" ]; do
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec flutter run -d android "$@"
|
device_id="$(android_device_id)"
|
||||||
|
echo "Waiting for '$device_id' to finish booting..."
|
||||||
|
wait_for_boot "$device_id"
|
||||||
|
|
||||||
|
echo "Launching OOTT on '$device_id'..."
|
||||||
|
exec flutter run -d "$device_id" "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user