Skip to content

Commit

Permalink
refactoring for more consistent behaviour across platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Apr 13, 2020
1 parent e9f6c5e commit be7cfa8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,22 @@ module.exports.check_java = function () {
// Returns a promise.
module.exports.check_android = function () {
return Promise.resolve().then(function () {
var androidCmdPath = forgivingWhichSync('android');
var adbInPath = forgivingWhichSync('adb');
var avdmanagerInPath = forgivingWhichSync('avdmanager');
var hasAndroidHome = !!process.env['ANDROID_SDK_ROOT'] && fs.existsSync(process.env['ANDROID_SDK_ROOT']);
function maybeSetAndroidHome (value) {
if (!hasAndroidHome && fs.existsSync(value)) {
hasAndroidHome = true;
process.env['ANDROID_SDK_ROOT'] = value;
}
}

var androidCmdPath = forgivingWhichSync('android');
var adbInPath = forgivingWhichSync('adb');
var avdmanagerInPath = forgivingWhichSync('avdmanager');
var hasAndroidHome = false;

if (process.env['ANDROID_SDK_ROOT']) {
maybeSetAndroidHome(path.resolve(process.env['ANDROID_SDK_ROOT']));
}

// First ensure ANDROID_HOME is set
// If we have no hints (nothing in PATH), try a few default locations
if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath) {
Expand Down Expand Up @@ -300,6 +306,7 @@ module.exports.check_android = function () {
maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk'));
}
}

if (!hasAndroidHome) {
// If we dont have ANDROID_SDK_ROOT, but we do have some tools on the PATH, try to infer from the tooling PATH.
var parentDir, grandParentDir;
Expand Down

0 comments on commit be7cfa8

Please sign in to comment.