android-emulator-runner icon indicating copy to clipboard operation
android-emulator-runner copied to clipboard

API 30 emulator shows com.android.systemui ANR on start

Open pyricau opened this issue 4 years ago • 7 comments

When the API 30 emulator starts, it shows an Application Not Responding (ANR) dialog for the com.android.systemui process. That ANR stays on for the duration of the tests. Most tests will run fine, the ANR is about the systemui process and not the app under test. However, any test that relies on a test activity window gaining focus will fail, because the focus is held by the ANR dialog.

This has been an issue for 2 of our libraries, see https://github.com/square/radiography/pull/132 and https://github.com/square/curtains/pull/6

Note that in the latter PR we found a work around: we leverage UI Automator to dismiss the dialog on test start.

pyricau avatar Mar 02 '21 00:03 pyricau

This PR might help, although I haven't tried on API 30, I was seeing the same issue very often on API 29.

https://github.com/ReactiveCircus/android-emulator-runner/pull/130

AfzalivE avatar Mar 02 '21 02:03 AfzalivE

Just released the @AfzalivE's change that increases the number of cores used from 1 to 2 to improve stability.

Please let us know if this makes things better / worse :)

ychescale9 avatar Mar 04 '21 23:03 ychescale9

Any reason this would increase the run times for tests? I would expect it to do the opposite, but I've been seeing a lot more shards timeout roughly around the time when this multi-core change was released I think.

zach-klippenstein avatar Mar 05 '21 21:03 zach-klippenstein

Any reason this would increase the run times for tests? I would expect it to do the opposite, but I've been seeing a lot more shards timeout roughly around the time when this multi-core change was released I think.

I would expect it to do the opposite unless the host system isn't able to handle it? Any runs you could link to that were affected?

I don't think I've seen many shard timeouts in our projects, mostly just emulator crashes.

AfzalivE avatar Mar 05 '21 21:03 AfzalivE

System dialogs should be closable in tests. Send a Intent.ACTION_CLOSE_SYSTEM_DIALOGS broadcast when initializing tests. It is deprecated for general in app use, but OK to be used in tests.

@Before
public void setUp() {
    // Implies the use of ActivityScenario, instead of ActivityScenarioRule or ActivityTestRule
    ActivityScenario.launch(MainActivity.class).onActivity(activity -> {
        activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
    });
}

ViliusSutkus89 avatar Jan 29 '22 21:01 ViliusSutkus89

We have also been experiencing this, while running Detox tests on GitHub Actions, like this:

      - name: Start emulator and run Detox integration tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 30
          target: default
          arch: x86_64
          profile: pixel
          avd-name: Pixel_3a_API_30
          script: yarn detox test --configuration android

The PR adding reactivecircus/android-emulator-runner: https://github.com/upleveled/hotline-bling-codealong/pull/26

The errors that we experience appear like the following, for example in this test run: https://github.com/upleveled/hotline-bling-codealong/runs/5967201257?check_suite_focus=true

$ /Users/runner/work/hotline-bling-codealong/hotline-bling-codealong/node_modules/.bin/detox test --configuration android
06:34:36.011 detox[3922] INFO:  [test.js] DETOX_CONFIGURATION="android" DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1649658875994 DETOX_USE_CUSTOM_LOGGER=true jest --config /Users/runner/work/hotline-bling-codealong/hotline-bling-codealong/e2e/jest.config.js --testNamePattern '^((?!:ios:).)*$' --maxWorkers 1 e2e
06:35:28.222 detox[3923] INFO:  Example is assigned to emulator-5554 (Pixel_3a_API_30)
06:35:37.182 detox[3923] INFO:  Example: should have header element
06:35:47.847 detox[3923] INFO:  [APP_STATUS] The app seems to be idle
06:35:55.202 detox[3923] INFO:  Example: should have header element [FAIL]

FAIL e2e/appStarts.e2e.js (70.676 s)
  Example
    ✕ should have header element (17533 ms)

  ● Example › should have header element

    DetoxRuntimeError: Test Failed: Waited for the root of the view hierarchy to have window focus and not request layout for 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Root:
    Root{application-window-token=android.view.ViewRootImpl$W@188a739, window-token=android.view.ViewRootImpl$W@188a739, has-window-focus=false, layout-params-type=1, layout-params-string={(0,0)(fillxfill) sim={adjust=resize forwardNavigation} ty=BASE_APPLICATION wanim=0x10302fe
      fl=LAYOUT_IN_SCREEN FORCE_NOT_FULLSCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
      pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
      fitSides=}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(fillxfill) sim={adjust=resize forwardNavigation} ty=BASE_APPLICATION wanim=0x10302fe
      fl=LAYOUT_IN_SCREEN FORCE_NOT_FULLSCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
      pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
      fitSides=}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}}

      11 |
      12 |   it('should have header element', async () => {
    > 13 |     await expect(element(by.id('HeaderView'))).toBeVisible();
         |                                                ^
      14 |   });
      15 | });
      16 |

      at _callee3$ (appStarts.e2e.js:13:48)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:293:22)
      at Generator.next (../node_modules/regenerator-runtime/runtime.js:118:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:63:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:154:20)
      at ../node_modules/regenerator-runtime/runtime.js:189:11

06:35:55.655 detox[3922] ERROR: [cli.js] Command failed: jest --config /Users/runner/work/hotline-bling-codealong/hotline-bling-codealong/e2e/jest.config.js --testNamePattern '^((?!:ios:).)*$' --maxWorkers 1 e2e

The screenshot that Detox takes on failure:

karlhorky avatar Apr 11 '22 08:04 karlhorky

One workaround that seems to be pretty stable so far is to switch to the aosp_atd images ("Slimmer emulation system images for automated tests"):

      - name: Start emulator and run Detox integration tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          target: aosp_atd
          api-level: 30
          arch: x86
          channel: canary
          profile: pixel
          avd-name: Pixel_3a_API_30_AOSP
          script: yarn detox test --configuration android

Above this step, I also added caching for the AVD snapshots, as suggested in the readme for this action:

      - name: Cache AVD snapshot
        uses: actions/cache@v3
        id: avd-cache
        with:
          path: |
            ~/.android/avd/*
            ~/.android/adb*
          key: avd-30-aosp-atd

      - name: Create AVD and generate snapshot for caching
        if: steps.avd-cache.outputs.cache-hit != 'true'
        uses: reactivecircus/android-emulator-runner@v2
        with:
          target: aosp_atd
          api-level: 30
          arch: x86
          channel: canary
          profile: pixel
          avd-name: Pixel_3a_API_30_AOSP
          force-avd-creation: false
          emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: false
          script: echo "Generated AVD snapshot for caching"

Full example: https://github.com/upleveled/hotline-bling-codealong/

karlhorky avatar Apr 11 '22 13:04 karlhorky

Closing per the few workarounds in the thread, and this being emulator related rather than action related.

mrk-han avatar Nov 02 '22 04:11 mrk-han