forked from github/cordova-android
CB-7980 Add --minSdkVersion and --versionCode flags to cordova/build command
These are also exposed via environment variables: ANDROID_VERSION_CODE, ANDROID_MIN_SDK_VERSION This also fixes build.gradle modifying the value set by ANDROID_VERSION_CODE when multi-apk is enabled (override should never be modified)
This commit is contained in:
parent
9224ab1592
commit
7cfb33d0ef
34
bin/templates/cordova/lib/build.js
vendored
34
bin/templates/cordova/lib/build.js
vendored
@ -306,15 +306,21 @@ function parseOpts(options, resolvedTarget) {
|
|||||||
// Iterate through command line options
|
// Iterate through command line options
|
||||||
for (var i=0; options && (i < options.length); ++i) {
|
for (var i=0; options && (i < options.length); ++i) {
|
||||||
if (/^--/.exec(options[i])) {
|
if (/^--/.exec(options[i])) {
|
||||||
var option = options[i].substring(2);
|
var keyValue = options[i].substring(2).split('=');
|
||||||
switch(option) {
|
var flagName = keyValue[0];
|
||||||
|
var flagValue = keyValue[1];
|
||||||
|
if ((flagName == 'versionCode' || flagName == 'minSdkVersion') && !flagValue) {
|
||||||
|
flagValue = options[i + 1];
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
switch(flagName) {
|
||||||
case 'debug':
|
case 'debug':
|
||||||
case 'release':
|
case 'release':
|
||||||
ret.buildType = option;
|
ret.buildType = flagName;
|
||||||
break;
|
break;
|
||||||
case 'ant':
|
case 'ant':
|
||||||
case 'gradle':
|
case 'gradle':
|
||||||
ret.buildMethod = option;
|
ret.buildMethod = flagName;
|
||||||
break;
|
break;
|
||||||
case 'device':
|
case 'device':
|
||||||
case 'emulator':
|
case 'emulator':
|
||||||
@ -324,8 +330,14 @@ function parseOpts(options, resolvedTarget) {
|
|||||||
case 'nobuild' :
|
case 'nobuild' :
|
||||||
ret.buildMethod = 'none';
|
ret.buildMethod = 'none';
|
||||||
break;
|
break;
|
||||||
|
case 'versionCode':
|
||||||
|
process.env['ANDROID_VERSION_CODE'] = flagValue;
|
||||||
|
break;
|
||||||
|
case 'minSdkVersion':
|
||||||
|
process.env['ANDROID_MIN_SDK_VERSION'] = flagValue;
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
console.warn('Build option \'' + options[i] + '\' not recognized (ignoring).');
|
console.warn('Build option --\'' + flagName + '\' not recognized (ignoring).');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('Build option \'' + options[i] + '\' not recognized (ignoring).');
|
console.warn('Build option \'' + options[i] + '\' not recognized (ignoring).');
|
||||||
@ -445,12 +457,14 @@ module.exports.findBestApkForArchitecture = function(buildResults, arch) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.help = function() {
|
module.exports.help = function() {
|
||||||
console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'build')) + ' [build_type]');
|
console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'build')) + ' [flags]');
|
||||||
console.log('Build Types : ');
|
console.log('Flags:');
|
||||||
console.log(' \'--debug\': Default build, will build project in debug mode');
|
console.log(' \'--debug\': will build project in debug mode (default)');
|
||||||
console.log(' \'--release\': will build project for release');
|
console.log(' \'--release\': will build project for release');
|
||||||
console.log(' \'--ant\': Default build, will build project with ant');
|
console.log(' \'--ant\': will build project with ant (default)');
|
||||||
console.log(' \'--gradle\': will build project with gradle');
|
console.log(' \'--gradle\': will build project with gradle');
|
||||||
console.log(' \'--nobuild\': will skip build process (can be used with run command)');
|
console.log(' \'--nobuild\': will skip build process (useful when using run command)');
|
||||||
|
console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs. Requires --gradle.');
|
||||||
|
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs. Requires --gradle.');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
};
|
||||||
|
@ -74,6 +74,9 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
versionCode Integer.parseInt(System.env.ANDROID_VERSION_CODE ?: ("" + getIntFromManifest("versionCode") + "0"))
|
versionCode Integer.parseInt(System.env.ANDROID_VERSION_CODE ?: ("" + getIntFromManifest("versionCode") + "0"))
|
||||||
|
if (System.env.ANDROID_MIN_SDK_VERSION) {
|
||||||
|
minSdkVersion Integer.parseInt(System.env.ANDROID_MIN_SDK_VERSION)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileSdkVersion cordova.cordovaSdkVersion
|
compileSdkVersion cordova.cordovaSdkVersion
|
||||||
@ -82,13 +85,13 @@ android {
|
|||||||
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
|
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
|
||||||
productFlavors {
|
productFlavors {
|
||||||
armv7 {
|
armv7 {
|
||||||
versionCode defaultConfig.versionCode + 2
|
versionCode System.env.ANDROID_VERSION_CODE ?: defaultConfig.versionCode + 2
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "armeabi-v7a", ""
|
abiFilters "armeabi-v7a", ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x86 {
|
x86 {
|
||||||
versionCode defaultConfig.versionCode + 4
|
versionCode System.env.ANDROID_VERSION_CODE ?: defaultConfig.versionCode + 4
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "x86", ""
|
abiFilters "x86", ""
|
||||||
}
|
}
|
||||||
@ -99,8 +102,16 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (getIntFromManifest("minSdkVersion") >= 20) {
|
} else if (!System.env.ANDROID_VERSION_CODE) {
|
||||||
|
def minSdkVersion = Integer.parseInt(System.env.ANDROID_MIN_SDK_VERSION ?: "" + getIntFromManifest("minSdkVersion"))
|
||||||
|
// Vary versionCode by the two most common API levels:
|
||||||
|
// 14 is ICS, which is the lowest API level for many apps.
|
||||||
|
// 20 is Lollipop, which is the lowest API level for the updatable system webview.
|
||||||
|
if (minSdkVersion >= 20) {
|
||||||
defaultConfig.versionCode += 9
|
defaultConfig.versionCode += 9
|
||||||
|
} else if (minSdkVersion >= 14) {
|
||||||
|
defaultConfig.versionCode += 8
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
Loading…
Reference in New Issue
Block a user