diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js index 30056f46..df2448c0 100644 --- a/bin/templates/cordova/lib/build.js +++ b/bin/templates/cordova/lib/build.js @@ -26,6 +26,7 @@ var shell = require('shelljs'), fs = require('fs'), ROOT = path.join(__dirname, '..', '..'); var check_reqs = require('./check_reqs'); +var exec = require('./exec'); var LOCAL_PROPERTIES_TEMPLATE = '# This file is automatically generated.\n' + @@ -337,6 +338,20 @@ module.exports.run = function(options) { }); }; +/* + * Detects the architecture of a device/emulator + * Returns "arm" or "x86". + */ +module.exports.detectArchitecture = function(target) { + return exec('adb -s ' + target + ' shell cat /proc/cpuinfo') + .then(function(output) { + if (/intel/i.exec(output)) { + return 'x86'; + } + return 'arm'; + }); +}; + /* * Gets the path to the apk file, if not such file exists then * the script will error out. (should we error or just return undefined?) diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js index df212876..671f93d0 100644 --- a/bin/templates/cordova/lib/device.js +++ b/bin/templates/cordova/lib/device.js @@ -58,19 +58,18 @@ module.exports.install = function(target) { // default device target = typeof target !== 'undefined' ? target : device_list[0]; - if (device_list.indexOf(target) < 0) + if (device_list.indexOf(target) < 0) { return Q.reject('ERROR: Unable to find target \'' + target + '\'.'); - - var apk_path; - if (typeof process.env.DEPLOY_APK_ARCH == 'undefined') { - apk_path = build.get_apk(); - } else { - apk_path = build.get_apk(null, process.env.DEPLOY_APK_ARCH); } - launchName = appinfo.getActivityName(); - console.log('Installing app on device...'); - var cmd = 'adb -s ' + target + ' install -r "' + apk_path + '"'; - return exec(cmd); + + return build.detectArchitecture(target) + .then(function(arch) { + var apk_path = build.get_apk(null, arch); + launchName = appinfo.getActivityName(); + console.log('Installing app on device...'); + var cmd = 'adb -s ' + target + ' install -r "' + apk_path + '"'; + return exec(cmd); + }); }).then(function(output) { if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output); diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 0b9747de..88b35f7b 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -293,9 +293,12 @@ module.exports.install = function(target) { return Q.reject('Unable to find target \'' + target + '\'. Failed to deploy to emulator.'); } - console.log('Installing app on emulator...'); - var apk_path = build.get_apk(); - return exec('adb -s ' + target + ' install -r "' + apk_path + '"'); + return build.detectArchitecture(target) + .then(function(arch) { + var apk_path = build.get_apk(null, arch); + console.log('Installing app on emulator...'); + return exec('adb -s ' + target + ' install -r "' + apk_path + '"'); + }); }).then(function(output) { if (output.match(/Failure/)) { return Q.reject('Failed to install apk to emulator: ' + output);