mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
fix: cordova requirements command and SDK lookup based on tools (#1877)
* fix: cordova requirements command and SDK lookup based on tools * Update spec/unit/AndroidCommandLineTools.spec.js Co-authored-by: エリス <erisu@users.noreply.github.com> * Update lib/env/AndroidCommandLineTools.js Co-authored-by: エリス <erisu@users.noreply.github.com> * Update lib/env/AndroidCommandLineTools.js Co-authored-by: エリス <erisu@users.noreply.github.com> * Update lib/env/AndroidCommandLineTools.js --------- Co-authored-by: エリス <erisu@users.noreply.github.com>
This commit is contained in:
+11
-7
@@ -24,6 +24,7 @@ const java = require('./env/java');
|
||||
const { CordovaError, ConfigParser, events } = require('cordova-common');
|
||||
const android_sdk = require('./android_sdk');
|
||||
const { SDK_VERSION } = require('./gradle-config-defaults');
|
||||
const AndroidCommandLineTools = require('./env/AndroidCommandLineTools');
|
||||
|
||||
// Re-exporting these for backwards compatibility and for unit testing.
|
||||
// TODO: Remove uses and use the ./utils module directly.
|
||||
@@ -216,14 +217,14 @@ module.exports.check_android = function () {
|
||||
}
|
||||
}
|
||||
if (avdmanagerInPath) {
|
||||
parentDir = path.dirname(avdmanagerInPath);
|
||||
grandParentDir = path.dirname(parentDir);
|
||||
if (path.basename(parentDir) === 'bin' && path.basename(grandParentDir) === 'tools') {
|
||||
maybeSetAndroidHome(path.dirname(grandParentDir));
|
||||
let sdkPath = null;
|
||||
if (/cmdline-tools/.test(avdmanagerInPath)) {
|
||||
sdkPath = path.resolve(avdmanagerInPath, '../../../..');
|
||||
maybeSetAndroidHome(sdkPath);
|
||||
} else {
|
||||
throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting it manually.\n' +
|
||||
'Detected \'avdmanager\' command at ' + parentDir + ' but no \'tools' + path.sep + 'bin\' directory found near.\n' +
|
||||
'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools' + path.sep + 'bin directory.');
|
||||
'Detected \'avdmanager\' command at ' + parentDir + ' but does not appear to be within an Android SDK installation.\n' +
|
||||
'Try reinstall Android SDK or update your PATH to include valid path to SDK');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +241,10 @@ module.exports.check_android = function () {
|
||||
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_HOME, 'platform-tools');
|
||||
}
|
||||
if (hasAndroidHome && !avdmanagerInPath) {
|
||||
process.env.PATH += path.delimiter + path.join(process.env.ANDROID_HOME, 'tools', 'bin');
|
||||
const cmdLineToolsBin = AndroidCommandLineTools.getBinPath();
|
||||
if (cmdLineToolsBin) {
|
||||
process.env.PATH += path.delimiter + cmdLineToolsBin;
|
||||
}
|
||||
}
|
||||
return hasAndroidHome;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user