From bc9e895e2537f212756eb8e18559fac2cb02c536 Mon Sep 17 00:00:00 2001 From: daserge Date: Wed, 16 Mar 2016 16:54:06 +0300 Subject: [PATCH] CB-10600 'cordova run android --release' does not use signed and zip-aligned version of APK De-prioritize unsigned builds Adds an actionable hint for INSTALL_PARSE_FAILED_NO_CERTIFICATES error Removes filtering by architecture when not specified --- bin/templates/cordova/lib/Adb.js | 8 +++++++- bin/templates/cordova/lib/builders/GenericBuilder.js | 11 ++++++++++- bin/templates/cordova/lib/emulator.js | 10 ++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bin/templates/cordova/lib/Adb.js b/bin/templates/cordova/lib/Adb.js index 98cd990c..ec3f3152 100644 --- a/bin/templates/cordova/lib/Adb.js +++ b/bin/templates/cordova/lib/Adb.js @@ -63,8 +63,14 @@ Adb.install = function (target, packagePath, opts) { .then(function(output) { // 'adb install' seems to always returns no error, even if installation fails // so we catching output to detect installation failure - if (output.match(/Failure/)) + if (output.match(/Failure/)) { + if (output.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) { + output += '\n\n' + 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' + + ' or sign and deploy the unsigned apk manually using Android tools.'; + } + return Q.reject(new CordovaError('Failed to install apk to device: ' + output)); + } }); }; diff --git a/bin/templates/cordova/lib/builders/GenericBuilder.js b/bin/templates/cordova/lib/builders/GenericBuilder.js index 6363b29b..362da431 100644 --- a/bin/templates/cordova/lib/builders/GenericBuilder.js +++ b/bin/templates/cordova/lib/builders/GenericBuilder.js @@ -93,6 +93,14 @@ GenericBuilder.prototype.extractRealProjectNameFromManifest = function () { module.exports = GenericBuilder; function apkSorter(fileA, fileB) { + // De-prioritize unsigned builds + var unsignedRE = /-unsigned/; + if (unsignedRE.exec(fileA)) { + return 1; + } else if (unsignedRE.exec(fileB)) { + return -1; + } + var timeDiff = fs.statSync(fileA).mtime - fs.statSync(fileB).mtime; return timeDiff === 0 ? fileA.length - fileB.length : timeDiff; } @@ -128,7 +136,8 @@ function findOutputApksHelper(dir, build_type, arch) { return !!/-x86|-arm/.exec(path.basename(p)) == archSpecific; /*jshint +W018 */ }); - if (archSpecific && ret.length > 1) { + + if (archSpecific && ret.length > 1 && arch) { ret = ret.filter(function(p) { return path.basename(p).indexOf('-' + arch) != -1; }); diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 1a07236f..28c93f54 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -368,8 +368,14 @@ module.exports.install = function(givenTarget, buildResults) { if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr)); // adb does not return an error code even if installation fails. Instead it puts a specific // message to stdout, so we have to use RegExp matching to detect installation failure. - else if (/Failure/.test(stdout)) reject(new CordovaError('Failed to install apk to emulator: ' + stdout)); - else resolve(stdout); + else if (/Failure/.test(stdout)) { + if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) { + stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' + + ' or sign and deploy the unsigned apk manually using Android tools.'; + } + + reject(new CordovaError('Failed to install apk to emulator: ' + stdout)); + } else resolve(stdout); }); }); }