mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
py: scripts/boot-emulator
This commit is contained in:
parent
f71aa07949
commit
d77fa13903
2 changed files with 71 additions and 28 deletions
71
scripts/boot-emulator.py
Executable file
71
scripts/boot-emulator.py
Executable file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
emu_process = None
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(sig, frame):
|
||||||
|
if emu_process is not None:
|
||||||
|
emu_process.signal(signal.SIGINT)
|
||||||
|
|
||||||
|
|
||||||
|
def make_cmdline_tools_path(android_home: Path) -> str:
|
||||||
|
return android_home / "cmdline-tools" / "latest" / "bin"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
android_home = os.getenv("ANDROID_HOME")
|
||||||
|
if not android_home:
|
||||||
|
raise RuntimeError("$ANDROID_HOME must be set to use this script")
|
||||||
|
android_home = Path(android_home)
|
||||||
|
api_level = os.getenv("ANDROID_API_LEVEL")
|
||||||
|
if not api_level:
|
||||||
|
print("$ANDROID_API_LEVEL not defined; defaulting to 33")
|
||||||
|
api_level = "33"
|
||||||
|
cmdline_path = make_cmdline_tools_path(android_home)
|
||||||
|
image_package = f"system-images;android-{api_level};google_apis;x86_64"
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
cmdline_path / "sdkmanager",
|
||||||
|
image_package,
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
cmdline_path / "avdmanager",
|
||||||
|
"create",
|
||||||
|
"avd",
|
||||||
|
"--force",
|
||||||
|
"-n",
|
||||||
|
f"Pixel_XL_API_{api_level}",
|
||||||
|
"--abi",
|
||||||
|
"google_apis/x86_64",
|
||||||
|
"--package",
|
||||||
|
image_package,
|
||||||
|
"--device",
|
||||||
|
"pixel_xl",
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
emu_process = subprocess.Popen(
|
||||||
|
[
|
||||||
|
android_home / "emulator" / "emulator",
|
||||||
|
"-avd",
|
||||||
|
f"Pixel_XL_API_{api_level}",
|
||||||
|
"-gpu",
|
||||||
|
"swiftshader_indirect",
|
||||||
|
"-noaudio",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
emu_process.wait()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -1,28 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Creates and boots an emulator that exactly matches the one in our CI. It is recommended
|
|
||||||
# to use this as the target device for screenshot tests.
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
[ -n "${ANDROID_HOME:-}" ] || {
|
|
||||||
echo "ANDROID_HOME must be set to use this script"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
[ -n "${ANDROID_API_LEVEL:-}" ] || { echo "ANDROID_API_LEVEL not defined; defaulting to 33"; }
|
|
||||||
|
|
||||||
API_LEVEL="${ANDROID_API_LEVEL:-33}"
|
|
||||||
|
|
||||||
sdkmanager "system-images;android-${API_LEVEL};google_apis;x86_64"
|
|
||||||
|
|
||||||
echo no | "${ANDROID_HOME}"/cmdline-tools/latest/bin/avdmanager create avd \
|
|
||||||
--force \
|
|
||||||
-n "Pixel_XL_API_${API_LEVEL}" \
|
|
||||||
--abi 'google_apis/x86_64' \
|
|
||||||
--package "system-images;android-${API_LEVEL};google_apis;x86_64" \
|
|
||||||
--device 'pixel_xl'
|
|
||||||
|
|
||||||
"${ANDROID_HOME}"/emulator/emulator \
|
|
||||||
-avd "Pixel_XL_API_${API_LEVEL}" \
|
|
||||||
-gpu 'swiftshader_indirect' \
|
|
||||||
-noaudio
|
|
Loading…
Add table
Add a link
Reference in a new issue