AndroidViewClient icon indicating copy to clipboard operation
AndroidViewClient copied to clipboard

ViewClient crash due to __parseTreeFromUiAutomatorDump ?

Open sooraj-sizon-pj opened this issue 2 years ago • 4 comments

Hi @dtmilano , I this error running AndroidViewClient on AWS ec2 instance image

Device is custom android emulator x86_64 running on AWS EC2 , I have same Emulator setup on my local env where AndroidViewClient works perfectly Where as on EC2 with same Automation script it goes through a few screens of android setupwizard and able to click on buttons and views and fails with this crash on like 4th or 5th step .

The emulator is running custom system-images build from AOSP A11_r1 tag has custom setup wizard another system app and a system service running very early at boot.

I ran uiautomatorviewer dump which returned

Xlib extension RANDR missing on display :1

Do you know what might cause this crash ?

sooraj-sizon-pj avatar Nov 06 '23 18:11 sooraj-sizon-pj

Are you using nested virtualization or bare metal EC2 instance? Is the setup wizard using animations? There's a known limitation of uiautomator not being able to obtain screen dump when the device is not idle (i.e. animation). To verifty that, if androidviewclient fails, you can try uiautomator dump immediately and verify the same error is obtained.

To overcome that limitation and others and adding extra functionality is that CulebraTester2-public backend exists. Perhaps you can give it a try.

dtmilano avatar Nov 07 '23 16:11 dtmilano

Are you using nested virtualization or bare metal EC2 instance? Is the setup wizard using animations?

I'm using EC2 bare metal instance (g4dn.metal)

There's a known limitation of uiautomator not being able to obtain screen dump when the device is not idle (i.e. animation). To verifty that, if androidviewclient fails, you can try uiautomator dump immediately and verify the same error is obtained.

To my surprise the same emulator build with setupwizard and everything works perfectly fine in my local machine running same ubuntu 22.04

To overcome that limitation and others and adding extra functionality is that CulebraTester2-public backend exists. Perhaps you can give it a try.

Thanks I will take a look ..

sooraj-sizon-pj avatar Nov 07 '23 18:11 sooraj-sizon-pj

To test after the error you should run

adb shell uiautomator dump

You missed shell in your screenshot.

dtmilano avatar Nov 07 '23 19:11 dtmilano

https://source.android.com/docs/setup/create/cuttlefish perhaps this helps.

dtmilano avatar Nov 09 '23 01:11 dtmilano

This was a bug in uiautomator for now simple workaround is add retries when this happens


MAX_RETRIES = 3
RETRY_DELAY = 1  # seconds

def retry_on_value_error(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        retries = 0
        while retries < MAX_RETRIES:
            try:
                return func(*args, **kwargs)
            except ValueError as e:
                print(f"Error: {e}, retrying... ({retries + 1}/{MAX_RETRIES})")
                time.sleep(RETRY_DELAY)
                retries += 1
        raise ValueError(f"Failed after {MAX_RETRIES} retries")
    return wrapper

viewClient.dump = retry_on_value_error(viewClient.dump)

Run this at the start of the script and every time uiautomnator sends empty xml it would retry

sooraj-sizon-pj avatar Jul 11 '24 12:07 sooraj-sizon-pj

Interesting, I thought it wasn't a recoverable error. Great that retrying works.

dtmilano avatar Jul 12 '24 05:07 dtmilano