appium: Android driver fails before emulator is booted

The problem

When I use avd capability to start emulator, android driver fails even before emulator is booted up.

adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
cmd: Can't find service: settings
cmd: Can't find service: settings

Environment

  • Appium version (or git revision) that exhibits the issue: 1.22.3
  • Desktop OS/version used to run Appium: MacOs 12.4
  • Node.js version (unless using Appium.app|exe): 18.5
  • Mobile platform/version under test: Android
  • Real device or emulator/simulator: simulator

Details

Used capabilities

            appiumOptions.AddAdditionalAppiumOption(MobileCapabilityType.PlatformName, "Android");
            appiumOptions.AddAdditionalAppiumOption("appPackage", "appPackage");
            appiumOptions.AddAdditionalAppiumOption("appActivity", "SplashScreen");
            appiumOptions.AddAdditionalAppiumOption("avd", "Pixel_2_API_31");
            appiumOptions.AddAdditionalAppiumOption("avdArgs", "-no-snapshot-load");
            appiumOptions.AddAdditionalAppiumOption("androidInstallTimeout", 120000); 
            appiumOptions.AddAdditionalAppiumOption("newCommandTimeout", 120); 
            appiumOptions.AddAdditionalAppiumOption("acceptInsecureCerts", true); 
            appiumOptions.AddAdditionalAppiumOption("appWaitDuration", 60000);
            appiumOptions.AddAdditionalAppiumOption("avdLaunchTimeout", 180000); 
            appiumOptions.AddAdditionalAppiumOption("avdReadyTimeout", 180000); 

            var driver = new AndroidDriver(ap, appiumOptions); // initialize Android 

When AndroidDriver is instantiated, it starts android emulator, emulator starts booting, shows google logo, appium fails with error:

adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
cmd: Can't find service: settings
cmd: Can't find service: settings

10 seconds later emulator is booted up to home screen properly. When I start emulator manually before running appium everything works just fine.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20

Most upvoted comments

@mykola-mokhnach

Im getting the same error, when running test against emulator using appium 2 and latest UIautomator plugin

An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/runner/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy'' exited with code 20'; Command output: cmd: Can't find service: settings
[0-0] cmd: Can't find service: settings
[0-0] cmd: Can't find service: settings
 alwaysMatch: {
[0-0]       'appium:platformName': 'android',
[0-0]       'appium:deviceName': 'nexus',
[0-0]       'appium:app': './src/test/api.apk',
[0-0]       'appium:platformVersion': '13',
[0-0]       'appium:uiautomator2ServerInstallTimeout': 150000,
[0-0]       'appium:appWaitForLaunch': true,
[0-0]       'appium:disableWindowAnimation': true,
[0-0]       'appium:autoGrantPermissions': true,
[0-0]       'appium:clearSystemFiles': true,
[0-0]       'appium:nativeWebScreenshot': true,
[0-0]       'appium:adbExecTimeout': 80000,
[0-0]       'appium:automationName': 'uiautomator2'
[0-0]     },

I’m afraid the timeout there is hardcoded. Although I don’t see a reason it could not be increased

@StephanB75 Try uia2 driver v. 2.4.5

I’ve changed the boot detection logic - lets see if it helps

Hey @StephanB75 I did have appium settings from previous runs. I have deleted it and we are back to first error again https://gist.github.com/jmalczak/efa9e97f3fecb5e93afc185a5873242a

was there an appium settings app from the previous runs on the device ? image

Try to delete it so that appium can reinstall it. That helped me in the past when switching versions.