diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 2f36b9a8..22209aa0 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -116,7 +116,7 @@ module.exports.list_images_using_avdmanager = function () { }; module.exports.list_images_using_android = function() { - return superspawn.spawn('android', ['list', 'avds']) + return superspawn.spawn('android', ['list', 'avd']) .then(function(output) { var response = output.split('\n'); var emulator_list = []; @@ -171,20 +171,10 @@ module.exports.list_images_using_android = function() { } */ module.exports.list_images = function() { - if (forgivingWhichSync('android')) { - return module.exports.list_images_using_android() - .catch(function(err) { - // try to use `avdmanager` in case `android` reports it is no longer available. - // this likely means the target machine is using a newer version of - // the android sdk, and possibly `avdmanager` is available. - if (err.code == 1 && err.stdout.indexOf('android command is no longer available')) { - return module.exports.list_images_using_avdmanager(); - } else { - throw err; - } - }); - } else if (forgivingWhichSync('avdmanager')) { + if (forgivingWhichSync('avdmanager')) { return module.exports.list_images_using_avdmanager(); + } else if (forgivingWhichSync('android')) { + return module.exports.list_images_using_android(); } else { return Q().then(function() { throw new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?'); @@ -228,6 +218,7 @@ module.exports.list_started = function() { }; // Returns a promise. +// TODO: we should remove this, there's a more robust method under android_sdk.js module.exports.list_targets = function() { return superspawn.spawn('android', ['list', 'targets'], {cwd: os.tmpdir()}) .then(function(output) { @@ -399,6 +390,7 @@ module.exports.create_image = function(name, target) { }); } else { console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.'); + // TODO: there's a more robust method for finding targets in android_sdk.js return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', this.list_targets()[0]]) .then(function() { // TODO: This seems like another error case, even though it always happens.