From 684f5da06642a5eb440746c79b010f8f77670ad6 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 30 Nov 2021 13:21:14 +0100 Subject: [PATCH] Android: Try harder to find the right qmake project file ... for adding the OpenSSL libs to. For the typical Android case of a single application product, this will do the right thing, and otherwise won't do anything worse than now. Fixes: QTCREATORBUG-24255 Change-Id: I577f3cbd3fda086b8a7c7c5614d0ca79ff9d46f7 Reviewed-by: Alessandro Portale --- src/plugins/android/androidbuildapkstep.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp index f42c5524acf..a4dc00a20a4 100644 --- a/src/plugins/android/androidbuildapkstep.cpp +++ b/src/plugins/android/androidbuildapkstep.cpp @@ -139,6 +139,7 @@ private: void signPackageCheckBoxToggled(bool checked); void onOpenSslCheckBoxChanged(); bool isOpenSslLibsIncluded(); + FilePath appProjectFilePath() const; QString openSslIncludeFileContent(const FilePath &projectPath); QWidget *createApplicationGroup(); @@ -420,7 +421,7 @@ void AndroidBuildApkWidget::signPackageCheckBoxToggled(bool checked) void AndroidBuildApkWidget::onOpenSslCheckBoxChanged() { - Utils::FilePath projectPath = m_step->buildConfiguration()->buildSystem()->projectFilePath(); + Utils::FilePath projectPath = appProjectFilePath(); QFile projectFile(projectPath.toString()); if (!projectFile.open(QIODevice::ReadWrite | QIODevice::Text)) { qWarning() << "Cannot open project file to add OpenSSL extra libs: " << projectPath; @@ -442,9 +443,21 @@ void AndroidBuildApkWidget::onOpenSslCheckBoxChanged() projectFile.close(); } +FilePath AndroidBuildApkWidget::appProjectFilePath() const +{ + const FilePath topLevelFile = m_step->buildConfiguration()->buildSystem()->projectFilePath(); + if (topLevelFile.fileName() == "CMakeLists.txt") + return topLevelFile; + static const auto isApp = [](Node *n) { return n->asProjectNode() + && n->asProjectNode()->productType() == ProductType::App; }; + Node * const appNode = m_step->buildConfiguration()->project()->rootProjectNode() + ->findNode(isApp); + return appNode ? appNode ->filePath() : topLevelFile; +} + bool AndroidBuildApkWidget::isOpenSslLibsIncluded() { - Utils::FilePath projectPath = m_step->buildConfiguration()->buildSystem()->projectFilePath(); + Utils::FilePath projectPath = appProjectFilePath(); const QString searchStr = openSslIncludeFileContent(projectPath); QFile projectFile(projectPath.toString()); projectFile.open(QIODevice::ReadOnly);