Android: Fix that Android Studio's jdk does not get detected (Windows)

If all jdk detection methods on Windows remain unsuccessful, let's try
to find an installation of Android Studio via the registry and use the
"jre" folder (which is actually a jdk) from there.

Change-Id: Ie4d7a4c5cc56f0b4675c86e436c3f1007994633c
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Alessandro Portale
2020-07-20 15:07:48 +02:00
parent 05cdce2fc9
commit 26f3157262

View File

@@ -1522,6 +1522,21 @@ AndroidConfigurations::AndroidConfigurations()
AndroidConfigurations::~AndroidConfigurations() = default;
static Utils::FilePath androidStudioPath()
{
if (Utils::HostOsInfo::isWindowsHost()) {
const QLatin1String registryKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Android Studio");
const QLatin1String valueName("Path");
#if defined(Q_OS_WIN)
const QSettings settings64(registryKey, QSettings::Registry64Format);
const QSettings settings32(registryKey, QSettings::Registry32Format);
return Utils::FilePath::fromUserInput(
settings64.value(valueName, settings32.value(valueName).toString()).toString());
#endif
}
return {}; // TODO non-Windows
}
FilePath AndroidConfig::getJdkPath()
{
FilePath jdkHome;
@@ -1561,6 +1576,16 @@ FilePath AndroidConfig::getJdkPath()
break;
}
}
// Nothing found yet? Let's try finding Android Studio's jdk
if (jdkHome.isEmpty()) {
const Utils::FilePath androidStudioSdkPath = androidStudioPath();
if (!androidStudioSdkPath.isEmpty()) {
const Utils::FilePath androidStudioSdkJrePath = androidStudioSdkPath / "jre";
if (androidStudioSdkJrePath.exists())
jdkHome = androidStudioSdkJrePath;
}
}
} else {
QStringList args;
if (HostOsInfo::isMacHost())