Appium 1.5 doesn't launch Android emulator

1.4.16 with the following capabilities would automatically launch the Android emulator:

platformName: 'Android',
deviceName: 'Android Emulator',
app: path.resolve('../myapp.apk'),
avd: 'Nexus_5_API_21'

1.5 doesn’t do that - logs show it trying to find connected devices for a while and then it fails with ‘Error: Could not find a connected Android device.’

Is this a bug or do I need to adjust the capabilities somehow?

2 Likes

I am seeing a similar behavior, but only when I don’t have an Android emulator already started. When one is running already I can run my tests and all of the defined AVDs will run. Once I shut them all down however Appium can’t see to start one of the AVDs.

Here is an example of the output I get when appium fails to start

[Appium] Welcome to Appium v1.5.0 (REV 733e169812eed33cec0626a82ad4f30eb988a24d)
[Appium] Non-default server args:
[Appium] log: ‘/Users/dans/Documents/git/appium/appium.log’
[Appium] avd: ‘AVD_for_Galaxy_S4’
[Appium] Deprecated server args:
[Appium] --avd => --default-capabilities ‘{“avd”:“AVD_for_Galaxy_S4”}’
[Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities:
[Appium] avd: ‘AVD_for_Galaxy_S4’
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] → POST /wd/hub/session
[MJSONWP] Calling AppiumDriver.createSession() with args: [{“avd”:“AVD_for_Galaxy_S4”,“platformVersion”:“4.4.2”,“app”:"/Users/dans/Documents/git/mobile/platforms/android/build/outputs/apk/android-debug.apk…
[Appium] Creating new AndroidDriver session
[Appium] Capabilities:
[Appium] avd: ‘AVD_for_Galaxy_S4’
[Appium] platformVersion: ‘4.4.2’
[Appium] app: ‘/Users/dans/Documents/git/mobile/platforms/android/build/outputs/apk/android-debug.apk’
[Appium] platformName: ‘Android’
[Appium] deviceName: ‘Galaxy S4’
[Appium] appActivity: ‘com.company.app.MainActivity’
[Appium] appPackage: ‘com.company.app’
[BaseDriver] Session created with session id: a8fe5612-3efe-4b3a-a360-c98f292003b0
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.7.0_71
[ADB] Checking whether adb is present
[ADB] Using adb from /usr/local/android-sdk/android-sdk-r24.4.1/platform-tools/adb
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices…
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server…
[debug] [ADB] Restarting adb`
…repeats…
[debug] [ADB] Could not find devices, restarting adb server…
[debug] [ADB] Restarting adb
…repeats…
[debug] [ADB] Restarting adb
[debug] [AndroidDriver] Shutting down Android driver
[AndroidDriver] Cannot shut down Android driver; it has already shut down
[MJSONWP] Encountered internal error running command: Error: Could not find a connected Android device.
at ADB.getDevices$ (lib/tools/system-calls.js:127:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at new Promise (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/es6.promise.js:197:7)
at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at getDevices (lib/tools/system-calls.js:130:18)
at ADB.getDevices$ (lib/tools/system-calls.js:144:20)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/$.microtask.js:19:5)
at doNTCallback0 (node.js:417:9)
at process._tickCallback (node.js:346:13)
[HTTP] ← POST /wd/hub/session 500 24349 ms - 179

This is likely a problem with adb not appium.

What are you seeing when do
adb devices

from your terminal?

I see nothing when I do

adb devices

but that’s presumably because I have no connected devices and no emulators running.

I don’t think it’s adb as when I switch to Appium 1.4.16 (without changing anything else) the emulator launch works again.
And then fails when I switch back to Appium 1.5.

The log output looks quite different as well - 1.4.16 shows lines like:

Getting connected emulators
0 emulator(s) connected
Trying to find Nexus_5_API_21 emulator
Launching Emulator with AVD Nexus_5_API_21, launchTimeout 120000ms and readyTimeout 120000ms
Checking whether emulator is present
Using emulator from /Users/jonesdar/fitmob/sdk-2016-01-13/tools/emulator

while it boots the emulator.
Those lines aren’t in the 1.5 logs which suggests the emulator launch code isn’t being run.

Note that when I say ‘emulator launch’ I’m talking about Appium starting an emulator that isn’t already running (sorry for any confusion).

As per my understanding appium does not internally start the avd.

We usually start it first using
emulator -avd “emulator Name”

then we run command

adb devices and it list something like “emulator-5555”

then appium will detect it and execute scripts on it.

Now in run time u can first execute this command using JAVA RunTime Class and then start u r appium server with correct capabilities it should work, unless 1.5 version has some bug

Appium 1.4.16 does internally start the avd if it’s not already running.
Appium 1.5 doesn’t.

Both versions internally start the iOS simulator if it’s not already running - which suggests the 1.5 avd behaviour is a bug.

1 Like

@jonesdar : Thanks for telling this I was not aware about this. I always have impression appium works on connected devices.

I hope the questioner can report this bug on appium repo. Till the fix come they can start AVD by JAVA code with command

I am not aware of this. It must have been an added feature (creep) that they removed for 1.5.

IOS simulators are very different from emulators, you can’t compare them.

That said, try raising a bug and see their response.

I am not aware of this. It must have been an added feature (creep)

It’s been the behaviour for nearly 2 years (since at least Appium 1.0.0).

To an Appium user Android emulators and iOS simulators are equivalent (both enable app testing without physical devices) - consistent behaviour across equivalents is a desirable feature in any software.

Bug raised: Appium 1.5 doesn't launch Android emulator · Issue #6233 · appium/appium · GitHub

3 Likes