From 1fb981f9fc06294aea9727c2e64454a316b9f58a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 23:56:37 +0000 Subject: [PATCH 1/4] Initial plan From 71f570c223af7df3df4e6874e55c2775a2cc8a02 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:00:34 +0000 Subject: [PATCH 2/4] Fix Android emulator CI job by replacing action with manual emulator startup Co-authored-by: kirklandsign <107070759+kirklandsign@users.noreply.github.com> --- .github/workflows/_android.yml | 99 +++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/.github/workflows/_android.yml b/.github/workflows/_android.yml index 7b67c340350..27c89dcfa55 100644 --- a/.github/workflows/_android.yml +++ b/.github/workflows/_android.yml @@ -74,6 +74,8 @@ jobs: python-version: '3.10' - name: Install Android dependencies + env: + ANDROID_HOME: /opt/android/sdk shell: bash run: | set -eux @@ -81,6 +83,14 @@ jobs: # Reuse the script that install Android on ET Docker image sudo -E bash .ci/docker/common/install_android.sh + # Move cmdline-tools to the proper structure for SDK manager + sudo mkdir -p $ANDROID_HOME/cmdline-tools + sudo mv /opt/cmdline-tools $ANDROID_HOME/cmdline-tools/latest + + # Install emulator and system images + sudo yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root="$ANDROID_HOME" "emulator" + sudo yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root="$ANDROID_HOME" "system-images;android-${{ env.API_LEVEL }};default;x86_64" + # After https://github.com/ReactiveCircus/android-emulator-runner/releases/tag/v2.33.0 release, # it seems that we need to chown the Android setup to the current user instead of root to # avoid permission issue @@ -107,23 +117,76 @@ jobs: ~/.android/adb* key: avd-${{ env.API_LEVEL }} - # NB: It takes about 10m to cold boot the emulator here - - name: Run Android emulator + - name: Create AVD env: ANDROID_HOME: /opt/android/sdk - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.API_LEVEL }} - arch: x86_64 - script: ./scripts/run_android_emulator.sh - # NB: This is to boot the emulator faster following the instructions on - # https://github.com/ReactiveCircus/android-emulator-runner. The max number - # of cores we can set is 6, any higher number will be reduced to 6. - cores: 6 - ram-size: 16384M - heap-size: 12288M - force-avd-creation: false - disable-animations: true - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - # This is to make sure that the job doesn't fail flakily - emulator-boot-timeout: 900 + shell: bash + run: | + set -eux + # Create AVD if it doesn't exist + if [ ! -d "$HOME/.android/avd/test_avd.avd" ]; then + echo "Creating AVD" + echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd \ + --force \ + --name test_avd \ + --package "system-images;android-${{ env.API_LEVEL }};default;x86_64" \ + --abi x86_64 \ + --device "pixel_5" + else + echo "AVD already exists" + fi + + - name: Start Emulator + env: + ANDROID_HOME: /opt/android/sdk + shell: bash + run: | + set -eux + # Start emulator in background with optimized flags + $ANDROID_HOME/emulator/emulator \ + -avd test_avd \ + -no-snapshot-load \ + -no-window \ + -gpu swiftshader_indirect \ + -no-boot-anim \ + -noaudio \ + -camera-back none \ + -cores 6 \ + -memory 16384 \ + -no-snapshot-save & + + # Start ADB server + $ANDROID_HOME/platform-tools/adb start-server + + # Wait for emulator to boot (up to 15 minutes) + for i in {1..90}; do + boot_completed=$($ANDROID_HOME/platform-tools/adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') + if [[ "$boot_completed" == "1" ]]; then + echo "Emulator booted successfully." + break + fi + echo "Waiting for emulator to boot... (attempt $i/90)" + sleep 10 + done + + # Verify boot completion + boot_status=$($ANDROID_HOME/platform-tools/adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') + if [[ "$boot_status" != "1" ]]; then + echo "ERROR: Emulator failed to boot within timeout" + exit 1 + fi + + - name: Check Devices + env: + ANDROID_HOME: /opt/android/sdk + shell: bash + run: | + set -eux + echo "Listing connected devices:" + $ANDROID_HOME/platform-tools/adb devices + + - name: Run Android Tests + env: + ANDROID_HOME: /opt/android/sdk + shell: bash + run: ./scripts/run_android_emulator.sh From 34e135f123c97d79b12c339a112c7c1461170ce6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:02:26 +0000 Subject: [PATCH 3/4] Address code review feedback: add path check and extract device ID to env var Co-authored-by: kirklandsign <107070759+kirklandsign@users.noreply.github.com> --- .github/workflows/_android.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/_android.yml b/.github/workflows/_android.yml index 27c89dcfa55..7ed0e600ed2 100644 --- a/.github/workflows/_android.yml +++ b/.github/workflows/_android.yml @@ -56,6 +56,7 @@ jobs: env: ANDROID_NDK_VERSION: r28c API_LEVEL: 34 + EMULATOR_DEVICE_ID: emulator-5554 steps: - name: Setup SSH (Click me for login details) uses: pytorch/test-infra/.github/actions/setup-ssh@main @@ -84,8 +85,13 @@ jobs: sudo -E bash .ci/docker/common/install_android.sh # Move cmdline-tools to the proper structure for SDK manager - sudo mkdir -p $ANDROID_HOME/cmdline-tools - sudo mv /opt/cmdline-tools $ANDROID_HOME/cmdline-tools/latest + if [ -d /opt/cmdline-tools ]; then + sudo mkdir -p $ANDROID_HOME/cmdline-tools + sudo mv /opt/cmdline-tools $ANDROID_HOME/cmdline-tools/latest + else + echo "ERROR: /opt/cmdline-tools not found after installation" + exit 1 + fi # Install emulator and system images sudo yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root="$ANDROID_HOME" "emulator" @@ -160,7 +166,7 @@ jobs: # Wait for emulator to boot (up to 15 minutes) for i in {1..90}; do - boot_completed=$($ANDROID_HOME/platform-tools/adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') + boot_completed=$($ANDROID_HOME/platform-tools/adb -s ${{ env.EMULATOR_DEVICE_ID }} shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') if [[ "$boot_completed" == "1" ]]; then echo "Emulator booted successfully." break @@ -170,7 +176,7 @@ jobs: done # Verify boot completion - boot_status=$($ANDROID_HOME/platform-tools/adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') + boot_status=$($ANDROID_HOME/platform-tools/adb -s ${{ env.EMULATOR_DEVICE_ID }} shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') if [[ "$boot_status" != "1" ]]; then echo "ERROR: Emulator failed to boot within timeout" exit 1 From f14088a4868f128c8cf60e31342b42f894da2bf2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:03:37 +0000 Subject: [PATCH 4/4] Improve emulator startup: check device detection before boot status Co-authored-by: kirklandsign <107070759+kirklandsign@users.noreply.github.com> --- .github/workflows/_android.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_android.yml b/.github/workflows/_android.yml index 7ed0e600ed2..3f065e1246c 100644 --- a/.github/workflows/_android.yml +++ b/.github/workflows/_android.yml @@ -164,14 +164,23 @@ jobs: # Start ADB server $ANDROID_HOME/platform-tools/adb start-server - # Wait for emulator to boot (up to 15 minutes) + # Wait for emulator device to be detected and boot (up to 15 minutes) + echo "Waiting for emulator device to be detected..." for i in {1..90}; do + # First check if the device is detected + if ! $ANDROID_HOME/platform-tools/adb devices | grep -q "${{ env.EMULATOR_DEVICE_ID }}"; then + echo "Device not yet detected... (attempt $i/90)" + sleep 10 + continue + fi + + # Then check if boot is completed boot_completed=$($ANDROID_HOME/platform-tools/adb -s ${{ env.EMULATOR_DEVICE_ID }} shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') if [[ "$boot_completed" == "1" ]]; then echo "Emulator booted successfully." break fi - echo "Waiting for emulator to boot... (attempt $i/90)" + echo "Device detected but waiting for boot to complete... (attempt $i/90)" sleep 10 done @@ -179,6 +188,7 @@ jobs: boot_status=$($ANDROID_HOME/platform-tools/adb -s ${{ env.EMULATOR_DEVICE_ID }} shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') if [[ "$boot_status" != "1" ]]; then echo "ERROR: Emulator failed to boot within timeout" + $ANDROID_HOME/platform-tools/adb devices exit 1 fi