From 26f31572620ea38888fbaafd23cafa403c1cf01a Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 20 Jul 2020 15:07:48 +0200 Subject: [PATCH] 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 --- src/plugins/android/androidconfigurations.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index cd120b54360..f92fc851db2 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -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())