mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-02 12:52:51 +08:00
fix(windows): get gradle path with which command (#1793)
This commit is contained in:
parent
1d82a3b52f
commit
f697ca7dec
@ -17,7 +17,6 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const execa = require('execa');
|
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const { forgivingWhichSync, isWindows, isDarwin } = require('./utils');
|
const { forgivingWhichSync, isWindows, isDarwin } = require('./utils');
|
||||||
@ -104,46 +103,7 @@ function getUserCompileSdkVersion (projectRoot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.get_gradle_wrapper = function () {
|
module.exports.get_gradle_wrapper = function () {
|
||||||
let androidStudioPath;
|
return forgivingWhichSync('gradle');
|
||||||
let i = 0;
|
|
||||||
let foundStudio = false;
|
|
||||||
let program_dir;
|
|
||||||
// OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually!
|
|
||||||
if (module.exports.isWindows()) {
|
|
||||||
// "shell" option enabled for CVE-2024-27980 (Windows) Mitigation
|
|
||||||
// See https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 for more details
|
|
||||||
const result = execa.sync(path.join(__dirname, 'getASPath.bat'), { shell: true });
|
|
||||||
// console.log('result.stdout =' + result.stdout.toString());
|
|
||||||
// console.log('result.stderr =' + result.stderr.toString());
|
|
||||||
|
|
||||||
if (result.stderr.toString().length > 0) {
|
|
||||||
const androidPath = path.join(process.env.ProgramFiles, 'Android') + '/';
|
|
||||||
if (fs.existsSync(androidPath)) {
|
|
||||||
program_dir = fs.readdirSync(androidPath);
|
|
||||||
while (i < program_dir.length && !foundStudio) {
|
|
||||||
if (program_dir[i].startsWith('Android Studio')) {
|
|
||||||
foundStudio = true;
|
|
||||||
androidStudioPath = path.join(process.env.ProgramFiles, 'Android', program_dir[i], 'gradle');
|
|
||||||
} else { ++i; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// console.log('got android studio path from registry');
|
|
||||||
// remove the (os independent) new line char at the end of stdout
|
|
||||||
// add gradle to match the above.
|
|
||||||
androidStudioPath = path.join(result.stdout.toString().split('\r\n')[0], 'gradle');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (androidStudioPath !== null && fs.existsSync(androidStudioPath)) {
|
|
||||||
const dirs = fs.readdirSync(androidStudioPath);
|
|
||||||
if (dirs[0].split('-')[0] === 'gradle') {
|
|
||||||
return path.join(androidStudioPath, dirs[0], 'bin', 'gradle');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// OK, let's try to check for Gradle!
|
|
||||||
return forgivingWhichSync('gradle');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a promise. Called only by build and clean commands.
|
// Returns a promise. Called only by build and clean commands.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user