Home » Android » Cordova error running on android emulator: "android: Command failed with exit code 2"

Cordova error running on android emulator: "android: Command failed with exit code 2"

Posted by: admin June 15, 2020 Leave a comment


I’m trying to run my cordova project in an android emulator:

cordova emulate android

The build is successful but the emulator is not starting and I get an error:

Error: android: Command failed with exit code 2

I get the same thing when running cordova requirements:

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
android: Command failed with exit code 2
Gradle: installed /opt/android-studio/gradle/gradle-3.2/bin/gradle
Error: Some of requirements check failed

I’ve upgraded Android SDK Tools to 26.0.1 and android command doesn’t work for me anymore. So I installed [email protected] as the release page says and use it in my project:

$ cordova platform ls
Installed platforms:
  android 6.2.1
Available platforms:
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ubuntu ~4.3.4
  webos ~3.7.0

But the error still happens. Does anyone has any ideas why this happens?

How to&Answers:

I think that a new version of Android SDK is not compatible with cordova emulation, so I change this:

return superspawn.spawn('android', ['list', 'avds'])

to this:

return superspawn.spawn('android', ['list', 'avd'])



and your error was fixed. That happens ’cause the command “android list avds” was changed to “android list avd” inside a new SDK. Thanx to Douglas Neves

If after that you’ll catch another error like this:

Failed to install ... Failure [INSTALL_FAILED_VERSION_DOWNGRADE]

You’ll need to change this:

var command = 'adb -s ' + target + ' install -r "' + apk + '"';

to this:

var command = 'adb uninstall "' + pkgName + '"; adb -s ' + target + ' install -r "' + apk + '"';

in the same file. This code will uninstall app before install it, so version problem will be disappeared.


you should update latest platform:

cordova platform remove android
cordova platform update [email protected]


You should save the whole workspace for ionic in under C drive with folder.

Execution failed for task ‘:mergeDebugResources’ error will be resolved.