Android: add prepare_apk_dir CMake target by default

Qt 6 CMake build doesn't execute prepare_apk_dir by default (this is
the equivalent of install step in qmake). Since we have the target
for installing the build artifacts to android-build already present
in the CMake targets list, it's better to just use it, instead of
using another custom step just for that.

Task-number: QTCREATORBUG-24679
Change-Id: I369d6ce513f9aaf917c5fcbb3f6aa44e36b97af8
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Assam Boudjelthia
2020-09-24 13:03:25 +03:00
parent e685bb3b11
commit 9dcbb8ca01

View File

@@ -32,15 +32,18 @@
#include "cmakeprojectconstants.h"
#include "cmaketool.h"
#include <android/androidconstants.h>
#include <coreplugin/find/itemviewfind.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
@@ -473,6 +476,30 @@ BuildStepConfigWidget *CMakeBuildStep::createConfigWidget()
connect(this, &CMakeBuildStep::buildTargetsChanged, widget, updateDetails);
// For Qt 6 for Android: Make sure to add "<target>_prepare_apk_dir" if only
// "all" target is selected. This copies the build shared libs to android-build
// folder, partially the same as done in AndroidPackageInstallationStep for
// qmake install step.
const Kit *k = target()->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}) {
QMetaObject::Connection *const connection = new QMetaObject::Connection;
*connection = connect(this, &CMakeBuildStep::buildTargetsChanged, widget, [this, connection]() {
const QString mainTarget = activeRunConfigTarget();
if (!mainTarget.isEmpty()) {
QStringList targets{buildTargets()};
if (targets == QStringList{allTarget()}) {
targets.append(QString("%1_prepare_apk_dir").arg(mainTarget));
setBuildTargets({targets});
QObject::disconnect(*connection);
delete connection;
}
}
});
}
}
return widget;
}