CB-7512 Use aligned apk rather than unaligned apk when sorting
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
index e63e342..3224758 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -38,8 +38,11 @@
p = path.join(directory, p);
return { p: p, t: fs.statSync(p).mtime };
}).sort(function(a,b) {
- return a.t > b.t ? -1 :
- a.t < b.t ? 1 : 0;
+ var timeDiff = b.t - a.t;
+ if (timeDiff === 0) {
+ return a.p.length - b.p.length;
+ }
+ return timeDiff;
}).map(function(p) { return p.p; });
return candidates;
} else {
@@ -151,8 +154,9 @@
console.error('ERROR : No .apk found in ' + binDir + ' directory');
process.exit(2);
}
- console.log('Using apk: ' + candidates[0]);
- return [candidates[0]];
+ var ret = candidates[0];
+ console.log('Using apk: ' + ret);
+ return [ret];
}
},
gradle: {
@@ -245,14 +249,16 @@
var candidates = find_files(binDir, function(candidate) {
// Need to choose between release and debug .apk.
if (build_type === 'debug') {
- return (path.extname(candidate) == '.apk' && candidate.indexOf('-debug-') >= 0);
+ return (path.extname(candidate) == '.apk' && candidate.indexOf('-debug') >= 0);
}
if (build_type === 'release') {
- return (path.extname(candidate) == '.apk' && candidate.indexOf('-release-') >= 0);
+ return (path.extname(candidate) == '.apk' && candidate.indexOf('-release') >= 0);
}
return path.extname(candidate) == '.apk';
});
- return candidates;
+ var ret = candidates[0];
+ console.log('Using apk: ' + ret);
+ return [ret];
}
},