diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2020-06-26 00:33:43 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2020-06-26 09:52:17 +0000 |
commit | b410def067082b88fb2c65dc66a6fcb69584ad90 (patch) | |
tree | d3e87fb1d281a2ccc8efab4b0ff66fbd447a31fb /src/plugins/android/androidsettingswidget.cpp | |
parent | ef9f57b5cb7a99fe5dcca20037fd8e76ad850784 (diff) |
Android: fix some issues with jdk path detection
* There were two functions to detect jdk path, unified them.
* First try to find jdk 1.8, if not found, look for newer versions.
SDK Tools version 26.x needs jdk 1.8 however, the new cmdline-tools
can work with the newest jdk, so the UI will warn the user if the
selected jdk cannot run sdkmanager potentially because of the jdk
version.
Change-Id: Iee2c378598c26e8a9a8245262110ac20322a2d2b
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/plugins/android/androidsettingswidget.cpp')
-rw-r--r-- | src/plugins/android/androidsettingswidget.cpp | 74 |
1 files changed, 3 insertions, 71 deletions
diff --git a/src/plugins/android/androidsettingswidget.cpp b/src/plugins/android/androidsettingswidget.cpp index 30442612210..951b40a2227 100644 --- a/src/plugins/android/androidsettingswidget.cpp +++ b/src/plugins/android/androidsettingswidget.cpp @@ -103,7 +103,6 @@ private: void apply() final { AndroidConfigurations::setConfig(m_androidConfig); } void validateJdk(); - FilePath findJdkInCommonPaths() const; void validateNdk(); void updateNdkList(); void onSdkPathChanged(); @@ -155,8 +154,7 @@ private: enum JavaValidation { JavaPathExistsRow, - JavaJdkValidRow, - JavaJdkValidVersionRow + JavaJdkValidRow }; enum AndroidValidation { @@ -395,7 +393,6 @@ AndroidSettingsWidget::AndroidSettingsWidget() QMap<int, QString> javaValidationPoints; javaValidationPoints[JavaPathExistsRow] = tr("JDK path exists."); javaValidationPoints[JavaJdkValidRow] = tr("JDK path is a valid JDK root folder."); - javaValidationPoints[JavaJdkValidVersionRow] = tr("Working JDK version (8) detected."); m_javaSummary = new SummaryWidget(javaValidationPoints, tr("Java Settings are OK."), tr("Java settings have errors."), m_ui.javaDetailsWidget); @@ -405,7 +402,7 @@ AndroidSettingsWidget::AndroidSettingsWidget() androidValidationPoints[SdkToolsInstalledRow] = tr("SDK tools installed."); androidValidationPoints[PlatformToolsInstalledRow] = tr("Platform tools installed."); androidValidationPoints[SdkManagerSuccessfulRow] = tr( - "SDK manager runs (requires exactly Java 1.8)."); + "SDK manager runs (SDK Tools versions <= 26.x require exactly Java 1.8)."); androidValidationPoints[AllEssentialsInstalledRow] = tr( "All essential packages installed for all installed Qt versions."); androidValidationPoints[BuildToolsInstalledRow] = tr("Build tools installed."); @@ -433,7 +430,7 @@ AndroidSettingsWidget::AndroidSettingsWidget() this, &AndroidSettingsWidget::validateJdk); FilePath currentJdkPath = m_androidConfig.openJDKLocation(); if (currentJdkPath.isEmpty()) - currentJdkPath = findJdkInCommonPaths(); + currentJdkPath = AndroidConfig::getJdkPath(); m_ui.OpenJDKLocationPathChooser->setFilePath(currentJdkPath); m_ui.OpenJDKLocationPathChooser->setPromptDialogTitle(tr("Select JDK Path")); @@ -584,24 +581,6 @@ void AndroidSettingsWidget::validateJdk() const FilePath bin = m_androidConfig.openJDKLocation().pathAppended("bin/javac" QTC_HOST_EXE_SUFFIX); m_javaSummary->setPointValid(JavaJdkValidRow, jdkPathExists && bin.exists()); - bool jdkVersionCorrect = false; - SynchronousProcess javacProcess; - const int timeoutS = 5; - javacProcess.setTimeoutS(timeoutS); - const CommandLine cmd(bin, {"-version"}); - SynchronousProcessResponse response = javacProcess.runBlocking(cmd); - if (response.result == SynchronousProcessResponse::Finished) { - QString output = response.stdOut(); // JDK 14 uses stdOut for this output. - if (output.isEmpty()) - output = response.stdErr(); // JDK 8 uses stdErr for this output. - if (output.startsWith("javac ")) { - const QVersionNumber javacVersion = QVersionNumber::fromString(output.mid(6)); - if (QVersionNumber(1, 8).isPrefixOf(javacVersion)) - jdkVersionCorrect = true; - } - } - m_javaSummary->setPointValid(JavaJdkValidVersionRow, jdkVersionCorrect); - updateUI(); } @@ -620,53 +599,6 @@ void AndroidSettingsWidget::validateOpenSsl() updateUI(); } -FilePath AndroidSettingsWidget::findJdkInCommonPaths() const -{ - QString jdkFromEnvVar = QString::fromLocal8Bit(getenv("JAVA_HOME")); - if (!jdkFromEnvVar.isEmpty()) - return FilePath::fromUserInput(jdkFromEnvVar); - - if (HostOsInfo::isWindowsHost()) { - QString jdkRegisteryPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\JDK\\"; - QSettings jdkSettings(jdkRegisteryPath, QSettings::NativeFormat); - - QStringList jdkVersions = jdkSettings.childGroups(); - FilePath jdkHome; - - for (const QString &version : jdkVersions) { - jdkSettings.beginGroup(version); - jdkHome = FilePath::fromUserInput(jdkSettings.value("JavaHome").toString()); - jdkSettings.endGroup(); - if (version.startsWith("1.8")) - return jdkHome; - } - - return jdkHome; - } - - QProcess findJdkPathProc; - - QString cmd; - QStringList args; - - if (HostOsInfo::isMacHost()) { - cmd = "sh"; - args << "-c" << "/usr/libexec/java_home"; - } else { - cmd = "sh"; - args << "-c" << "readlink -f $(which java)"; - } - - findJdkPathProc.start(cmd, args); - findJdkPathProc.waitForFinished(); - QByteArray jdkPath = findJdkPathProc.readAllStandardOutput().trimmed(); - - if (HostOsInfo::isMacHost()) - return FilePath::fromUtf8(jdkPath); - else - return FilePath::fromUtf8(jdkPath.replace("jre/bin/java", "")); -} - void AndroidSettingsWidget::validateNdk() { const QListWidgetItem *currentItem = m_ui.ndkListWidget->currentItem(); |