Skip to content

Commit

Permalink
Merge pull request apache#417 from DavidStrausz/master
Browse files Browse the repository at this point in the history
CB-13580: (android) fix build for multiple apks (different product flavors)

Note from @benjamn: this commit was cherry-picked from version 7.0.0 onto
version 6.4.0 in Meteor's fork of cordova-android, since the maintainer
has indicated the changes probably will not be back-ported to 6.x:
apache#417 (comment)

cc @menelike @abernix
  • Loading branch information
infil00p authored and benjamn committed Jan 15, 2018
1 parent 7a27ee4 commit 317db7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bin/templates/cordova/lib/builders/GenericBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ GenericBuilder.prototype.extractRealProjectNameFromManifest = function () {
module.exports = GenericBuilder;

function apkSorter (fileA, fileB) {
// De-prioritize arch specific builds
var archSpecificRE = /-x86|-arm/;
if (archSpecificRE.exec(fileA)) {
return 1;
} else if (archSpecificRE.exec(fileB)) {
return -1;
}

// De-prioritize unsigned builds
var unsignedRE = /-unsigned/;
if (unsignedRE.exec(fileA)) {
Expand All @@ -101,15 +109,22 @@ function apkSorter (fileA, fileB) {
return -1;
}

var timeDiff = fs.statSync(fileA).mtime - fs.statSync(fileB).mtime;
var timeDiff = fs.statSync(fileB).mtime - fs.statSync(fileA).mtime;
return timeDiff === 0 ? fileA.length - fileB.length : timeDiff;
}

function findOutputApksHelper (dir, build_type, arch) {
var shellSilent = shell.config.silent;
shell.config.silent = true;

var ret = shell.ls(path.join(dir, build_type, '*.apk')).filter(function (candidate) {
// list directory recursively
var ret = shell.ls('-R', dir).map(function (file) {
// ls does not include base directory
return path.join(dir, file);
}).filter(function (file) {
// find all APKs
return file.match(/\.apk?$/i);
}).filter(function (candidate) {
var apkName = path.basename(candidate);
// Need to choose between release and debug .apk.
if (build_type === 'debug') {
Expand Down
2 changes: 2 additions & 0 deletions bin/templates/project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ android {
buildToolsVersion cdvBuildToolsVersion

if (Boolean.valueOf(cdvBuildMultipleApks)) {
flavorDimensions "default"

productFlavors {
armv7 {
versionCode defaultConfig.versionCode*10 + 2
Expand Down

0 comments on commit 317db7d

Please sign in to comment.