diff --git a/scripts/boot_emulator.sh b/scripts/boot_emulator.sh index 5f7df108..10e607cf 100755 --- a/scripts/boot_emulator.sh +++ b/scripts/boot_emulator.sh @@ -3,19 +3,26 @@ # 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 -euxo pipefail +set -euo pipefail -[ -n "${ANDROID_SDK_ROOT}" ] || { echo "ANDROID_SDK_ROOT must be set to use this script"; exit 1; } +[ -n "${ANDROID_SDK_ROOT:-}" ] || { + echo "ANDROID_SDK_ROOT must be set to use this script" + exit + 1 +} +[ -n "${ANDROID_API_LEVEL:-}" ] || { echo "ANDROID_API_LEVEL not defined; defaulting to 30"; } + +API_LEVEL="${ANDROID_API_LEVEL:-30}" echo no | "${ANDROID_SDK_ROOT}"/cmdline-tools/latest/bin/avdmanager create avd \ --force \ -n Pixel_XL_API_30 \ --abi 'google_apis/x86' \ - --package 'system-images;android-30;google_apis;x86' \ + --package "system-images;android-${API_LEVEL};google_apis;x86" \ --device 'pixel_xl' "${ANDROID_SDK_ROOT}"/emulator/emulator \ - -avd Pixel_XL_API_30 \ + -avd "Pixel_XL_API_${API_LEVEL}" \ -no-window \ -gpu swiftshader_indirect \ -no-snapshot \ diff --git a/scripts/setup_environment.sh b/scripts/setup_environment.sh index 55595f74..0aacc518 100755 --- a/scripts/setup_environment.sh +++ b/scripts/setup_environment.sh @@ -1,10 +1,19 @@ #!/usr/bin/env bash -set -euxo pipefail +# Installs the latest command line tools and sets up the necessary packages for an Android emulator +# for API level $ANDROID_API_LEVEL, or API 30 if unspecified. + +set -euo pipefail CMDLINE_TOOLS_URL_MAC="https://dl.google.com/android/repository/commandlinetools-mac-6858069_latest.zip" CMDLINE_TOOLS_URL_LINUX="https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip" +[ -n "${ANDROID_SDK_ROOT:-}" ] || { + echo "ANDROID_SDK_ROOT must be set to use this script" + exit + 1 +} + if [ "$(uname)" == "Linux" ]; then wget "${CMDLINE_TOOLS_URL_LINUX}" -O /tmp/tools.zip -o /dev/null elif [ "$(uname)" == "Darwin" ]; then @@ -13,13 +22,21 @@ else echo "This script only works on Linux and Mac" exit 1 fi + +[ -n "${ANDROID_API_LEVEL:-}" ] || { echo "ANDROID_API_LEVEL not defined; defaulting to 30"; } + +API_LEVEL="${ANDROID_API_LEVEL:-30}" + unzip -qo /tmp/tools.zip -d "${ANDROID_SDK_ROOT}/latest" mkdir -p "${ANDROID_SDK_ROOT}/cmdline-tools" +if [ -d "${ANDROID_SDK_ROOT}/cmdline-tools" ]; then + rm -rf "${ANDROID_SDK_ROOT}/cmdline-tools" +fi +mkdir -p "${ANDROID_SDK_ROOT}/cmdline-tools" mv -v "${ANDROID_SDK_ROOT}/latest/cmdline-tools" "${ANDROID_SDK_ROOT}/cmdline-tools/latest" export PATH="${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${PATH}" -sdkmanager --install 'build-tools;30.0.3' platform-tools 'platforms;android-30' +sdkmanager --install 'build-tools;30.0.3' platform-tools "platforms;android-${API_LEVEL}" sdkmanager --install emulator -sdkmanager --install 'system-images;android-30;google_apis;x86' - +sdkmanager --install "system-images;android-${API_LEVEL};google_apis;x86"