From 5cc14b803160dff4ebc89991b3eea5d1199c6cca Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 20 Jun 2017 16:54:32 -0700 Subject: [PATCH] CB-12605 In Windows get Android studio path from the registry This closes #387 --- bin/templates/cordova/lib/check_reqs.js | 29 ++++++++++++++++++------- bin/templates/cordova/lib/getASPath.bat | 3 +++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 bin/templates/cordova/lib/getASPath.bat diff --git a/bin/templates/cordova/lib/check_reqs.js b/bin/templates/cordova/lib/check_reqs.js index 1fd397ad..d87b5473 100644 --- a/bin/templates/cordova/lib/check_reqs.js +++ b/bin/templates/cordova/lib/check_reqs.js @@ -108,16 +108,29 @@ module.exports.get_gradle_wrapper = function() { } else { ++i; } } } else if (module.exports.isWindows()) { - var 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; } + + var result = child_process.spawnSync(path.join(__dirname,'getASPath.bat')); + //console.log('result.stdout =' + result.stdout.toString()); + //console.log('result.stderr =' + result.stderr.toString()); + + if(result.stderr.toString().length > 0) { + var 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)) { diff --git a/bin/templates/cordova/lib/getASPath.bat b/bin/templates/cordova/lib/getASPath.bat new file mode 100644 index 00000000..14dad439 --- /dev/null +++ b/bin/templates/cordova/lib/getASPath.bat @@ -0,0 +1,3 @@ +@ECHO OFF +for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Android Studio" /v Path') do set "ASPath=%%~b" +ECHO %ASPath% \ No newline at end of file