mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-02 21:03:02 +08:00
CB-12546: use android_sdk list_targets instead of rewriting the same thing again.
This commit is contained in:
parent
ebd4a02d2c
commit
f7687a2567
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
var android_sdk = require('./templates/cordova/lib/android_sdk');
|
var android_sdk = require('./templates/cordova/lib/android_sdk');
|
||||||
|
|
||||||
android_sdk.print_newest_available_sdk_target.done(null, function(err) {
|
android_sdk.print_newest_available_sdk_target().done(null, function(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
6
bin/templates/cordova/lib/android_sdk.js
vendored
6
bin/templates/cordova/lib/android_sdk.js
vendored
@ -60,10 +60,10 @@ module.exports.list_targets = function() {
|
|||||||
// lets see if `sdkmanager` is available and we can figure it out
|
// lets see if `sdkmanager` is available and we can figure it out
|
||||||
var avail_regex = /android command is no longer available/;
|
var avail_regex = /android command is no longer available/;
|
||||||
if (err.code && (err.stdout.match(avail_regex) || err.stderr.match(avail_regex))) {
|
if (err.code && (err.stdout.match(avail_regex) || err.stderr.match(avail_regex))) {
|
||||||
return superspawn.spawn('sdkmanager', ['--list'], {capture: ['stdout', 'stderr']})
|
return superspawn.spawn('sdkmanager', ['--list'])
|
||||||
.then(function(result) {
|
.then(function(stdout) {
|
||||||
var parsing_installed_packages = false;
|
var parsing_installed_packages = false;
|
||||||
var lines = result.stdout.split('\n');
|
var lines = stdout.split('\n');
|
||||||
var targets = [];
|
var targets = [];
|
||||||
for (var i = 0, l = lines.length; i < l; i++) {
|
for (var i = 0, l = lines.length; i < l; i++) {
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
|
34
bin/templates/cordova/lib/check_reqs.js
vendored
34
bin/templates/cordova/lib/check_reqs.js
vendored
@ -31,7 +31,7 @@ var shelljs = require('shelljs'),
|
|||||||
PROJECT_ROOT = path.join(__dirname, '..', '..');
|
PROJECT_ROOT = path.join(__dirname, '..', '..');
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
var superspawn = require('cordova-common').superspawn;
|
var superspawn = require('cordova-common').superspawn;
|
||||||
|
var android_sdk = require('./android_sdk');
|
||||||
|
|
||||||
function forgivingWhichSync(cmd) {
|
function forgivingWhichSync(cmd) {
|
||||||
try {
|
try {
|
||||||
@ -89,7 +89,7 @@ module.exports.check_ant = function() {
|
|||||||
// Parse Ant version from command output
|
// Parse Ant version from command output
|
||||||
return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
|
return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
throw new CordovaError("Failed to run `ant -version`. Make sure you have `ant` on your $PATH.");
|
throw new CordovaError('Failed to run `ant -version`. Make sure you have `ant` on your $PATH.');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -299,11 +299,11 @@ module.exports.check_android = function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: is this actually needed?
|
||||||
module.exports.getAbsoluteAndroidCmd = function () {
|
module.exports.getAbsoluteAndroidCmd = function () {
|
||||||
var cmd = forgivingWhichSync('android');
|
var cmd = forgivingWhichSync('android');
|
||||||
// TODO: this probably needs to be `sdkmanager`, no?
|
|
||||||
if (cmd.length === 0) {
|
if (cmd.length === 0) {
|
||||||
cmd = forgivingWhichSync('avdmanager');
|
cmd = forgivingWhichSync('sdkmanager');
|
||||||
}
|
}
|
||||||
if (module.exports.isWindows()) {
|
if (module.exports.isWindows()) {
|
||||||
return '"' + cmd + '"';
|
return '"' + cmd + '"';
|
||||||
@ -317,37 +317,24 @@ module.exports.check_android_target = function(originalError) {
|
|||||||
// android-L
|
// android-L
|
||||||
// Google Inc.:Google APIs:20
|
// Google Inc.:Google APIs:20
|
||||||
// Google Inc.:Glass Development Kit Preview:20
|
// Google Inc.:Glass Development Kit Preview:20
|
||||||
var valid_target = module.exports.get_target();
|
var desired_api_level = parseInt(module.exports.get_target().replace(/android-/, ''));
|
||||||
var msg = 'Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.';
|
|
||||||
// Changing "targets" to "target" is stupid and makes more code. Thanks Google!
|
// Changing "targets" to "target" is stupid and makes more code. Thanks Google!
|
||||||
var cmd = 'android';
|
return android_sdk.list_targets()
|
||||||
// TODO: the following conditional needs fixing, probably should leverage `sdkmanager`
|
.then(function(targets) {
|
||||||
// oh and tests
|
if (targets.indexOf(desired_api_level) >= 0) {
|
||||||
if (forgivingWhichSync('avdmanager').length > 0)
|
|
||||||
cmd = 'avdmanager';
|
|
||||||
return superspawn.spawn(cmd, ['list', 'targets', '--compact'])
|
|
||||||
.then(function(stdout) {
|
|
||||||
var targets = output.split('\n');
|
|
||||||
if (targets.indexOf(valid_target) >= 0) {
|
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
var androidCmd = module.exports.getAbsoluteAndroidCmd();
|
var androidCmd = module.exports.getAbsoluteAndroidCmd();
|
||||||
var msg = 'Please install Android target: "' + valid_target + '".\n\n' +
|
var msg = 'Please install Android target / API level: "' + desired_api_level + '".\n\n' +
|
||||||
'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
|
'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
|
||||||
'You will require:\n' +
|
'You will require:\n' +
|
||||||
'1. "SDK Platform" for ' + valid_target + '\n' +
|
'1. "SDK Platform" for API level ' + desired_api_level + '\n' +
|
||||||
'2. "Android SDK Platform-tools (latest)\n' +
|
'2. "Android SDK Platform-tools (latest)\n' +
|
||||||
'3. "Android SDK Build-tools" (latest)';
|
'3. "Android SDK Build-tools" (latest)';
|
||||||
if (originalError) {
|
if (originalError) {
|
||||||
msg = originalError + '\n' + msg;
|
msg = originalError + '\n' + msg;
|
||||||
}
|
}
|
||||||
throw new CordovaError(msg);
|
throw new CordovaError(msg);
|
||||||
}).catch(function(err) {
|
|
||||||
throw new CordovaError(msg);
|
|
||||||
});
|
|
||||||
return tryCommand(cmd, msg)
|
|
||||||
.then(function(output) {
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -362,7 +349,6 @@ module.exports.run = function() {
|
|||||||
throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
|
throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!values[1]) {
|
if (!values[1]) {
|
||||||
throw new CordovaError('Requirements check failed for Android SDK');
|
throw new CordovaError('Requirements check failed for Android SDK');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user