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 <hjk@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Alessandro Portale
2021-02-12 20:57:18 +01:00
parent 768d4321f9
commit ae5255cebd
6 changed files with 29 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -32,6 +32,7 @@
#include "androidconstants.h"
#include "androidglobal.h"
#include "androidavdmanager.h"
#include "androidqtversion.h"
#include <coreplugin/fileutils.h>
#include <coreplugin/icore.h>
@@ -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);

View File

@@ -35,7 +35,9 @@
#include <qtsupport/qtsupportconstants.h>
#include <qtsupport/qtversionmanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/project.h>
@@ -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");

View File

@@ -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:

View File

@@ -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)) {