2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
#include "androidbuildapkstep.h"
|
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
|
#include "androidconstants.h"
|
2020-09-14 08:13:20 +02:00
|
|
|
#include "androidcreatekeystorecertificate.h"
|
|
|
|
|
#include "androidextralibrarylistmodel.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "androidmanager.h"
|
2021-02-12 20:57:18 +01:00
|
|
|
#include "androidqtversion.h"
|
2017-08-18 08:22:34 +02:00
|
|
|
#include "androidsdkmanager.h"
|
2022-10-06 17:53:35 +02:00
|
|
|
#include "androidtr.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "certificatesmodel.h"
|
2020-09-14 08:13:20 +02:00
|
|
|
#include "createandroidmanifestwizard.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "javaparser.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <projectexplorer/buildstep.h>
|
2019-01-18 18:07:54 +01:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2020-03-31 20:25:54 +02:00
|
|
|
#include <projectexplorer/buildsystem.h>
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <projectexplorer/processparameters.h>
|
2018-07-02 18:40:29 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2018-12-05 10:29:48 +01:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2020-09-01 13:28:50 +03:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
2017-12-06 10:27:27 +01:00
|
|
|
#include <utils/algorithm.h>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <utils/fancylineedit.h>
|
2019-12-13 00:06:34 +01:00
|
|
|
#include <utils/infolabel.h>
|
2022-08-01 18:33:26 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <utils/pathchooser.h>
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QComboBox>
|
2019-03-06 14:17:17 +02:00
|
|
|
#include <QDateTime>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QDialogButtonBox>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QGroupBox>
|
2019-03-06 14:17:17 +02:00
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <QListView>
|
2018-06-18 11:49:14 +02:00
|
|
|
#include <QLoggingCategory>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <QMessageBox>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <QProcess>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QPushButton>
|
2020-02-20 16:41:30 +01:00
|
|
|
#include <QTimer>
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <QToolButton>
|
2016-12-22 17:55:17 +01:00
|
|
|
|
2020-09-14 08:13:20 +02:00
|
|
|
#include <algorithm>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <memory>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
using namespace ProjectExplorer;
|
2020-05-29 07:07:29 +02:00
|
|
|
using namespace QtSupport;
|
2019-05-15 13:59:43 +02:00
|
|
|
using namespace Utils;
|
2018-06-13 13:51:41 +02:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
namespace Android {
|
2020-09-14 08:13:20 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static Q_LOGGING_CATEGORY(buildapkstepLog, "qtc.android.build.androidbuildapkstep", QtWarningMsg)
|
2018-07-02 18:40:29 +02:00
|
|
|
|
2017-06-12 14:23:06 +02:00
|
|
|
const char KeystoreLocationKey[] = "KeystoreLocation";
|
|
|
|
|
const char BuildTargetSdkKey[] = "BuildTargetSdk";
|
|
|
|
|
const char VerboseOutputKey[] = "VerboseOutput";
|
2016-12-22 17:55:17 +01:00
|
|
|
|
2017-10-23 13:42:07 +02:00
|
|
|
class PasswordInputDialog : public QDialog
|
|
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
public:
|
|
|
|
|
enum Context{
|
|
|
|
|
KeystorePassword = 1,
|
|
|
|
|
CertificatePassword
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PasswordInputDialog(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
static QString getPassword(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, bool *ok = nullptr,
|
|
|
|
|
QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::function<bool (const QString &)> verifyCallback = [](const QString &) { return true; };
|
|
|
|
|
QLabel *inputContextlabel = new QLabel(this);
|
|
|
|
|
QLineEdit *inputEdit = new QLineEdit(this);
|
2022-10-06 17:53:35 +02:00
|
|
|
Utils::InfoLabel *warningLabel = new Utils::InfoLabel(::Android::Tr::tr("Incorrect password."),
|
2019-12-13 00:06:34 +01:00
|
|
|
Utils::InfoLabel::Warning, this);
|
2016-12-22 17:55:17 +01:00
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
|
|
|
this);
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-14 08:13:20 +02:00
|
|
|
// AndroidBuildApkWidget
|
|
|
|
|
|
2020-10-02 17:53:39 +02:00
|
|
|
class AndroidBuildApkWidget : public QWidget
|
2020-09-14 08:13:20 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit AndroidBuildApkWidget(AndroidBuildApkStep *step);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setCertificates();
|
|
|
|
|
void updateSigningWarning();
|
|
|
|
|
void signPackageCheckBoxToggled(bool checked);
|
|
|
|
|
void onOpenSslCheckBoxChanged();
|
|
|
|
|
bool isOpenSslLibsIncluded();
|
2021-11-30 13:21:14 +01:00
|
|
|
FilePath appProjectFilePath() const;
|
2020-09-14 08:13:20 +02:00
|
|
|
QString openSslIncludeFileContent(const FilePath &projectPath);
|
|
|
|
|
|
|
|
|
|
QWidget *createApplicationGroup();
|
|
|
|
|
QWidget *createSignPackageGroup();
|
|
|
|
|
QWidget *createAdvancedGroup();
|
|
|
|
|
QWidget *createAdditionalLibrariesGroup();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
AndroidBuildApkStep *m_step = nullptr;
|
|
|
|
|
QCheckBox *m_signPackageCheckBox = nullptr;
|
|
|
|
|
InfoLabel *m_signingDebugWarningLabel = nullptr;
|
|
|
|
|
QComboBox *m_certificatesAliasComboBox = nullptr;
|
|
|
|
|
QCheckBox *m_addDebuggerCheckBox = nullptr;
|
|
|
|
|
QCheckBox *m_openSslCheckBox = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AndroidBuildApkWidget::AndroidBuildApkWidget(AndroidBuildApkStep *step)
|
2020-10-02 17:53:39 +02:00
|
|
|
: m_step(step)
|
2020-09-14 08:13:20 +02:00
|
|
|
{
|
2022-08-01 18:33:26 +02:00
|
|
|
using namespace Layouting;
|
|
|
|
|
Column {
|
|
|
|
|
createSignPackageGroup(),
|
|
|
|
|
createApplicationGroup(),
|
|
|
|
|
createAdvancedGroup(),
|
|
|
|
|
createAdditionalLibrariesGroup()
|
|
|
|
|
}.attachTo(this, WithoutMargins);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
connect(m_step->buildConfiguration(), &BuildConfiguration::buildTypeChanged,
|
|
|
|
|
this, &AndroidBuildApkWidget::updateSigningWarning);
|
|
|
|
|
|
|
|
|
|
connect(m_signPackageCheckBox, &QAbstractButton::clicked,
|
|
|
|
|
m_addDebuggerCheckBox, &QWidget::setEnabled);
|
|
|
|
|
|
|
|
|
|
signPackageCheckBoxToggled(m_step->signPackage());
|
|
|
|
|
updateSigningWarning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AndroidBuildApkWidget::createApplicationGroup()
|
|
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
QtSupport::QtVersion *qt = QtSupport::QtKitAspect::qtVersion(m_step->target()->kit());
|
2021-08-16 20:19:46 +03:00
|
|
|
const int minApiSupported = AndroidManager::defaultMinimumSDK(qt);
|
2020-09-14 08:13:20 +02:00
|
|
|
QStringList targets = AndroidConfig::apiLevelNamesFor(AndroidConfigurations::sdkManager()->
|
|
|
|
|
filteredSdkPlatforms(minApiSupported));
|
|
|
|
|
targets.removeDuplicates();
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto group = new QGroupBox(Tr::tr("Application"), this);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
auto targetSDKComboBox = new QComboBox();
|
|
|
|
|
targetSDKComboBox->addItems(targets);
|
|
|
|
|
targetSDKComboBox->setCurrentIndex(targets.indexOf(m_step->buildTargetSdk()));
|
|
|
|
|
|
2022-07-19 22:51:32 +02:00
|
|
|
connect(targetSDKComboBox, &QComboBox::activated, this, [this, targetSDKComboBox](int idx) {
|
2020-09-14 08:13:20 +02:00
|
|
|
const QString sdk = targetSDKComboBox->itemText(idx);
|
|
|
|
|
m_step->setBuildTargetSdk(sdk);
|
|
|
|
|
AndroidManager::updateGradleProperties(m_step->target(), QString()); // FIXME: Use real key.
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto formLayout = new QFormLayout(group);
|
2022-10-06 17:53:35 +02:00
|
|
|
formLayout->addRow(Tr::tr("Android build platform SDK:"), targetSDKComboBox);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto createAndroidTemplatesButton = new QPushButton(Tr::tr("Create Templates"));
|
2020-09-14 08:13:20 +02:00
|
|
|
createAndroidTemplatesButton->setToolTip(
|
2022-10-06 17:53:35 +02:00
|
|
|
Tr::tr("Create an Android package for Custom Java code, assets, and Gradle configurations."));
|
2020-09-14 08:13:20 +02:00
|
|
|
connect(createAndroidTemplatesButton, &QAbstractButton::clicked, this, [this] {
|
|
|
|
|
CreateAndroidManifestWizard wizard(m_step->buildSystem());
|
|
|
|
|
wizard.exec();
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
formLayout->addRow(Tr::tr("Android customization:"), createAndroidTemplatesButton);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AndroidBuildApkWidget::createSignPackageGroup()
|
|
|
|
|
{
|
|
|
|
|
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
|
|
|
sizePolicy.setHorizontalStretch(0);
|
|
|
|
|
sizePolicy.setVerticalStretch(0);
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto group = new QGroupBox(Tr::tr("Application Signature"), this);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto keystoreLocationLabel = new QLabel(Tr::tr("Keystore:"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
keystoreLocationLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
auto keystoreLocationChooser = new PathChooser(group);
|
|
|
|
|
keystoreLocationChooser->setExpectedKind(PathChooser::File);
|
|
|
|
|
keystoreLocationChooser->lineEdit()->setReadOnly(true);
|
2021-09-08 17:16:43 +02:00
|
|
|
keystoreLocationChooser->setFilePath(m_step->keystorePath());
|
2021-06-08 14:10:12 +02:00
|
|
|
keystoreLocationChooser->setInitialBrowsePathBackup(FileUtils::homePath());
|
2022-10-06 17:53:35 +02:00
|
|
|
keystoreLocationChooser->setPromptDialogFilter(Tr::tr("Keystore files (*.keystore *.jks)"));
|
|
|
|
|
keystoreLocationChooser->setPromptDialogTitle(Tr::tr("Select Keystore File"));
|
2022-09-02 11:49:36 +02:00
|
|
|
connect(keystoreLocationChooser, &PathChooser::textChanged, this, [this, keystoreLocationChooser] {
|
|
|
|
|
const FilePath file = keystoreLocationChooser->rawFilePath();
|
2020-09-14 08:13:20 +02:00
|
|
|
m_step->setKeystorePath(file);
|
|
|
|
|
m_signPackageCheckBox->setChecked(!file.isEmpty());
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
setCertificates();
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto keystoreCreateButton = new QPushButton(Tr::tr("Create..."), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
connect(keystoreCreateButton, &QAbstractButton::clicked, this, [this, keystoreLocationChooser] {
|
|
|
|
|
AndroidCreateKeystoreCertificate d;
|
|
|
|
|
if (d.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2021-09-08 17:16:43 +02:00
|
|
|
keystoreLocationChooser->setFilePath(d.keystoreFilePath());
|
2020-09-14 08:13:20 +02:00
|
|
|
m_step->setKeystorePath(d.keystoreFilePath());
|
|
|
|
|
m_step->setKeystorePassword(d.keystorePassword());
|
|
|
|
|
m_step->setCertificateAlias(d.certificateAlias());
|
|
|
|
|
m_step->setCertificatePassword(d.certificatePassword());
|
|
|
|
|
setCertificates();
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
m_signPackageCheckBox = new QCheckBox(Tr::tr("Sign package"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
m_signPackageCheckBox->setChecked(m_step->signPackage());
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
m_signingDebugWarningLabel = new Utils::InfoLabel(Tr::tr("Signing a debug package"),
|
2020-09-14 08:13:20 +02:00
|
|
|
Utils::InfoLabel::Warning, group);
|
|
|
|
|
m_signingDebugWarningLabel->hide();
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto certificateAliasLabel = new QLabel(Tr::tr("Certificate alias:"), group);
|
2022-08-01 18:33:26 +02:00
|
|
|
certificateAliasLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
m_certificatesAliasComboBox = new QComboBox(group);
|
|
|
|
|
m_certificatesAliasComboBox->setEnabled(false);
|
2022-08-01 18:33:26 +02:00
|
|
|
m_certificatesAliasComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
2022-08-01 18:33:26 +02:00
|
|
|
using namespace Layouting;
|
|
|
|
|
Column {
|
|
|
|
|
Row { keystoreLocationLabel, keystoreLocationChooser, keystoreCreateButton },
|
|
|
|
|
m_signPackageCheckBox,
|
|
|
|
|
Row { m_signingDebugWarningLabel, certificateAliasLabel, m_certificatesAliasComboBox }
|
|
|
|
|
}.attachTo(group);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
connect(m_signPackageCheckBox, &QAbstractButton::toggled,
|
|
|
|
|
this, &AndroidBuildApkWidget::signPackageCheckBoxToggled);
|
|
|
|
|
|
|
|
|
|
auto updateAlias = [this](int idx) {
|
|
|
|
|
QString alias = m_certificatesAliasComboBox->itemText(idx);
|
|
|
|
|
if (!alias.isEmpty())
|
|
|
|
|
m_step->setCertificateAlias(alias);
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-19 22:51:32 +02:00
|
|
|
connect(m_certificatesAliasComboBox, &QComboBox::activated, this, updateAlias);
|
|
|
|
|
connect(m_certificatesAliasComboBox, &QComboBox::currentIndexChanged, this, updateAlias);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AndroidBuildApkWidget::createAdvancedGroup()
|
|
|
|
|
{
|
2022-10-06 17:53:35 +02:00
|
|
|
auto group = new QGroupBox(Tr::tr("Advanced Actions"), this);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto openPackageLocationCheckBox = new QCheckBox(Tr::tr("Open package location after build"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
openPackageLocationCheckBox->setChecked(m_step->openPackageLocation());
|
|
|
|
|
connect(openPackageLocationCheckBox, &QAbstractButton::toggled,
|
|
|
|
|
this, [this](bool checked) { m_step->setOpenPackageLocation(checked); });
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
m_addDebuggerCheckBox = new QCheckBox(Tr::tr("Add debug server"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
m_addDebuggerCheckBox->setEnabled(false);
|
2022-10-06 17:53:35 +02:00
|
|
|
m_addDebuggerCheckBox->setToolTip(Tr::tr("Packages debug server with "
|
2020-09-14 08:13:20 +02:00
|
|
|
"the APK to enable debugging. For the signed APK this option is unchecked by default."));
|
|
|
|
|
m_addDebuggerCheckBox->setChecked(m_step->addDebugger());
|
|
|
|
|
connect(m_addDebuggerCheckBox, &QAbstractButton::toggled,
|
|
|
|
|
m_step, &AndroidBuildApkStep::setAddDebugger);
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
auto verboseOutputCheckBox = new QCheckBox(Tr::tr("Verbose output"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
verboseOutputCheckBox->setChecked(m_step->verboseOutput());
|
|
|
|
|
|
|
|
|
|
auto vbox = new QVBoxLayout(group);
|
2022-01-21 16:06:36 +01:00
|
|
|
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(m_step->kit());
|
2022-07-04 18:36:40 +02:00
|
|
|
if (version && version->qtVersion() >= QVersionNumber(5, 14)) {
|
2022-10-06 17:53:35 +02:00
|
|
|
auto buildAAB = new QCheckBox(Tr::tr("Build Android App Bundle (*.aab)"), group);
|
2020-09-14 08:13:20 +02:00
|
|
|
buildAAB->setChecked(m_step->buildAAB());
|
|
|
|
|
connect(buildAAB, &QAbstractButton::toggled, m_step, &AndroidBuildApkStep::setBuildAAB);
|
|
|
|
|
vbox->addWidget(buildAAB);
|
|
|
|
|
}
|
|
|
|
|
vbox->addWidget(openPackageLocationCheckBox);
|
|
|
|
|
vbox->addWidget(verboseOutputCheckBox);
|
|
|
|
|
vbox->addWidget(m_addDebuggerCheckBox);
|
|
|
|
|
|
|
|
|
|
connect(verboseOutputCheckBox, &QAbstractButton::toggled,
|
|
|
|
|
this, [this](bool checked) { m_step->setVerboseOutput(checked); });
|
|
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AndroidBuildApkWidget::createAdditionalLibrariesGroup()
|
|
|
|
|
{
|
2022-10-06 17:53:35 +02:00
|
|
|
auto group = new QGroupBox(Tr::tr("Additional Libraries"));
|
2020-09-14 08:13:20 +02:00
|
|
|
group->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
auto libsModel = new AndroidExtraLibraryListModel(m_step->buildSystem(), this);
|
|
|
|
|
connect(libsModel, &AndroidExtraLibraryListModel::enabledChanged, this,
|
|
|
|
|
[this, group](const bool enabled) {
|
|
|
|
|
group->setEnabled(enabled);
|
|
|
|
|
m_openSslCheckBox->setChecked(isOpenSslLibsIncluded());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto libsView = new QListView;
|
|
|
|
|
libsView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2022-10-06 17:53:35 +02:00
|
|
|
libsView->setToolTip(Tr::tr("List of extra libraries to include in Android package and load on startup."));
|
2020-09-14 08:13:20 +02:00
|
|
|
libsView->setModel(libsModel);
|
|
|
|
|
|
2022-09-07 12:48:57 +02:00
|
|
|
auto addLibButton = new QPushButton;
|
2022-10-06 17:53:35 +02:00
|
|
|
addLibButton->setText(Tr::tr("Add..."));
|
|
|
|
|
addLibButton->setToolTip(Tr::tr("Select library to include in package."));
|
2020-09-14 08:13:20 +02:00
|
|
|
addLibButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
|
connect(addLibButton, &QAbstractButton::clicked, this, [this, libsModel] {
|
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
2022-10-06 17:53:35 +02:00
|
|
|
Tr::tr("Select additional libraries"),
|
2020-09-14 08:13:20 +02:00
|
|
|
QDir::homePath(),
|
2022-10-06 17:53:35 +02:00
|
|
|
Tr::tr("Libraries (*.so)"));
|
2020-09-14 08:13:20 +02:00
|
|
|
if (!fileNames.isEmpty())
|
|
|
|
|
libsModel->addEntries(fileNames);
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-07 12:48:57 +02:00
|
|
|
auto removeLibButton = new QPushButton;
|
2022-10-06 17:53:35 +02:00
|
|
|
removeLibButton->setText(Tr::tr("Remove"));
|
|
|
|
|
removeLibButton->setToolTip(Tr::tr("Remove currently selected library from list."));
|
2020-09-14 08:13:20 +02:00
|
|
|
connect(removeLibButton, &QAbstractButton::clicked, this, [libsModel, libsView] {
|
|
|
|
|
QModelIndexList removeList = libsView->selectionModel()->selectedIndexes();
|
|
|
|
|
libsModel->removeEntries(removeList);
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
m_openSslCheckBox = new QCheckBox(Tr::tr("Include prebuilt OpenSSL libraries"));
|
|
|
|
|
m_openSslCheckBox->setToolTip(Tr::tr("This is useful for apps that use SSL operations. The path "
|
2022-06-28 10:08:45 +02:00
|
|
|
"can be defined in Edit > Preferences > Devices > Android."));
|
2020-09-14 08:13:20 +02:00
|
|
|
connect(m_openSslCheckBox, &QAbstractButton::clicked, this,
|
|
|
|
|
&AndroidBuildApkWidget::onOpenSslCheckBoxChanged);
|
|
|
|
|
|
2022-08-01 18:33:26 +02:00
|
|
|
using namespace Layouting;
|
|
|
|
|
Grid {
|
|
|
|
|
m_openSslCheckBox, br,
|
|
|
|
|
libsView, Column { addLibButton, removeLibButton, st }
|
|
|
|
|
}.attachTo(group);
|
2020-09-14 08:13:20 +02:00
|
|
|
|
|
|
|
|
QItemSelectionModel *libSelection = libsView->selectionModel();
|
|
|
|
|
connect(libSelection, &QItemSelectionModel::selectionChanged, this, [libSelection, removeLibButton] {
|
|
|
|
|
removeLibButton->setEnabled(libSelection->hasSelection());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Target *target = m_step->target();
|
|
|
|
|
const QString buildKey = target->activeBuildKey();
|
|
|
|
|
const ProjectNode *node = target->project()->findNodeForBuildKey(buildKey);
|
|
|
|
|
group->setEnabled(node && !node->parseInProgress());
|
|
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkWidget::signPackageCheckBoxToggled(bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_certificatesAliasComboBox->setEnabled(checked);
|
|
|
|
|
m_step->setSignPackage(checked);
|
|
|
|
|
m_addDebuggerCheckBox->setChecked(!checked);
|
|
|
|
|
updateSigningWarning();
|
|
|
|
|
if (!checked)
|
|
|
|
|
return;
|
|
|
|
|
if (!m_step->keystorePath().isEmpty())
|
|
|
|
|
setCertificates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkWidget::onOpenSslCheckBoxChanged()
|
|
|
|
|
{
|
2021-11-30 13:21:14 +01:00
|
|
|
Utils::FilePath projectPath = appProjectFilePath();
|
2020-09-14 08:13:20 +02:00
|
|
|
QFile projectFile(projectPath.toString());
|
|
|
|
|
if (!projectFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
2021-10-03 13:13:13 +03:00
|
|
|
qWarning() << "Cannot open project file to add OpenSSL extra libs: " << projectPath;
|
2020-09-14 08:13:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString searchStr = openSslIncludeFileContent(projectPath);
|
|
|
|
|
QTextStream textStream(&projectFile);
|
|
|
|
|
|
|
|
|
|
QString fileContent = textStream.readAll();
|
|
|
|
|
if (!m_openSslCheckBox->isChecked()) {
|
|
|
|
|
fileContent.remove("\n" + searchStr);
|
|
|
|
|
} else if (!fileContent.contains(searchStr, Qt::CaseSensitive)) {
|
|
|
|
|
fileContent.append(searchStr + "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
projectFile.resize(0);
|
|
|
|
|
textStream << fileContent;
|
|
|
|
|
projectFile.close();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 13:21:14 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:13:20 +02:00
|
|
|
bool AndroidBuildApkWidget::isOpenSslLibsIncluded()
|
|
|
|
|
{
|
2021-11-30 13:21:14 +01:00
|
|
|
Utils::FilePath projectPath = appProjectFilePath();
|
2020-09-14 08:13:20 +02:00
|
|
|
const QString searchStr = openSslIncludeFileContent(projectPath);
|
|
|
|
|
QFile projectFile(projectPath.toString());
|
|
|
|
|
projectFile.open(QIODevice::ReadOnly);
|
|
|
|
|
QTextStream textStream(&projectFile);
|
|
|
|
|
QString fileContent = textStream.readAll();
|
|
|
|
|
projectFile.close();
|
|
|
|
|
return fileContent.contains(searchStr, Qt::CaseSensitive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidBuildApkWidget::openSslIncludeFileContent(const FilePath &projectPath)
|
|
|
|
|
{
|
|
|
|
|
QString openSslPath = AndroidConfigurations::currentConfig().openSslLocation().toString();
|
|
|
|
|
if (projectPath.endsWith(".pro"))
|
|
|
|
|
return "android: include(" + openSslPath + "/openssl.pri)";
|
|
|
|
|
if (projectPath.endsWith("CMakeLists.txt"))
|
|
|
|
|
return "if (ANDROID)\n include(" + openSslPath + "/CMakeLists.txt)\nendif()";
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkWidget::setCertificates()
|
|
|
|
|
{
|
|
|
|
|
QAbstractItemModel *certificates = m_step->keystoreCertificates();
|
|
|
|
|
if (certificates) {
|
|
|
|
|
m_signPackageCheckBox->setChecked(certificates);
|
|
|
|
|
m_certificatesAliasComboBox->setModel(certificates);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkWidget::updateSigningWarning()
|
|
|
|
|
{
|
|
|
|
|
bool nonRelease = m_step->buildType() != BuildConfiguration::Release;
|
|
|
|
|
bool visible = m_step->signPackage() && nonRelease;
|
|
|
|
|
m_signingDebugWarningLabel->setVisible(visible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AndroidBuildApkStep
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
AndroidBuildApkStep::AndroidBuildApkStep(BuildStepList *parent, Utils::Id id)
|
2019-12-20 17:05:30 +01:00
|
|
|
: AbstractProcessStep(parent, id),
|
2017-08-18 08:22:34 +02:00
|
|
|
m_buildTargetSdk(AndroidConfig::apiLevelNameFor(AndroidConfigurations::
|
|
|
|
|
sdkManager()->latestAndroidSdkPlatform()))
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2018-10-22 17:56:04 +02:00
|
|
|
setImmutable(true);
|
2022-10-06 17:53:35 +02:00
|
|
|
setDisplayName(Tr::tr("Build Android APK"));
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:31:44 +01:00
|
|
|
bool AndroidBuildApkStep::init()
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2021-10-03 13:13:13 +03:00
|
|
|
if (!AbstractProcessStep::init()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("\"%1\" step failed initialization.").arg(displayName()),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
2020-09-14 17:17:55 +02:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2020-09-14 17:17:55 +02:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
if (m_signPackage) {
|
2018-06-18 11:49:14 +02:00
|
|
|
qCDebug(buildapkstepLog) << "Signing enabled";
|
2014-06-25 15:42:11 +02:00
|
|
|
// check keystore and certificate passwords
|
2018-06-18 11:49:14 +02:00
|
|
|
if (!verifyKeystorePassword() || !verifyCertificatePassword()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Keystore/Certificate password verification failed."),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
2016-12-22 17:55:17 +01:00
|
|
|
return false;
|
2018-06-18 11:49:14 +02:00
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2021-10-03 13:13:13 +03:00
|
|
|
if (buildType() != BuildConfiguration::Release)
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Warning: Signing a debug or profile package."), Task::Warning);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
|
2021-10-03 13:13:13 +03:00
|
|
|
if (!version) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.").arg(kit()->displayName()),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
2014-06-25 15:42:11 +02:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2017-07-31 13:36:18 +02:00
|
|
|
const QVersionNumber sdkToolsVersion = AndroidConfigurations::currentConfig().sdkToolsVersion();
|
2021-05-28 18:22:44 +03:00
|
|
|
if (sdkToolsVersion >= QVersionNumber(25, 3, 0)
|
2020-11-28 15:44:37 +02:00
|
|
|
&& AndroidConfigurations::currentConfig().preCmdlineSdkToolsInstalled()) {
|
2019-05-17 13:20:41 +02:00
|
|
|
if (!version->sourcePath().pathAppended("src/3rdparty/gradle").exists()) {
|
2020-09-01 13:28:50 +03:00
|
|
|
const QString error
|
2022-10-06 17:53:35 +02:00
|
|
|
= Tr::tr("The installed SDK tools version (%1) does not include Gradle "
|
|
|
|
|
"scripts. The minimum Qt version required for Gradle build to work "
|
|
|
|
|
"is %2")
|
|
|
|
|
.arg(sdkToolsVersion.toString())
|
|
|
|
|
.arg("5.9.0/5.6.3");
|
2021-10-03 13:13:13 +03:00
|
|
|
reportWarningOrError(error, Task::Error);
|
2017-09-08 23:36:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2022-07-04 18:36:40 +02:00
|
|
|
} else if (version->qtVersion() < QVersionNumber(5, 4, 0)) {
|
2022-10-06 17:53:35 +02:00
|
|
|
const QString error = Tr::tr("The minimum Qt version required for Gradle build to work is %1. "
|
|
|
|
|
"It is recommended to install the latest Qt version.")
|
|
|
|
|
.arg("5.4.0");
|
2021-10-03 13:13:13 +03:00
|
|
|
reportWarningOrError(error, Task::Error);
|
2017-04-12 14:08:17 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 15:56:18 +02:00
|
|
|
const int minSDKForKit = AndroidManager::minimumSDK(kit());
|
2016-08-17 18:46:12 +02:00
|
|
|
if (AndroidManager::minimumSDK(target()) < minSDKForKit) {
|
2020-09-01 13:28:50 +03:00
|
|
|
const QString error
|
2022-10-06 17:53:35 +02:00
|
|
|
= Tr::tr("The API level set for the APK is less than the minimum required by the kit."
|
|
|
|
|
"\nThe minimum API level required by the kit is %1.")
|
|
|
|
|
.arg(minSDKForKit);
|
2021-10-03 13:13:13 +03:00
|
|
|
reportWarningOrError(error, Task::Error);
|
2016-08-17 18:46:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
m_openPackageLocationForRun = m_openPackageLocation;
|
2021-08-23 21:36:55 +03:00
|
|
|
const FilePath outputDir = AndroidManager::androidBuildDirectory(target());
|
2020-02-19 11:55:48 +01:00
|
|
|
|
|
|
|
|
if (m_buildAAB) {
|
|
|
|
|
const QString bt = buildType() == BuildConfiguration::Release ? QLatin1String("release")
|
|
|
|
|
: QLatin1String("debug");
|
2021-08-23 21:36:55 +03:00
|
|
|
m_packagePath = outputDir.pathAppended(
|
2021-09-20 09:47:45 +02:00
|
|
|
QString("build/outputs/bundle/%1/android-build-%1.aab").arg(bt));
|
2020-02-19 11:55:48 +01:00
|
|
|
} else {
|
2021-08-12 12:08:08 +02:00
|
|
|
m_packagePath = AndroidManager::apkPath(target());
|
2020-02-19 11:55:48 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 18:02:52 +02:00
|
|
|
qCDebug(buildapkstepLog).noquote() << "APK or AAB path:" << m_packagePath.toUserOutput();
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2021-08-11 08:11:44 +02:00
|
|
|
FilePath command = version->hostBinPath().pathAppended("androiddeployqt").withExecutableSuffix();
|
2018-06-13 13:51:41 +02:00
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
m_inputFile = AndroidQtVersion::androidDeploymentSettings(target());
|
2020-01-20 11:20:09 +02:00
|
|
|
if (m_inputFile.isEmpty()) {
|
2018-06-13 13:51:41 +02:00
|
|
|
m_skipBuilding = true;
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("No valid input file for \"%1\".").arg(target()->activeBuildKey()),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Warning);
|
2018-06-13 13:51:41 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-03-11 17:23:12 +01:00
|
|
|
m_skipBuilding = false;
|
2018-06-13 13:51:41 +02:00
|
|
|
|
2020-02-12 18:25:11 +01:00
|
|
|
if (m_buildTargetSdk.isEmpty()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Android build SDK version is not defined. Check Android settings.")
|
2021-10-03 13:13:13 +03:00
|
|
|
, Task::Error);
|
2018-06-13 13:51:41 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
QStringList arguments = {"--input", m_inputFile.toString(),
|
|
|
|
|
"--output", outputDir.toString(),
|
2020-02-12 18:25:11 +01:00
|
|
|
"--android-platform", m_buildTargetSdk,
|
2018-06-13 13:51:41 +02:00
|
|
|
"--jdk", AndroidConfigurations::currentConfig().openJDKLocation().toString()};
|
|
|
|
|
|
|
|
|
|
if (m_verbose)
|
|
|
|
|
arguments << "--verbose";
|
|
|
|
|
|
|
|
|
|
arguments << "--gradle";
|
|
|
|
|
|
2019-08-26 14:19:07 +03:00
|
|
|
if (m_buildAAB)
|
|
|
|
|
arguments << "--aab" << "--jarsigner";
|
|
|
|
|
|
2022-09-13 09:24:25 +03:00
|
|
|
if (buildType() == BuildConfiguration::Release) {
|
|
|
|
|
arguments << "--release";
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
QStringList argumentsPasswordConcealed = arguments;
|
|
|
|
|
|
|
|
|
|
if (m_signPackage) {
|
2022-09-13 09:24:25 +03:00
|
|
|
arguments << "--sign" << m_keystorePath.toString() << m_certificateAlias
|
2018-06-13 13:51:41 +02:00
|
|
|
<< "--storepass" << m_keystorePasswd;
|
2022-09-13 09:24:25 +03:00
|
|
|
argumentsPasswordConcealed << "--sign" << "******"
|
2018-06-13 13:51:41 +02:00
|
|
|
<< "--storepass" << "******";
|
|
|
|
|
if (!m_certificatePasswd.isEmpty()) {
|
|
|
|
|
arguments << "--keypass" << m_certificatePasswd;
|
|
|
|
|
argumentsPasswordConcealed << "--keypass" << "******";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Must be the last option, otherwise androiddeployqt might use the other
|
|
|
|
|
// params (e.g. --sign) to choose not to add gdbserver
|
2022-07-04 18:36:40 +02:00
|
|
|
if (version->qtVersion() >= QVersionNumber(5, 6, 0)) {
|
2020-02-19 11:55:48 +01:00
|
|
|
if (m_addDebugger || buildType() == ProjectExplorer::BuildConfiguration::Debug)
|
2018-06-13 13:51:41 +02:00
|
|
|
arguments << "--gdbserver";
|
|
|
|
|
else
|
|
|
|
|
arguments << "--no-gdbserver";
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 17:17:55 +02:00
|
|
|
processParameters()->setCommandLine({command, arguments});
|
2018-06-13 13:51:41 +02:00
|
|
|
|
|
|
|
|
// Generate arguments with keystore password concealed
|
|
|
|
|
ProjectExplorer::ProcessParameters pp2;
|
2020-08-13 16:47:33 +02:00
|
|
|
setupProcessParameters(&pp2);
|
2020-09-15 08:03:08 +02:00
|
|
|
pp2.setCommandLine({command, argumentsPasswordConcealed});
|
2021-08-17 18:10:52 +02:00
|
|
|
m_command = pp2.effectiveCommand();
|
2018-06-13 13:51:41 +02:00
|
|
|
m_argumentsPasswordConcealed = pp2.prettyArguments();
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
void AndroidBuildApkStep::setupOutputFormatter(OutputFormatter *formatter)
|
|
|
|
|
{
|
|
|
|
|
const auto parser = new JavaParser;
|
2021-05-05 16:33:31 +02:00
|
|
|
parser->setProjectFileList(project()->files(Project::AllFiles));
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
const QString buildKey = target()->activeBuildKey();
|
|
|
|
|
const ProjectNode *node = project()->findNodeForBuildKey(buildKey);
|
2021-08-17 18:10:52 +02:00
|
|
|
FilePath sourceDirPath;
|
2020-04-16 13:53:05 +02:00
|
|
|
if (node)
|
2021-08-17 18:10:52 +02:00
|
|
|
sourceDirPath = FilePath::fromVariant(node->data(Constants::AndroidPackageSourceDir));
|
|
|
|
|
parser->setSourceDirectory(sourceDirPath.canonicalPath());
|
2021-08-23 21:36:55 +03:00
|
|
|
parser->setBuildDirectory(AndroidManager::androidBuildDirectory(target()));
|
2020-04-16 13:53:05 +02:00
|
|
|
formatter->addLineParser(parser);
|
|
|
|
|
AbstractProcessStep::setupOutputFormatter(formatter);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
void AndroidBuildApkStep::showInGraphicalShell()
|
|
|
|
|
{
|
2021-08-12 12:08:08 +02:00
|
|
|
Core::FileUtils::showInGraphicalShell(Core::ICore::dialogParent(), m_packagePath);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-02 17:53:39 +02:00
|
|
|
QWidget *AndroidBuildApkStep::createConfigWidget()
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2018-07-02 18:40:29 +02:00
|
|
|
return new AndroidBuildApkWidget(this);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::processFinished(int exitCode, QProcess::ExitStatus status)
|
|
|
|
|
{
|
|
|
|
|
AbstractProcessStep::processFinished(exitCode, status);
|
|
|
|
|
if (m_openPackageLocationForRun && status == QProcess::NormalExit && exitCode == 0)
|
2020-02-20 16:41:30 +01:00
|
|
|
QTimer::singleShot(0, this, &AndroidBuildApkStep::showInGraphicalShell);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
bool AndroidBuildApkStep::verifyKeystorePassword()
|
|
|
|
|
{
|
2017-01-10 16:33:56 +01:00
|
|
|
if (!m_keystorePath.exists()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Cannot sign the package. Invalid keystore path (%1).")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(m_keystorePath.toString()), Task::Error);
|
2017-01-10 16:33:56 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
if (AndroidManager::checkKeystorePassword(m_keystorePath.toString(), m_keystorePasswd))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
auto verifyCallback = std::bind(&AndroidManager::checkKeystorePassword,
|
|
|
|
|
m_keystorePath.toString(), std::placeholders::_1);
|
|
|
|
|
m_keystorePasswd = PasswordInputDialog::getPassword(PasswordInputDialog::KeystorePassword,
|
|
|
|
|
verifyCallback, "", &success);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::verifyCertificatePassword()
|
|
|
|
|
{
|
2017-01-10 16:33:56 +01:00
|
|
|
if (!AndroidManager::checkCertificateExists(m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias)) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Cannot sign the package. Certificate alias %1 does not exist.")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(m_certificateAlias), Task::Error);
|
2017-01-10 16:33:56 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
if (AndroidManager::checkCertificatePassword(m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias, m_certificatePasswd)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
auto verifyCallback = std::bind(&AndroidManager::checkCertificatePassword,
|
|
|
|
|
m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias, std::placeholders::_1);
|
|
|
|
|
|
|
|
|
|
m_certificatePasswd = PasswordInputDialog::getPassword(PasswordInputDialog::CertificatePassword,
|
|
|
|
|
verifyCallback, m_certificateAlias,
|
|
|
|
|
&success);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
static bool copyFileIfNewer(const FilePath &sourceFilePath,
|
|
|
|
|
const FilePath &destinationFilePath)
|
2019-03-06 14:17:17 +02:00
|
|
|
{
|
2021-08-17 18:10:52 +02:00
|
|
|
if (sourceFilePath == destinationFilePath)
|
2020-01-20 11:20:09 +02:00
|
|
|
return true;
|
2021-08-17 18:10:52 +02:00
|
|
|
if (destinationFilePath.exists()) {
|
|
|
|
|
if (sourceFilePath.lastModified() <= destinationFilePath.lastModified())
|
2019-03-06 14:17:17 +02:00
|
|
|
return true;
|
2021-08-17 18:10:52 +02:00
|
|
|
if (!destinationFilePath.removeFile())
|
2019-03-06 14:17:17 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
if (!destinationFilePath.parentDir().ensureWritableDir())
|
2019-03-06 14:17:17 +02:00
|
|
|
return false;
|
2021-08-17 18:10:52 +02:00
|
|
|
return sourceFilePath.copyFile(destinationFilePath);
|
2019-03-06 14:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void AndroidBuildApkStep::doRun()
|
2018-06-13 13:51:41 +02:00
|
|
|
{
|
|
|
|
|
if (m_skipBuilding) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Android deploy settings file not found, not building an APK."),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
emit finished(true);
|
2018-06-13 13:51:41 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
auto setup = [this] {
|
2019-08-26 14:19:07 +03:00
|
|
|
const auto androidAbis = AndroidManager::applicationAbis(target());
|
2021-05-25 19:34:25 +03:00
|
|
|
const QString buildKey = target()->activeBuildKey();
|
|
|
|
|
|
2022-01-21 16:06:36 +01:00
|
|
|
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
|
2021-10-03 13:13:13 +03:00
|
|
|
if (!version) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(kit()->displayName()), Task::Error);
|
2021-05-25 19:34:25 +03:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2021-05-25 19:34:25 +03:00
|
|
|
|
2021-08-23 21:36:55 +03:00
|
|
|
const FilePath buildDir = buildDirectory();
|
|
|
|
|
const FilePath androidBuildDir = AndroidManager::androidBuildDirectory(target());
|
2019-08-26 14:19:07 +03:00
|
|
|
for (const auto &abi : androidAbis) {
|
2021-08-23 21:36:55 +03:00
|
|
|
FilePath androidLibsDir = androidBuildDir / "libs" / abi;
|
2021-05-25 19:34:25 +03:00
|
|
|
if (!androidLibsDir.exists()) {
|
2021-08-17 18:10:52 +02:00
|
|
|
if (!androidLibsDir.ensureWritableDir()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("The Android build folder %1 was not found and could "
|
|
|
|
|
"not be created.").arg(androidLibsDir.toUserOutput()),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
2021-05-25 19:34:25 +03:00
|
|
|
return false;
|
2022-07-04 18:36:40 +02:00
|
|
|
} else if (version->qtVersion() >= QVersionNumber(6, 0, 0)
|
|
|
|
|
&& version->qtVersion() <= QVersionNumber(6, 1, 1)) {
|
2021-05-25 19:34:25 +03:00
|
|
|
// 6.0.x <= Qt <= 6.1.1 used to need a manaul call to _prepare_apk_dir target,
|
|
|
|
|
// and now it's made directly with ALL target, so this code below ensures
|
|
|
|
|
// these versions are not broken.
|
|
|
|
|
const QString fileName = QString("lib%1_%2.so").arg(buildKey, abi);
|
2021-08-23 21:36:55 +03:00
|
|
|
const FilePath from = buildDir / fileName;
|
2021-05-25 19:34:25 +03:00
|
|
|
const FilePath to = androidLibsDir / fileName;
|
|
|
|
|
if (!from.exists() || to.exists())
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
if (!from.copyFile(to)) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Cannot copy the target's lib file %1 to the "
|
2021-10-03 13:13:13 +03:00
|
|
|
"Android build folder %2.")
|
|
|
|
|
.arg(fileName, androidLibsDir.toUserOutput()),
|
|
|
|
|
Task::Error);
|
2021-05-25 19:34:25 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-05-25 19:34:25 +03:00
|
|
|
}
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
bool inputExists = m_inputFile.exists();
|
|
|
|
|
if (inputExists && !AndroidManager::isQtCreatorGenerated(m_inputFile))
|
2020-01-20 11:20:09 +02:00
|
|
|
return true; // use the generated file if it was not generated by qtcreator
|
2019-10-18 09:25:14 +03:00
|
|
|
|
2021-05-25 19:34:25 +03:00
|
|
|
BuildSystem *bs = buildSystem();
|
2021-09-20 14:30:42 +02:00
|
|
|
const FilePaths targets = Utils::transform(
|
|
|
|
|
bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
|
|
|
|
|
&FilePath::fromUserInput);
|
2019-03-06 14:17:17 +02:00
|
|
|
if (targets.isEmpty())
|
2020-01-20 11:20:09 +02:00
|
|
|
return inputExists; // qmake does this job for us
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2020-01-20 11:20:09 +02:00
|
|
|
QJsonObject deploySettings = Android::AndroidManager::deploymentSettings(target());
|
|
|
|
|
QString applicationBinary;
|
2020-08-20 13:58:21 +02:00
|
|
|
if (!version->supportsMultipleQtAbis()) {
|
2020-01-20 11:20:09 +02:00
|
|
|
QTC_ASSERT(androidAbis.size() == 1, return false);
|
2020-03-31 20:25:54 +02:00
|
|
|
applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.toString();
|
2021-08-23 21:36:55 +03:00
|
|
|
FilePath androidLibsDir = androidBuildDir / "libs" / androidAbis.first();
|
2021-08-17 18:10:52 +02:00
|
|
|
for (const FilePath &target : targets) {
|
2021-10-03 13:13:13 +03:00
|
|
|
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
|
|
|
|
|
reportWarningOrError(
|
2022-10-06 17:53:35 +02:00
|
|
|
Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
|
|
|
|
|
Task::Error);
|
2020-01-20 11:20:09 +02:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2020-01-20 11:20:09 +02:00
|
|
|
}
|
|
|
|
|
deploySettings["target-architecture"] = androidAbis.first();
|
|
|
|
|
} else {
|
2021-06-04 08:38:29 +02:00
|
|
|
applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.fileName();
|
2020-01-20 11:20:09 +02:00
|
|
|
QJsonObject architectures;
|
|
|
|
|
|
|
|
|
|
// Copy targets to android build folder
|
|
|
|
|
for (const auto &abi : androidAbis) {
|
|
|
|
|
QString targetSuffix = QString{"_%1.so"}.arg(abi);
|
|
|
|
|
if (applicationBinary.endsWith(targetSuffix)) {
|
|
|
|
|
// Keep only TargetName from "lib[TargetName]_abi.so"
|
|
|
|
|
applicationBinary.remove(0, 3).chop(targetSuffix.size());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 21:36:55 +03:00
|
|
|
FilePath androidLibsDir = androidBuildDir / "libs" / abi;
|
2021-08-17 18:10:52 +02:00
|
|
|
for (const FilePath &target : targets) {
|
2020-01-20 11:20:09 +02:00
|
|
|
if (target.endsWith(targetSuffix)) {
|
2021-10-03 13:13:13 +03:00
|
|
|
const FilePath destination = androidLibsDir.pathAppended(target.fileName());
|
|
|
|
|
if (!copyFileIfNewer(target, destination)) {
|
|
|
|
|
reportWarningOrError(
|
2022-10-06 17:53:35 +02:00
|
|
|
Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
|
|
|
|
|
Task::Error);
|
2020-01-20 11:20:09 +02:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2020-01-20 11:20:09 +02:00
|
|
|
architectures[abi] = AndroidManager::archTriplet(abi);
|
2019-08-26 14:19:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-20 11:20:09 +02:00
|
|
|
deploySettings["architectures"] = architectures;
|
2019-03-06 14:17:17 +02:00
|
|
|
}
|
2019-08-26 14:19:07 +03:00
|
|
|
deploySettings["application-binary"] = applicationBinary;
|
|
|
|
|
|
2020-04-03 11:20:42 +02:00
|
|
|
QString extraLibs = bs->extraData(buildKey, Android::Constants::AndroidExtraLibs).toString();
|
2019-03-06 14:17:17 +02:00
|
|
|
if (!extraLibs.isEmpty())
|
|
|
|
|
deploySettings["android-extra-libs"] = extraLibs;
|
|
|
|
|
|
2020-04-03 11:20:42 +02:00
|
|
|
QString androidSrcs = bs->extraData(buildKey, Android::Constants::AndroidPackageSourceDir).toString();
|
2019-03-06 14:17:17 +02:00
|
|
|
if (!androidSrcs.isEmpty())
|
|
|
|
|
deploySettings["android-package-source-directory"] = androidSrcs;
|
|
|
|
|
|
2020-04-03 11:20:42 +02:00
|
|
|
QString qmlImportPath = bs->extraData(buildKey, "QML_IMPORT_PATH").toString();
|
2019-03-06 14:17:17 +02:00
|
|
|
if (!qmlImportPath.isEmpty())
|
|
|
|
|
deploySettings["qml-import-paths"] = qmlImportPath;
|
|
|
|
|
|
2020-04-03 11:20:42 +02:00
|
|
|
QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
|
2019-03-06 14:17:17 +02:00
|
|
|
if (qmlRootPath.isEmpty())
|
|
|
|
|
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
2019-05-30 15:16:07 +02:00
|
|
|
deploySettings["qml-root-path"] = qmlRootPath;
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-08-17 18:10:52 +02:00
|
|
|
QFile f{m_inputFile.toString()};
|
2021-10-03 13:13:13 +03:00
|
|
|
if (!f.open(QIODevice::WriteOnly)) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
|
2021-10-03 13:13:13 +03:00
|
|
|
.arg(m_inputFile.toUserOutput()), Task::Error);
|
2019-03-06 14:17:17 +02:00
|
|
|
return false;
|
2021-10-03 13:13:13 +03:00
|
|
|
}
|
2019-03-06 14:17:17 +02:00
|
|
|
f.write(QJsonDocument{deploySettings}.toJson());
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!setup()) {
|
2022-10-06 17:53:35 +02:00
|
|
|
reportWarningOrError(Tr::tr("Cannot set up \"%1\", not building an APK.").arg(displayName()),
|
2021-10-03 13:13:13 +03:00
|
|
|
Task::Error);
|
2019-03-06 14:17:17 +02:00
|
|
|
emit finished(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
AbstractProcessStep::doRun();
|
2018-06-13 13:51:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-03 13:13:13 +03:00
|
|
|
void AndroidBuildApkStep::reportWarningOrError(const QString &message, Task::TaskType type)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(buildapkstepLog) << message;
|
|
|
|
|
emit addOutput(message, OutputFormat::ErrorMessage);
|
|
|
|
|
TaskHub::addTask(BuildSystemTask(type, message));
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
void AndroidBuildApkStep::processStarted()
|
|
|
|
|
{
|
2022-10-06 17:53:35 +02:00
|
|
|
emit addOutput(Tr::tr("Starting: \"%1\" %2")
|
2021-08-17 18:10:52 +02:00
|
|
|
.arg(m_command.toUserOutput(), m_argumentsPasswordConcealed),
|
2018-06-13 13:51:41 +02:00
|
|
|
BuildStep::OutputFormat::NormalMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2021-08-17 18:10:52 +02:00
|
|
|
m_keystorePath = FilePath::fromVariant(map.value(KeystoreLocationKey));
|
2014-06-25 15:42:11 +02:00
|
|
|
m_signPackage = false; // don't restore this
|
|
|
|
|
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
|
2017-08-18 08:22:34 +02:00
|
|
|
if (m_buildTargetSdk.isEmpty()) {
|
|
|
|
|
m_buildTargetSdk = AndroidConfig::apiLevelNameFor(AndroidConfigurations::
|
|
|
|
|
sdkManager()->latestAndroidSdkPlatform());
|
|
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
m_verbose = map.value(VerboseOutputKey).toBool();
|
|
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidBuildApkStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap();
|
2021-08-17 18:10:52 +02:00
|
|
|
map.insert(KeystoreLocationKey, m_keystorePath.toVariant());
|
2014-06-25 15:42:11 +02:00
|
|
|
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
|
|
|
|
|
map.insert(VerboseOutputKey, m_verbose);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
Utils::FilePath AndroidBuildApkStep::keystorePath()
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
|
|
|
|
return m_keystorePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidBuildApkStep::buildTargetSdk() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargetSdk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setBuildTargetSdk(const QString &sdk)
|
|
|
|
|
{
|
|
|
|
|
m_buildTargetSdk = sdk;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-01 13:28:50 +03:00
|
|
|
void AndroidBuildApkStep::stdError(const QString &output)
|
|
|
|
|
{
|
|
|
|
|
AbstractProcessStep::stdError(output);
|
|
|
|
|
|
2020-11-20 18:11:33 +02:00
|
|
|
QString newOutput = output;
|
|
|
|
|
newOutput.remove(QRegularExpression("^(\\n)+"));
|
|
|
|
|
|
2020-11-23 15:53:19 +02:00
|
|
|
if (newOutput.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-11-20 18:11:33 +02:00
|
|
|
if (newOutput.startsWith("warning", Qt::CaseInsensitive)
|
|
|
|
|
|| newOutput.startsWith("note", Qt::CaseInsensitive))
|
|
|
|
|
TaskHub::addTask(BuildSystemTask(Task::Warning, newOutput));
|
2020-09-01 13:28:50 +03:00
|
|
|
else
|
2020-11-20 18:11:33 +02:00
|
|
|
TaskHub::addTask(BuildSystemTask(Task::Error, newOutput));
|
2020-09-01 13:28:50 +03:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QVariant AndroidBuildApkStep::data(Utils::Id id) const
|
2019-03-06 14:17:17 +02:00
|
|
|
{
|
2020-02-16 20:46:23 +02:00
|
|
|
if (id == Constants::AndroidNdkPlatform) {
|
2020-09-07 15:56:18 +02:00
|
|
|
if (auto qtVersion = QtKitAspect::qtVersion(kit()))
|
2020-05-29 07:07:29 +02:00
|
|
|
return AndroidConfigurations::currentConfig()
|
|
|
|
|
.bestNdkPlatformMatch(AndroidManager::minimumSDK(target()), qtVersion).mid(8);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
if (id == Constants::NdkLocation) {
|
2020-09-07 15:56:18 +02:00
|
|
|
if (auto qtVersion = QtKitAspect::qtVersion(kit()))
|
2020-05-29 07:07:29 +02:00
|
|
|
return QVariant::fromValue(AndroidConfigurations::currentConfig().ndkLocation(qtVersion));
|
|
|
|
|
return {};
|
2020-02-16 20:46:23 +02:00
|
|
|
}
|
2019-10-18 09:25:14 +03:00
|
|
|
if (id == Constants::SdkLocation)
|
|
|
|
|
return QVariant::fromValue(AndroidConfigurations::currentConfig().sdkLocation());
|
2021-09-05 18:49:26 +03:00
|
|
|
|
|
|
|
|
if (id == Constants::AndroidMkSpecAbis)
|
2019-08-26 14:19:07 +03:00
|
|
|
return AndroidManager::applicationAbis(target());
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
return AbstractProcessStep::data(id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void AndroidBuildApkStep::setKeystorePath(const Utils::FilePath &path)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
|
|
|
|
m_keystorePath = path;
|
|
|
|
|
m_certificatePasswd.clear();
|
|
|
|
|
m_keystorePasswd.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setKeystorePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setCertificateAlias(const QString &alias)
|
|
|
|
|
{
|
|
|
|
|
m_certificateAlias = alias;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setCertificatePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_certificatePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::signPackage() const
|
|
|
|
|
{
|
|
|
|
|
return m_signPackage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setSignPackage(bool b)
|
|
|
|
|
{
|
|
|
|
|
m_signPackage = b;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 14:19:07 +03:00
|
|
|
bool AndroidBuildApkStep::buildAAB() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildAAB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setBuildAAB(bool aab)
|
|
|
|
|
{
|
|
|
|
|
m_buildAAB = aab;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::openPackageLocation() const
|
|
|
|
|
{
|
|
|
|
|
return m_openPackageLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setOpenPackageLocation(bool open)
|
|
|
|
|
{
|
|
|
|
|
m_openPackageLocation = open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setVerboseOutput(bool verbose)
|
|
|
|
|
{
|
|
|
|
|
m_verbose = verbose;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 14:03:20 +02:00
|
|
|
bool AndroidBuildApkStep::addDebugger() const
|
|
|
|
|
{
|
|
|
|
|
return m_addDebugger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setAddDebugger(bool debug)
|
|
|
|
|
{
|
|
|
|
|
m_addDebugger = debug;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::verboseOutput() const
|
|
|
|
|
{
|
|
|
|
|
return m_verbose;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *AndroidBuildApkStep::keystoreCertificates()
|
|
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
// check keystore passwords
|
|
|
|
|
if (!verifyKeystorePassword())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
CertificatesModel *model = nullptr;
|
2017-06-12 18:23:05 +02:00
|
|
|
const QStringList params = {"-list", "-v", "-keystore", m_keystorePath.toUserOutput(),
|
|
|
|
|
"-storepass", m_keystorePasswd, "-J-Duser.language=en"};
|
2016-12-22 17:55:17 +01:00
|
|
|
|
2021-06-22 04:33:47 +02:00
|
|
|
QtcProcess keytoolProc;
|
2016-12-22 17:55:17 +01:00
|
|
|
keytoolProc.setTimeoutS(30);
|
2021-05-17 12:02:42 +02:00
|
|
|
keytoolProc.setCommand({AndroidConfigurations::currentConfig().keytoolPath(), params});
|
2022-03-02 04:12:25 +01:00
|
|
|
keytoolProc.runBlocking(EventLoopMode::On);
|
|
|
|
|
if (keytoolProc.result() > ProcessResult::FinishedWithError)
|
2022-10-06 17:53:35 +02:00
|
|
|
QMessageBox::critical(nullptr, Tr::tr("Error"), Tr::tr("Failed to run keytool."));
|
2016-12-22 17:55:17 +01:00
|
|
|
else
|
2022-06-17 14:17:14 +02:00
|
|
|
model = new CertificatesModel(keytoolProc.cleanedStdOut(), this);
|
2016-12-22 17:55:17 +01:00
|
|
|
|
|
|
|
|
return model;
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
PasswordInputDialog::PasswordInputDialog(PasswordInputDialog::Context context,
|
|
|
|
|
std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr,
|
|
|
|
|
QWidget *parent) :
|
|
|
|
|
QDialog(parent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint),
|
|
|
|
|
verifyCallback(callback)
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
inputEdit->setEchoMode(QLineEdit::Password);
|
|
|
|
|
|
|
|
|
|
warningLabel->hide();
|
|
|
|
|
|
|
|
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
mainLayout->addWidget(inputContextlabel);
|
|
|
|
|
mainLayout->addWidget(inputEdit);
|
2019-12-13 00:06:34 +01:00
|
|
|
mainLayout->addWidget(warningLabel);
|
2016-12-22 17:55:17 +01:00
|
|
|
mainLayout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
|
|
connect(inputEdit, &QLineEdit::textChanged,[this](const QString &text) {
|
|
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-19 22:51:32 +02:00
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, [this] {
|
2016-12-22 17:55:17 +01:00
|
|
|
if (verifyCallback(inputEdit->text())) {
|
|
|
|
|
accept(); // Dialog accepted.
|
|
|
|
|
} else {
|
|
|
|
|
warningLabel->show();
|
|
|
|
|
inputEdit->clear();
|
|
|
|
|
adjustSize();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
|
2022-10-06 17:53:35 +02:00
|
|
|
setWindowTitle(context == KeystorePassword ? Tr::tr("Keystore") : Tr::tr("Certificate"));
|
2016-12-22 17:55:17 +01:00
|
|
|
|
|
|
|
|
QString contextStr;
|
|
|
|
|
if (context == KeystorePassword)
|
2022-10-06 17:53:35 +02:00
|
|
|
contextStr = Tr::tr("Enter keystore password");
|
2016-12-22 17:55:17 +01:00
|
|
|
else
|
2022-10-06 17:53:35 +02:00
|
|
|
contextStr = Tr::tr("Enter certificate password");
|
2016-12-22 17:55:17 +01:00
|
|
|
|
|
|
|
|
contextStr += extraContextStr.isEmpty() ? QStringLiteral(":") :
|
|
|
|
|
QStringLiteral(" (%1):").arg(extraContextStr);
|
|
|
|
|
inputContextlabel->setText(contextStr);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
QString PasswordInputDialog::getPassword(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, bool *ok, QWidget *parent)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
std::unique_ptr<PasswordInputDialog> dlg(new PasswordInputDialog(context, callback,
|
|
|
|
|
extraContextStr, parent));
|
|
|
|
|
bool isAccepted = dlg->exec() == QDialog::Accepted;
|
|
|
|
|
if (ok)
|
|
|
|
|
*ok = isAccepted;
|
|
|
|
|
return isAccepted ? dlg->inputEdit->text() : "";
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 18:40:29 +02:00
|
|
|
|
|
|
|
|
// AndroidBuildApkStepFactory
|
|
|
|
|
|
|
|
|
|
AndroidBuildApkStepFactory::AndroidBuildApkStepFactory()
|
|
|
|
|
{
|
2018-12-05 13:00:36 +01:00
|
|
|
registerStep<AndroidBuildApkStep>(Constants::ANDROID_BUILD_APK_ID);
|
2018-07-02 18:40:29 +02:00
|
|
|
setSupportedDeviceType(Constants::ANDROID_DEVICE_TYPE);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
2022-10-06 17:53:35 +02:00
|
|
|
setDisplayName(Tr::tr("Build Android APK"));
|
2018-07-02 18:40:29 +02:00
|
|
|
setRepeatable(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2014-06-25 15:42:11 +02:00
|
|
|
} // namespace Android
|