Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions build/scripts/android-sdk-emu.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 10x that value, 1~3s might not be enough to escape the same fate as previous attempt(s)
in grand scheme of things, 10~30s(1min total) is really nothing IF we can move forward

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we don't understand why it's failing in the first place. It just up and dies, with nothing in the log files. This makes it slightly annoying to reason about.

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
Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion build/scripts/android-test-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
16 changes: 9 additions & 7 deletions build/scripts/android-uitest-wait-systemui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"

Loading