From 9dcbb8ca01e0981b6a3c7ea8dd278014343f48e3 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 24 Sep 2020 13:03:25 +0300 Subject: [PATCH] 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 --- .../cmakeprojectmanager/cmakebuildstep.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index d120623e65e..65e51a41704 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -32,15 +32,18 @@ #include "cmakeprojectconstants.h" #include "cmaketool.h" +#include #include #include #include +#include #include #include #include #include #include - +#include +#include #include #include @@ -473,6 +476,30 @@ BuildStepConfigWidget *CMakeBuildStep::createConfigWidget() connect(this, &CMakeBuildStep::buildTargetsChanged, widget, updateDetails); + // For Qt 6 for Android: Make sure to add "_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; }