2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androidbuildapkstep.h"
|
|
|
|
|
#include "androidbuildapkwidget.h"
|
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
|
#include "androidconstants.h"
|
|
|
|
|
#include "androidmanager.h"
|
2017-08-18 08:22:34 +02:00
|
|
|
#include "androidsdkmanager.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "androidqtsupport.h"
|
|
|
|
|
#include "certificatesmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "javaparser.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
2017-12-06 10:27:27 +01:00
|
|
|
#include <utils/algorithm.h>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
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>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
using namespace ProjectExplorer;
|
2018-06-18 11:49:14 +02:00
|
|
|
namespace {
|
|
|
|
|
Q_LOGGING_CATEGORY(buildapkstepLog, "qtc.android.build.androidbuildapkstep")
|
|
|
|
|
}
|
2018-06-13 13:51:41 +02:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
namespace Android {
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2017-04-12 14:08:17 +02:00
|
|
|
const QVersionNumber gradleScriptRevokedSdkVersion(25, 3, 0);
|
2017-06-12 14:23:06 +02:00
|
|
|
const char KeystoreLocationKey[] = "KeystoreLocation";
|
|
|
|
|
const char BuildTargetSdkKey[] = "BuildTargetSdk";
|
|
|
|
|
const char VerboseOutputKey[] = "VerboseOutput";
|
2017-09-27 18:24:04 -07:00
|
|
|
const char UseMinistroKey[] = "UseMinistro";
|
2016-12-22 17:55:17 +01:00
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
static void setupProcessParameters(ProcessParameters *pp,
|
|
|
|
|
BuildConfiguration *bc,
|
|
|
|
|
const QStringList &arguments,
|
|
|
|
|
const QString &command)
|
|
|
|
|
{
|
|
|
|
|
pp->setMacroExpander(bc->macroExpander());
|
|
|
|
|
pp->setWorkingDirectory(bc->buildDirectory().toString());
|
|
|
|
|
Utils::Environment env = bc->environment();
|
|
|
|
|
pp->setEnvironment(env);
|
|
|
|
|
pp->setCommand(command);
|
|
|
|
|
pp->setArguments(Utils::QtcProcess::joinArgs(arguments));
|
|
|
|
|
pp->resolveAll();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 13:42:07 +02:00
|
|
|
class PasswordInputDialog : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
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);
|
|
|
|
|
QLabel *warningIcon = new QLabel(this);
|
|
|
|
|
QLabel *warningLabel = new QLabel(this);
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
|
|
|
this);
|
|
|
|
|
};
|
|
|
|
|
|
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup
This follow the rough pattern of recent *RunConfigurationFactory changes
for build and deploy configurations.
- Collapse the two lines of constructors similar to what
890c1906e6fb2ec did for RunConfigurations
* Deploy* was purely mechanical
* Build* ctors are split in connects() in the ctor body
to create "empty shell for clone" etc
and build step additions in initialize() functions which
are only used in the create() case.
-- Allows to collapse the shared 'ctor()' functions, too.
- Move FooBuildConfigurationFactory::create() implementations
to FooBuildConfiguration() constructor. That was a strange
and unneeded ping-pong between factories and objects, and
furthermore allows one level less of indirection (and for a
later, left out here, some reduction of the
FooBuildConfiguration interfaces that were only used to
accommodate the *Factory::create() functions.
- Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(),
but there wasn't one in the base classses. Have one there.
- Most canHandle() functions were checking simple restrictions on
e.g. project or target types, specify those by setters in the
constructors instead and check them in the base canHandle()
- clone() is generally replaced by a creation of a "shell object"
and a fromMap(source->toMap()), implemented in the base, there
are two cases left for Android and Qbs that needed(?) some extra
polish
- generally use canHandle() in base implementation, instead
of doing that in all Derived::canFoo()
- as a result, canCreate/create/canClone/clone reimplementations
are not needed anymore, keep the base implementation for
now (could be inlined into their only users later), but
de-virtualize them.
- Combine Ios{Preset,DSym}BuildStepFactory. There was only one
'dsym' build step they could create.
- Split the 'mangled' id into the ProjectConfiguration subtype
specific constant identifier, and a QString extraId() bit.
Only maintain the mangled id in saved settings.
- Make ProjectConfiguration::m_id a constant member, adapt
all constructors of derived classe.
Not done in this patch:
- Finish possible cosmetic changes on top
- Add a way to specify restrictions to supported Qt versions
(used in Android/Ios), as the base implementation does not
depend on the qtsupport plugin
- Combine the QList<X> availableFoo() + createFoo(X) function
pairs to somthing like a direct
QList<struct { X; std::function<X()>; }> fooCreators()
to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base)
pingpong
- Remove the *Factories from the global object pool
- Do something about priority(). Falling back to plain
qmake in android+qmake setup is not helpful.
Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:28:40 +01:00
|
|
|
AndroidBuildApkStep::AndroidBuildApkStep(ProjectExplorer::BuildStepList *parent, Core::Id id)
|
2014-06-25 15:42:11 +02:00
|
|
|
: ProjectExplorer::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
|
|
|
{
|
|
|
|
|
//: AndroidBuildApkStep default display name
|
|
|
|
|
setDefaultDisplayName(tr("Build Android APK"));
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-13 12:19:35 +01:00
|
|
|
bool AndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::BuildConfiguration *bc = buildConfiguration();
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
qCDebug(buildapkstepLog) << "Init failed. Keystore/Certificate password verification failed.";
|
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
|
|
|
|
2015-02-20 15:10:56 +01:00
|
|
|
if (bc->buildType() != ProjectExplorer::BuildConfiguration::Release)
|
|
|
|
|
emit addOutput(tr("Warning: Signing a debug or profile package."),
|
2017-01-12 10:59:12 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
|
|
|
|
|
if (!version)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-07-31 13:36:18 +02:00
|
|
|
const QVersionNumber sdkToolsVersion = AndroidConfigurations::currentConfig().sdkToolsVersion();
|
2017-09-08 23:36:13 +02:00
|
|
|
if (sdkToolsVersion >= gradleScriptRevokedSdkVersion) {
|
|
|
|
|
if (!version->sourcePath().appendPath("src/3rdparty/gradle").exists()) {
|
|
|
|
|
emit addOutput(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"),
|
|
|
|
|
OutputFormat::Stderr);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (version->qtVersion() < QtSupport::QtVersionNumber(5, 4, 0)) {
|
2017-12-27 13:56:54 +01:00
|
|
|
emit addOutput(tr("The minimum Qt version required for Gradle build to work is %1. "
|
2017-09-08 23:36:13 +02:00
|
|
|
"It is recommended to install the latest Qt version.")
|
|
|
|
|
.arg("5.4.0"), OutputFormat::Stderr);
|
2017-04-12 14:08:17 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 18:46:12 +02:00
|
|
|
int minSDKForKit = AndroidManager::minimumSDK(target()->kit());
|
|
|
|
|
if (AndroidManager::minimumSDK(target()) < minSDKForKit) {
|
|
|
|
|
emit addOutput(tr("The API level set for the APK is less than the minimum required by the kit."
|
2017-01-12 10:59:12 +01:00
|
|
|
"\nThe minimum API level required by the kit is %1.").arg(minSDKForKit), OutputFormat::Stderr);
|
2016-08-17 18:46:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
JavaParser *parser = new JavaParser;
|
2017-12-06 10:27:27 +01:00
|
|
|
parser->setProjectFileList(Utils::transform(target()->project()->files(ProjectExplorer::Project::AllFiles),
|
|
|
|
|
&Utils::FileName::toString));
|
2018-05-09 09:55:37 +02:00
|
|
|
|
2018-05-31 10:51:37 +02:00
|
|
|
AndroidQtSupport *qtSupport = AndroidManager::androidQtSupport(target());
|
|
|
|
|
QFileInfo sourceDirInfo(qtSupport->targetDataItem(Constants::AndroidPackageSourceDir, target()));
|
|
|
|
|
parser->setSourceDirectory(Utils::FileName::fromString(sourceDirInfo.canonicalFilePath()));
|
2017-06-12 14:23:06 +02:00
|
|
|
parser->setBuildDirectory(Utils::FileName::fromString(bc->buildDirectory().appendPath(Constants::ANDROID_BUILDDIRECTORY).toString()));
|
2014-06-25 15:42:11 +02:00
|
|
|
setOutputParser(parser);
|
|
|
|
|
|
|
|
|
|
m_openPackageLocationForRun = m_openPackageLocation;
|
2018-05-31 10:51:37 +02:00
|
|
|
m_apkPath = qtSupport->apkPath(target()).toString();
|
2018-06-18 11:49:14 +02:00
|
|
|
qCDebug(buildapkstepLog) << "APK path:" << m_apkPath;
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
if (!AbstractProcessStep::init(earlierSteps))
|
2014-06-25 15:42:11 +02:00
|
|
|
return false;
|
|
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
QString command = version->qmakeProperty("QT_HOST_BINS");
|
|
|
|
|
if (!command.endsWith('/'))
|
|
|
|
|
command += '/';
|
|
|
|
|
command += "androiddeployqt";
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
command += ".exe";
|
|
|
|
|
|
|
|
|
|
QString outputDir = bc->buildDirectory().appendPath(Constants::ANDROID_BUILDDIRECTORY).toString();
|
|
|
|
|
|
|
|
|
|
QString inputFile = AndroidManager::androidQtSupport(target())
|
|
|
|
|
->targetDataItem(Constants::AndroidDeploySettingsFile, target());
|
|
|
|
|
if (inputFile.isEmpty()) {
|
|
|
|
|
m_skipBuilding = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString buildTargetSdk = AndroidManager::buildTargetSDK(target());
|
|
|
|
|
if (buildTargetSdk.isEmpty()) {
|
|
|
|
|
emit addOutput(tr("Android build SDK not defined. Check Android settings."),
|
|
|
|
|
OutputFormat::Stderr);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList arguments = {"--input", inputFile,
|
|
|
|
|
"--output", outputDir,
|
|
|
|
|
"--android-platform", AndroidManager::buildTargetSDK(target()),
|
|
|
|
|
"--jdk", AndroidConfigurations::currentConfig().openJDKLocation().toString()};
|
|
|
|
|
|
|
|
|
|
if (m_verbose)
|
|
|
|
|
arguments << "--verbose";
|
|
|
|
|
|
|
|
|
|
arguments << "--gradle";
|
|
|
|
|
|
|
|
|
|
if (m_useMinistro)
|
|
|
|
|
arguments << "--deployment" << "ministro";
|
|
|
|
|
|
|
|
|
|
QStringList argumentsPasswordConcealed = arguments;
|
|
|
|
|
|
|
|
|
|
if (m_signPackage) {
|
|
|
|
|
arguments << "--sign" << m_keystorePath.toString() << m_certificateAlias
|
|
|
|
|
<< "--storepass" << m_keystorePasswd;
|
|
|
|
|
argumentsPasswordConcealed << "--sign" << "******"
|
|
|
|
|
<< "--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
|
|
|
|
|
if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0)) {
|
|
|
|
|
if (m_addDebugger || bc->buildType() == ProjectExplorer::BuildConfiguration::Debug)
|
|
|
|
|
arguments << "--gdbserver";
|
|
|
|
|
else
|
|
|
|
|
arguments << "--no-gdbserver";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ProcessParameters *pp = processParameters();
|
|
|
|
|
setupProcessParameters(pp, bc, arguments, command);
|
|
|
|
|
|
|
|
|
|
// Generate arguments with keystore password concealed
|
|
|
|
|
ProjectExplorer::ProcessParameters pp2;
|
|
|
|
|
setupProcessParameters(&pp2, bc, argumentsPasswordConcealed, command);
|
|
|
|
|
m_command = pp2.effectiveCommand();
|
|
|
|
|
m_argumentsPasswordConcealed = pp2.prettyArguments();
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::showInGraphicalShell()
|
|
|
|
|
{
|
2018-02-01 17:06:42 +01:00
|
|
|
Core::FileUtils::showInGraphicalShell(Core::ICore::mainWindow(), m_apkPath);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStepConfigWidget *AndroidBuildApkStep::createConfigWidget()
|
|
|
|
|
{
|
2018-06-13 18:25:46 +02:00
|
|
|
return new AndroidBuildApkInnerWidget(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)
|
|
|
|
|
QMetaObject::invokeMethod(this, "showInGraphicalShell", Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
bool AndroidBuildApkStep::verifyKeystorePassword()
|
|
|
|
|
{
|
2017-01-10 16:33:56 +01:00
|
|
|
if (!m_keystorePath.exists()) {
|
2017-09-08 14:20:43 +02:00
|
|
|
addOutput(tr("Cannot sign the package. Invalid keystore path (%1).")
|
2017-01-20 10:08:43 +02:00
|
|
|
.arg(m_keystorePath.toString()), OutputFormat::ErrorMessage);
|
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)) {
|
|
|
|
|
addOutput(tr("Cannot sign the package. Certificate alias %1 does not exist.")
|
2017-01-20 10:08:43 +02:00
|
|
|
.arg(m_certificateAlias), OutputFormat::ErrorMessage);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 13:51:41 +02:00
|
|
|
void AndroidBuildApkStep::run(QFutureInterface<bool> &fi)
|
|
|
|
|
{
|
|
|
|
|
if (m_skipBuilding) {
|
|
|
|
|
emit addOutput(tr("No application .pro file found, not building an APK."), BuildStep::OutputFormat::ErrorMessage);
|
|
|
|
|
reportRunResult(fi, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AbstractProcessStep::run(fi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::processStarted()
|
|
|
|
|
{
|
|
|
|
|
emit addOutput(tr("Starting: \"%1\" %2")
|
|
|
|
|
.arg(QDir::toNativeSeparators(m_command),
|
|
|
|
|
m_argumentsPasswordConcealed),
|
|
|
|
|
BuildStep::OutputFormat::NormalMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePath = Utils::FileName::fromString(map.value(KeystoreLocationKey).toString());
|
|
|
|
|
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();
|
2017-09-27 18:24:04 -07:00
|
|
|
m_useMinistro = map.value(UseMinistroKey).toBool();
|
2014-06-25 15:42:11 +02:00
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidBuildApkStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap();
|
|
|
|
|
map.insert(KeystoreLocationKey, m_keystorePath.toString());
|
|
|
|
|
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
|
|
|
|
|
map.insert(VerboseOutputKey, m_verbose);
|
2017-09-27 18:24:04 -07:00
|
|
|
map.insert(UseMinistroKey, m_useMinistro);
|
2014-06-25 15:42:11 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileName AndroidBuildApkStep::keystorePath()
|
|
|
|
|
{
|
|
|
|
|
return m_keystorePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidBuildApkStep::buildTargetSdk() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargetSdk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setBuildTargetSdk(const QString &sdk)
|
|
|
|
|
{
|
|
|
|
|
m_buildTargetSdk = sdk;
|
2017-09-08 23:36:13 +02:00
|
|
|
AndroidManager::updateGradleProperties(target());
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setKeystorePath(const Utils::FileName &path)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::openPackageLocation() const
|
|
|
|
|
{
|
|
|
|
|
return m_openPackageLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setOpenPackageLocation(bool open)
|
|
|
|
|
{
|
|
|
|
|
m_openPackageLocation = open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setVerboseOutput(bool verbose)
|
|
|
|
|
{
|
|
|
|
|
m_verbose = verbose;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 18:24:04 -07:00
|
|
|
bool AndroidBuildApkStep::useMinistro() const
|
|
|
|
|
{
|
|
|
|
|
return m_useMinistro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setUseMinistro(bool useMinistro)
|
|
|
|
|
{
|
|
|
|
|
m_useMinistro = useMinistro;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Utils::SynchronousProcess keytoolProc;
|
|
|
|
|
keytoolProc.setTimeoutS(30);
|
|
|
|
|
const Utils::SynchronousProcessResponse response
|
|
|
|
|
= keytoolProc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), params);
|
2017-01-11 09:29:37 +01:00
|
|
|
if (response.result > Utils::SynchronousProcessResponse::FinishedError)
|
2016-12-22 17:55:17 +01:00
|
|
|
QMessageBox::critical(0, tr("Error"), tr("Failed to run keytool."));
|
|
|
|
|
else
|
|
|
|
|
model = new CertificatesModel(response.stdOut(), this);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
warningIcon->setPixmap(Utils::Icons::WARNING.pixmap());
|
|
|
|
|
warningIcon->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
|
|
|
|
|
warningIcon->hide();
|
|
|
|
|
|
|
|
|
|
warningLabel->hide();
|
|
|
|
|
|
|
|
|
|
auto warningLayout = new QHBoxLayout;
|
|
|
|
|
warningLayout->addWidget(warningIcon);
|
|
|
|
|
warningLayout->addWidget(warningLabel);
|
|
|
|
|
|
|
|
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
mainLayout->addWidget(inputContextlabel);
|
|
|
|
|
mainLayout->addWidget(inputEdit);
|
|
|
|
|
mainLayout->addLayout(warningLayout);
|
|
|
|
|
mainLayout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
|
|
connect(inputEdit, &QLineEdit::textChanged,[this](const QString &text) {
|
|
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, [this]() {
|
|
|
|
|
if (verifyCallback(inputEdit->text())) {
|
|
|
|
|
accept(); // Dialog accepted.
|
|
|
|
|
} else {
|
|
|
|
|
warningIcon->show();
|
|
|
|
|
warningLabel->show();
|
|
|
|
|
warningLabel->setText(tr("Incorrect password."));
|
|
|
|
|
inputEdit->clear();
|
|
|
|
|
adjustSize();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
|
|
|
|
|
setWindowTitle(context == KeystorePassword ? tr("Keystore") : tr("Certificate"));
|
|
|
|
|
|
|
|
|
|
QString contextStr;
|
|
|
|
|
if (context == KeystorePassword)
|
|
|
|
|
contextStr = tr("Enter keystore password");
|
|
|
|
|
else
|
|
|
|
|
contextStr = tr("Enter certificate password");
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Android
|
2017-10-23 13:42:07 +02:00
|
|
|
|
|
|
|
|
#include "androidbuildapkstep.moc"
|