From ae5255cebd7fd00598cd63fabc36c98cf2b39288 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 12 Feb 2021 20:57:18 +0100 Subject: [PATCH] Android: Fix android-*-deployment-settings.json detection Qt 6.0 + CMake: The name for the Android deployment settings file needs to be determined by using the build key of the current run configuration rather than by using the display name of the project root node. Since in contrast to qmake/Qbs, CMake does not supply us with the file name and we have to contruct it ourselves. Therefore, it makes sense to move the value into the Android plugin. This change adds AndroidQtVersion::androidDeploymentSettings which lets qmake and Qbs still provide the value as before while handling the CMake fallback. Fixes: QTCREATORBUG-25209 Change-Id: I12314d06a45d6e045cb654d9140f9d2ed4602f67 Reviewed-by: hjk Reviewed-by: Assam Boudjelthia --- src/plugins/android/androidbuildapkstep.cpp | 9 +++------ src/plugins/android/androiddebugsupport.cpp | 3 ++- src/plugins/android/androiddeployqtstep.cpp | 3 ++- src/plugins/android/androidqtversion.cpp | 20 +++++++++++++++++++ src/plugins/android/androidqtversion.h | 2 ++ .../cmakeprojectmanager/cmakebuildsystem.cpp | 20 ------------------- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp index c6fe7a0f68b..c9c0ab3f800 100644 --- a/src/plugins/android/androidbuildapkstep.cpp +++ b/src/plugins/android/androidbuildapkstep.cpp @@ -31,6 +31,7 @@ #include "androidcreatekeystorecertificate.h" #include "androidextralibrarylistmodel.h" #include "androidmanager.h" +#include "androidqtversion.h" #include "androidsdkmanager.h" #include "certificatesmodel.h" #include "createandroidmanifestwizard.h" @@ -572,13 +573,9 @@ bool AndroidBuildApkStep::init() QString outputDir = buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY).toString(); - const QString buildKey = target()->activeBuildKey(); - const ProjectNode *node = project()->findNodeForBuildKey(buildKey); - if (node) - m_inputFile = node->data(Constants::AndroidDeploySettingsFile).toString(); - + m_inputFile = AndroidQtVersion::androidDeploymentSettings(target()).toString(); if (m_inputFile.isEmpty()) { - qCDebug(buildapkstepLog) << "no input file" << node << buildKey; + qCDebug(buildapkstepLog) << "no input file" << target()->activeBuildKey(); m_skipBuilding = true; return true; } diff --git a/src/plugins/android/androiddebugsupport.cpp b/src/plugins/android/androiddebugsupport.cpp index 04ec22f66c0..47200b7510d 100644 --- a/src/plugins/android/androiddebugsupport.cpp +++ b/src/plugins/android/androiddebugsupport.cpp @@ -78,7 +78,8 @@ static QStringList getSoLibSearchPath(const ProjectNode *node) res.append(node->data(Constants::AndroidSoLibPath).toStringList()); }); - const QString jsonFile = node->data(Android::Constants::AndroidDeploySettingsFile).toString(); + const QString jsonFile = AndroidQtVersion::androidDeploymentSettings( + node->getProject()->activeTarget()).toString(); QFile deploymentSettings(jsonFile); if (deploymentSettings.open(QIODevice::ReadOnly)) { QJsonParseError error; diff --git a/src/plugins/android/androiddeployqtstep.cpp b/src/plugins/android/androiddeployqtstep.cpp index 9a4e6b5ae9b..48db8833c48 100644 --- a/src/plugins/android/androiddeployqtstep.cpp +++ b/src/plugins/android/androiddeployqtstep.cpp @@ -32,6 +32,7 @@ #include "androidconstants.h" #include "androidglobal.h" #include "androidavdmanager.h" +#include "androidqtversion.h" #include #include @@ -200,7 +201,7 @@ bool AndroidDeployQtStep::init() m_command = AndroidConfigurations::currentConfig().adbToolPath(); AndroidManager::setManifestPath(target(), m_manifestName); } else { - QString jsonFile = node->data(Constants::AndroidDeploySettingsFile).toString(); + QString jsonFile = AndroidQtVersion::androidDeploymentSettings(target()).toString(); if (jsonFile.isEmpty()) { const QString error = tr("Cannot find the androiddeploy Json file."); emit addOutput(error, OutputFormat::Stderr); diff --git a/src/plugins/android/androidqtversion.cpp b/src/plugins/android/androidqtversion.cpp index a5da746ccf8..952580462d8 100644 --- a/src/plugins/android/androidqtversion.cpp +++ b/src/plugins/android/androidqtversion.cpp @@ -35,7 +35,9 @@ #include #include +#include #include +#include #include #include #include @@ -169,6 +171,24 @@ int AndroidQtVersion::minimumNDK() const return m_minNdk; } +Utils::FilePath AndroidQtVersion::androidDeploymentSettings(const Target *target) +{ + // Try to fetch the file name from node data as provided by qmake and Qbs + const QString buildKey = target->activeBuildKey(); + const ProjectNode *node = target->project()->findNodeForBuildKey(buildKey); + if (node) { + const QString nameFromData = node->data(Constants::AndroidDeploySettingsFile).toString(); + if (!nameFromData.isEmpty()) + return Utils::FilePath::fromUserInput(nameFromData); + } + // If unavailable, construct the name by ourselves (CMake) + const BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(target->kit()); + const bool isQt6 = qt && qt->qtVersion() >= QtSupport::QtVersionNumber{6, 0, 0}; + return target->activeBuildConfiguration()->buildDirectory().pathAppended( + isQt6 ? QString::fromLatin1("android-%1-deployment-settings.json").arg(buildKey) + : QLatin1String("android_deployment_settings.json")); +} + void AndroidQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const { m_androidAbis = evaluator->values("ALL_ANDROID_ABIS"); diff --git a/src/plugins/android/androidqtversion.h b/src/plugins/android/androidqtversion.h index ab07b0464a8..bb5c5ff7a50 100644 --- a/src/plugins/android/androidqtversion.h +++ b/src/plugins/android/androidqtversion.h @@ -56,6 +56,8 @@ public: const QStringList &androidAbis() const; int minimumNDK() const; + static Utils::FilePath androidDeploymentSettings(const ProjectExplorer::Target *target); + protected: void parseMkSpec(ProFileEvaluator *) const override; private: diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 71e294c28a9..636f0c47f56 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -606,33 +606,13 @@ void CMakeBuildSystem::updateProjectData() auto newRoot = generateProjectTree(m_allFiles, true); if (newRoot) { setRootProjectNode(std::move(newRoot)); - CMakeConfigItem settingFileItem; - settingFileItem.key = Android::Constants::ANDROID_DEPLOYMENT_SETTINGS_FILE; const FilePath buildDir = cmakeBuildConfiguration()->buildDirectory(); if (p->rootProjectNode()) { const QString nodeName = p->rootProjectNode()->displayName(); p->setDisplayName(nodeName); - - const Kit *k = kit(); - if (DeviceTypeKitAspect::deviceTypeId(k) == Android::Constants::ANDROID_DEVICE_TYPE) { - const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k); - if (qt && qt->qtVersion() >= QtSupport::QtVersionNumber{6, 0, 0}) { - const QLatin1String jsonFile("android-%1-deployment-settings.json"); - settingFileItem.value = buildDir.pathAppended(jsonFile.arg(nodeName)) - .toString() - .toUtf8(); - } - } } - if (settingFileItem.value.isEmpty()) { - settingFileItem.value = buildDir.pathAppended("android_deployment_settings.json") - .toString() - .toUtf8(); - } - patchedConfig.append(settingFileItem); - for (const CMakeBuildTarget &bt : qAsConst(m_buildTargets)) { const QString buildKey = bt.title; if (ProjectNode *node = p->findNodeForBuildKey(buildKey)) {