CB-11198 Skip android target sdk check. This closes #303.

This commit is contained in:
Nikhil Khandelwal 2016-05-03 16:02:02 -07:00
parent d351e316bf
commit 5d21fb26e6
3 changed files with 45 additions and 19 deletions

View File

@ -143,18 +143,16 @@ module.exports.check_java = function() {
} }
}).then(function() { }).then(function() {
var msg = var msg =
'Failed to run "java -version", make sure that you have a JDK installed.\n' + 'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n'; 'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
if (process.env['JAVA_HOME']) { if (process.env['JAVA_HOME']) {
msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n'; msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
} }
return tryCommand('java -version', msg)
.then(function() {
// We use tryCommand with catchStderr = true, because // We use tryCommand with catchStderr = true, because
// javac writes version info to stderr instead of stdout // javac writes version info to stderr instead of stdout
return tryCommand('javac -version', msg, true); return tryCommand('javac -version', msg, true)
}).then(function (output) { .then(function (output) {
var match = /javac ((?:\d+\.)+(?:\d+))/i.exec(output)[1]; var match = /javac ((?:\d+\.)+(?:\d+))/i.exec(output);
return match && match[1]; return match && match[1];
}); });
}); });
@ -238,13 +236,13 @@ module.exports.getAbsoluteAndroidCmd = function () {
return cmd.replace(/(\s)/g, '\\$1'); return cmd.replace(/(\s)/g, '\\$1');
}; };
module.exports.check_android_target = function(valid_target) { module.exports.check_android_target = function(originalError) {
// valid_target can look like: // valid_target can look like:
// android-19 // android-19
// 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
if (!valid_target) valid_target = module.exports.get_target(); var valid_target = module.exports.get_target();
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.'; 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.';
return tryCommand('android list targets --compact', msg) return tryCommand('android list targets --compact', msg)
.then(function(output) { .then(function(output) {
@ -254,18 +252,22 @@ module.exports.check_android_target = function(valid_target) {
} }
var androidCmd = module.exports.getAbsoluteAndroidCmd(); var androidCmd = module.exports.getAbsoluteAndroidCmd();
throw new CordovaError('Please install Android target: "' + valid_target + '".\n\n' + var msg = 'Please install Android target: "' + valid_target + '".\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 ' + valid_target + '\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) {
msg = originalError + '\n' + msg;
}
throw new CordovaError(msg);
}); });
}; };
// Returns a promise. // Returns a promise.
module.exports.run = function() { module.exports.run = function() {
return Q.all([this.check_java(), this.check_android().then(this.check_android_target)]) return Q.all([this.check_java(), this.check_android()])
.then(function() { .then(function() {
console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']); console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
console.log('JAVA_HOME=' + process.env['JAVA_HOME']); console.log('JAVA_HOME=' + process.env['JAVA_HOME']);

View File

@ -107,7 +107,22 @@ AntBuilder.prototype.build = function(opts) {
var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts); var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts);
return check_reqs.check_ant() return check_reqs.check_ant()
.then(function() { .then(function() {
return spawn('ant', args, {stdio: 'inherit'}); return spawn('ant', args, {stdio: 'pipe'});
}).progress(function (stdio){
if (stdio.stderr) {
process.stderr.write(stdio.stderr);
} else {
process.stdout.write(stdio.stdout);
}
}).catch(function (error) {
if (error.toString().indexOf('Unable to resolve project target') >= 0) {
return check_reqs.check_android_target(error).then(function() {
// If due to some odd reason - check_android_target succeeds
// we should still fail here.
return Q.reject(error);
});
}
return Q.reject(error);
}); });
}; };

View File

@ -203,6 +203,15 @@ GradleBuilder.prototype.build = function(opts) {
} else { } else {
process.stdout.write(stdio.stdout); process.stdout.write(stdio.stdout);
} }
}).catch(function (error) {
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
return check_reqs.check_android_target(error).then(function() {
// If due to some odd reason - check_android_target succeeds
// we should still fail here.
return Q.reject(error);
});
}
return Q.reject(error);
}); });
}; };