Apparently both the driver.orientation and driver.rotate Ruby methods blow up the Appium session connected to an Android emulator that is of version 4.1 API 16 (Google APIs). I did not have this issue with API 19 or API 24.
When connecting via arc to debug this issue, I will run the command driver.orientation and the following error is returned in the Appium session console:
[HTTP] --> GET /wd/hub/session/ac635e11-d2fe-432a-ab7c-0f7d2a74b613/orientation {}
[MJSONWP] Calling AppiumDriver.getOrientation() with args: ["ac635e11-d2fe-432a-ab7c-0f7d2a74b613"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"orientation","params":{}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"orientation","params":{}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: orientation
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[AndroidBootstrap] [UIAUTO STDOUT] Error in testRunServer:
[AndroidBootstrap] [UIAUTO STDOUT] java.lang.NoSuchMethodError: com.android.uiautomator.core.UiDevice.getDisplayRotation
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.handler.Orientation.getRotation(Orientation.java:76)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.handler.Orientation.execute(Orientation.java:62)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:81)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:203)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:105)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:159)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:37)
[AndroidBootstrap] [UIAUTO STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:124)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
[AndroidBootstrap] [UIAUTO STDOUT] at dalvik.system.NativeStart.main(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stack=java.lang.NoSuchMethodError: com.android.uiautomator.core.UiDevice.getDisplayRotation
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.handler.Orientation.getRotation(Orientation.java:76)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.handler.Orientation.execute(Orientation.java:62)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:81)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:203)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:105)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:159)
[AndroidBootstrap] [UIAUTO STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:37)
[AndroidBootstrap] [UIAUTO STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:124)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
[AndroidBootstrap] [UIAUTO STDOUT] at dalvik.system.NativeStart.main(Native Method)
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[AndroidBootstrap] [UIAUTO STDOUT] Test results for UiAutomatorTestRunner=.E
[AndroidBootstrap] [UIAUTO STDOUT] Time: 31.522
[AndroidBootstrap] [UIAUTO STDOUT] FAILURES!!!
[AndroidBootstrap] [UIAUTO STDOUT] Tests run: 1, Failures: 0, Errors: 1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[UiAutomator] UiAutomator exited unexpectedly with code 0, signal null
[UiAutomator] Moving to state 'stopped'
[AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was 'UiAUtomator shut down unexpectedly'
[Appium] Removing session ac635e11-d2fe-432a-ab7c-0f7d2a74b613 from our master session list
[ADB] Getting connected devices...
[MJSONWP] Encountered internal error running command: Error: UiAUtomator shut down unexpectedly
at AndroidBootstrap.callee$2$0$ (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/lib/bootstrap.js:76:44)
at tryCatch (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at Promise.F (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
at AsyncIterator.enqueue (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
at AsyncIterator.prototype.(anonymous function) [as next] (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at Object.runtime.async (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at UiAutomator.callee$2$0 (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/build/lib/bootstrap.js:173:42)
at emitOne (events.js:96:13)
at UiAutomator.emit (events.js:188:7)
at UiAutomator.changeState (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator/lib/uiautomator.js:85:10)
at SubProcess. (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator/lib/uiautomator.js:47:14)
at emitTwo (events.js:106:13)
at SubProcess.emit (events.js:191:7)
at ChildProcess. (/private/var/folders/gw/g089b35s6d78n26n2xv12f91zjw115/T/AppTranslocation/824188FE-2DE0-46A5-A06D-B2A0DC47E091/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/teen_process/lib/teen_process.js:205:14)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
[HTTP] <-- GET /wd/hub/session/ac635e11-d2fe-432a-ab7c-0f7d2a74b613/orientation 500 51 ms - 205
[ADB] 1 device(s) connected
[ADB] Running '/Users/mario/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","com.product.some_product.demo"]
[ADB] Pressing the HOME button
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '/Users/mario/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","input","keyevent",3]
[AndroidBootstrap] Cannot shut down Android bootstrap; it has already shut down
[Logcat] Stopping logcat capture
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '/Users/mario/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.unlock"]
[AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
The arc error returned for displaying the Selenium exception is:
Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command. Original error: UiAUtomator shut down unexpectedly
from /usr/local/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
Since these methods work in API 19 and 24 it makes me stumped as to what I should do to work around this. I unfortunately need to be able to rotate my app. If anyone has some suggestions on how to work around this then I’m all ears
Capabilities I’m using:
[caps]
platformName = "Android"
platformVersion = "4.1"
deviceName = "Android 4.1 Emulator"
app = "../../app-debug.apk"
avd = "Nexus_5X_API_16"
avdArgs = "-no-boot-anim"
rotatable = true
orientation = "PORTRAIT"
Ruby:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Appium:
appium 1.6.5
Appium Gem Versions:
appium_console (2.3.0)
appium_lib (9.4.9)
Thanks!