Last active
May 7, 2024 07:34
-
-
Save tommie/336e908a95ded68037d5b99985d3f275 to your computer and use it in GitHub Desktop.
Wrapper script to add command line options to the AVD emulator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# Wrapper script to add command line options to the AVD emulator. | |
# | |
# avdmanager should support the studio.emu.params environment variable, but it doesn't handle commas well. | |
# | |
# ## Installation | |
# | |
# 1. Find your AVD home directory. It should have an `emulator` subdirectory. | |
# 2. Move the `emulator/emulator` file to `emulator/emulator-orig`. | |
# 3. Store this script as `emulator/emulator`. | |
# 4. After upgrades, you will have to do it all again. | |
# | |
# ## Usage | |
# | |
# Use the environment variable AVDX_EMU_PARAMS to set parameters directly. | |
# Or use the environment variable AVDX_EMU_PARAMS_FILE to set a file to read parameters from. | |
# Or add parameters directly to the params variable below. | |
# Do this before starting Android Studio or AVD Manager, since processes inherit environment variables from their parents. | |
# | |
# ## See Also | |
# | |
# * https://stackoverflow.com/questions/39397056/how-to-pass-command-line-options-to-the-emulator-in-android-studio | |
# * https://developer.android.com/studio/run/emulator-commandline.html | |
# * https://source.android.com/docs/automotive/start/passthrough | |
set -e | |
set -o pipefail | |
scriptdir=$(dirname "$(readlink -f "$0")") | |
scriptname=$(basename "$0") | |
realscriptname="$scriptname-orig" | |
emulator="$scriptdir/$realscriptname" | |
params=( "$@" ) | |
# Add more parameters here: | |
params+=( ) | |
if [ -r "$AVDX_EMU_PARAMS_FILE" ]; then | |
params+=( $(<$AVDX_EMU_PARAMS_FILE) ) | |
fi | |
if [ -n "$AVDX_EMU_PARAMS" ]; then | |
params+=( $AVDX_EMU_PARAMS ) | |
fi | |
exec "$emulator" "${params[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment