diff --git a/build/scripts/android-sdk-emu.inc.sh b/build/scripts/android-sdk-emu.inc.sh index 0a2374930..b17769900 100644 --- a/build/scripts/android-sdk-emu.inc.sh +++ b/build/scripts/android-sdk-emu.inc.sh @@ -74,20 +74,40 @@ EMU_UPDATE_FILE="$HOME/.android/emu-update-last-check.ini" mkdir -p "$UNO_UITEST_SCREENSHOT_PATH" +# Retry wrapper for sdkmanager --install to handle transient network/unzip failures. +# Retries up to 3 times with increasing back-off (1s, 2s). +sdkmanager_install() { + local max_attempts=3 + local attempt=1 + while (( attempt <= max_attempts )); do + if echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" \ + "--sdk_root=${ANDROID_HOME}" --install "$@" | tr '\r' '\n' | uniq; then + return 0 + fi + if (( attempt < max_attempts )); then + echo "sdkmanager --install $* failed (attempt $attempt/$max_attempts), retrying in ${attempt}s..." + sleep "$attempt" + fi + ((attempt++)) + done + echo "sdkmanager --install $* failed after $max_attempts attempts" + return 1 +} + install_android_sdk() { SIMULATOR_APILEVEL="$1" if [[ ! -f "$SDK_MGR_TOOLS_FLAG" ]]; then touch "$SDK_MGR_TOOLS_FLAG" - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'tools'| tr '\r' '\n' | uniq - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'platform-tools' | tr '\r' '\n' | uniq - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'build-tools;36.0.0' | tr '\r' '\n' | uniq - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install 'extras;android;m2repository' | tr '\r' '\n' | uniq + sdkmanager_install 'tools' + sdkmanager_install 'platform-tools' + sdkmanager_install 'build-tools;36.0.0' + sdkmanager_install 'extras;android;m2repository' fi - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install "platforms;android-$SIMULATOR_APILEVEL" | tr '\r' '\n' | uniq - echo "y" | "$LATEST_CMDLINE_TOOLS_PATH/bin/sdkmanager" "--sdk_root=${ANDROID_HOME}" --install "system-images;android-$SIMULATOR_APILEVEL;google_apis_playstore;$ANDROID_SIMULATOR_ABI" | tr '\r' '\n' | uniq + sdkmanager_install "platforms;android-$SIMULATOR_APILEVEL" + sdkmanager_install "system-images;android-$SIMULATOR_APILEVEL;google_apis_playstore;$ANDROID_SIMULATOR_ABI" } if [[ ! -f "$EMU_UPDATE_FILE" ]]; then @@ -102,7 +122,10 @@ if [[ -f "$AVD_CONFIG_FILE" ]]; then else # Install AVD files install_android_sdk "$ANDROID_SIMULATOR_APILEVEL" - install_android_sdk 36 + + # API-36 platform is needed for build-tools/apkanalyzer, but the full + # system image (~1.5 GB) is not used for the emulator — skip it. + sdkmanager_install "platforms;android-36" if [[ -f "$ANDROID_HOME/platform-tools/platform-tools/adb" ]]; then # It appears that the platform-tools 29.0.6 are extracting into an incorrect path diff --git a/build/scripts/android-test-run.sh b/build/scripts/android-test-run.sh index f8f6ecc79..da342438a 100755 --- a/build/scripts/android-test-run.sh +++ b/build/scripts/android-test-run.sh @@ -23,7 +23,22 @@ export ANDROID_SIMULATOR_APILEVEL=34 source "$BUILD_SOURCESDIRECTORY/build/scripts/android-sdk-emu.inc.sh" -"$ANDROID_HOME/platform-tools/adb" install -r "$UNO_TEST_ANDROIDAPK_PATH" +# Retry adb install — the emulator may be transiently unresponsive right after boot. +adb_install_ok=false +for i in 1 2 3; do + if "$ANDROID_HOME/platform-tools/adb" install -r "$UNO_TEST_ANDROIDAPK_PATH"; then + adb_install_ok=true + break + fi + if [ "$i" -lt 3 ]; then + echo "adb install failed (attempt $i/3), retrying in ${i}s..." + sleep "$i" + fi +done +if [ "$adb_install_ok" = false ]; then + echo "ERROR: adb install failed after 3 attempts." + exit 1 +fi package_name=$("$LATEST_CMDLINE_TOOLS_PATH/bin/apkanalyzer" manifest application-id "$UNO_TEST_ANDROIDAPK_PATH") diff --git a/build/scripts/android-uitest-wait-systemui.sh b/build/scripts/android-uitest-wait-systemui.sh index e0f312083..6449d4ad9 100644 --- a/build/scripts/android-uitest-wait-systemui.sh +++ b/build/scripts/android-uitest-wait-systemui.sh @@ -69,8 +69,10 @@ while [[ -z ${LAUNCHER_READY} ]]; do case $UI_FOCUS in *"Not Responding"*) echo "Detected an ANR! Dismissing..." - $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_DPAD_RIGHT - $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_ENTER + # Guard keyevent calls: adb can transiently return 255 when the + # emulator is still settling, and set -e would kill the script. + $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_DPAD_RIGHT || true + $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_ENTER || true ;; *"Launcher"*) LAUNCHER_READY=true @@ -86,17 +88,17 @@ while [[ -z ${LAUNCHER_READY} ]]; do # For some reason the messaging app can be brought up in front # (DEBUG) Current focus: mCurrentFocus=Window{1170051 u0 com.google.android.apps.messaging/com.google.android.apps.messaging.ui.ConversationListActivity} # Try bringing back the home screen to check on the launcher. - $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_HOME + $ANDROID_HOME/platform-tools/adb shell input keyevent KEYCODE_HOME || true ;; esac done # Force terminate system UI to restart clean -"$ANDROID_HOME/platform-tools/adb" shell am force-stop com.android.systemui +"$ANDROID_HOME/platform-tools/adb" shell am force-stop com.android.systemui || true -"$ANDROID_HOME/platform-tools/adb" shell settings put global animator_duration_scale 0 -"$ANDROID_HOME/platform-tools/adb" shell settings put global transition_animation_scale 0 -"$ANDROID_HOME/platform-tools/adb" shell settings put global window_animation_scale 0 +"$ANDROID_HOME/platform-tools/adb" shell settings put global animator_duration_scale 0 || true +"$ANDROID_HOME/platform-tools/adb" shell settings put global transition_animation_scale 0 || true +"$ANDROID_HOME/platform-tools/adb" shell settings put global window_animation_scale 0 || true echo "Launcher is ready!"