2013-09-17 18:24:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-09-17 18:24:57 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androiddeployqtstep.h"
|
|
|
|
|
#include "androiddeployqtwidget.h"
|
|
|
|
|
#include "certificatesmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "javaparser.h"
|
|
|
|
|
#include "androidmanager.h"
|
2013-11-06 13:06:10 +01:00
|
|
|
#include "androidconstants.h"
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/messagemanager.h>
|
|
|
|
|
#include <projectexplorer/buildsteplist.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-10-29 16:19:24 +01:00
|
|
|
#include <qmakeprojectmanager/qmakebuildconfiguration.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakeproject.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakenodes.h>
|
2013-09-17 18:24:57 +02:00
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
using namespace Android;
|
|
|
|
|
using namespace Android::Internal;
|
|
|
|
|
|
|
|
|
|
const QLatin1String DeployActionKey("Qt4ProjectManager.AndroidDeployQtStep.DeployQtAction");
|
|
|
|
|
const QLatin1String KeystoreLocationKey("KeystoreLocation");
|
|
|
|
|
const QLatin1String SignPackageKey("SignPackage");
|
|
|
|
|
const QLatin1String BuildTargetSdkKey("BuildTargetSdk");
|
|
|
|
|
const QLatin1String VerboseOutputKey("VerboseOutput");
|
|
|
|
|
const QLatin1String InputFile("InputFile");
|
2014-01-08 09:33:21 +01:00
|
|
|
const QLatin1String ProFilePathForInputFile("ProFilePathForInputFile");
|
2013-09-17 18:24:57 +02:00
|
|
|
const Core::Id AndroidDeployQtStep::Id("Qt4ProjectManager.AndroidDeployQtStep");
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
|
// AndroidDeployQtStepFactory
|
|
|
|
|
/////////////////
|
|
|
|
|
|
|
|
|
|
AndroidDeployQtStepFactory::AndroidDeployQtStepFactory(QObject *parent)
|
|
|
|
|
: IBuildStepFactory(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Core::Id> AndroidDeployQtStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY)
|
|
|
|
|
return QList<Core::Id>();
|
|
|
|
|
if (!AndroidManager::supportsAndroid(parent->target()))
|
|
|
|
|
return QList<Core::Id>();
|
|
|
|
|
if (parent->contains(AndroidDeployQtStep::Id))
|
|
|
|
|
return QList<Core::Id>();
|
2013-10-09 17:16:01 +02:00
|
|
|
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(parent->target()->kit());
|
|
|
|
|
if (!qtVersion || qtVersion->qtVersion() < QtSupport::QtVersionNumber(5, 2, 0))
|
|
|
|
|
return QList<Core::Id>();
|
2013-09-17 18:24:57 +02:00
|
|
|
return QList<Core::Id>() << AndroidDeployQtStep::Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidDeployQtStepFactory::displayNameForId(const Core::Id id) const
|
|
|
|
|
{
|
|
|
|
|
if (id == AndroidDeployQtStep::Id)
|
|
|
|
|
return tr("Deploy to Android device or emulator");
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, const Core::Id id) const
|
|
|
|
|
{
|
|
|
|
|
return availableCreationIds(parent).contains(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::create(ProjectExplorer::BuildStepList *parent, const Core::Id id)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(canCreate(parent, id));
|
|
|
|
|
Q_UNUSED(id);
|
|
|
|
|
return new AndroidDeployQtStep(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStepFactory::canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const
|
|
|
|
|
{
|
|
|
|
|
return canCreate(parent, ProjectExplorer::idFromMap(map));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(canRestore(parent, map));
|
|
|
|
|
AndroidDeployQtStep * const step = new AndroidDeployQtStep(parent);
|
|
|
|
|
if (!step->fromMap(map)) {
|
|
|
|
|
delete step;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStepFactory::canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const
|
|
|
|
|
{
|
|
|
|
|
return canCreate(parent, product->id());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(canClone(parent, product));
|
|
|
|
|
return new AndroidDeployQtStep(parent, static_cast<AndroidDeployQtStep *>(product));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
|
// AndroidDeployQtStep
|
|
|
|
|
/////////////////
|
|
|
|
|
|
|
|
|
|
AndroidDeployQtStep::AndroidDeployQtStep(ProjectExplorer::BuildStepList *parent)
|
|
|
|
|
: ProjectExplorer::AbstractProcessStep(parent, Id)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AndroidDeployQtStep::AndroidDeployQtStep(ProjectExplorer::BuildStepList *parent,
|
|
|
|
|
AndroidDeployQtStep *other)
|
|
|
|
|
: ProjectExplorer::AbstractProcessStep(parent, other)
|
|
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::ctor()
|
|
|
|
|
{
|
|
|
|
|
//: AndroidDeployQtStep default display name
|
|
|
|
|
setDefaultDisplayName(tr("Deploy to Android device"));
|
|
|
|
|
m_deployAction = BundleLibrariesDeployment;
|
|
|
|
|
m_signPackage = false;
|
|
|
|
|
m_openPackageLocation = false;
|
|
|
|
|
m_verbose = false;
|
|
|
|
|
|
|
|
|
|
// will be overwriten by settings if the user choose something different
|
2014-03-24 16:31:28 +01:00
|
|
|
SdkPlatform sdk = AndroidConfigurations::currentConfig().highestAndroidSdk();
|
|
|
|
|
if (sdk.apiLevel > 0)
|
|
|
|
|
m_buildTargetSdk = QLatin1String("android-") + QString::number(sdk.apiLevel);
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
connect(project(), SIGNAL(proFilesEvaluated()),
|
|
|
|
|
this, SLOT(updateInputFile()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::init()
|
|
|
|
|
{
|
|
|
|
|
if (AndroidManager::checkForQt51Files(project()->projectDirectory()))
|
2013-10-18 10:48:11 +02:00
|
|
|
emit addOutput(tr("Found old folder \"android\" in source directory. Qt 5.2 does not use that folder by default."), ErrorOutput);
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
m_targetArch = AndroidManager::targetArch(target());
|
2013-10-09 16:24:25 +02:00
|
|
|
if (m_targetArch.isEmpty()) {
|
|
|
|
|
emit addOutput(tr("No Android arch set by the .pro file."), ErrorOutput);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-09-17 18:24:57 +02:00
|
|
|
m_deviceAPILevel = AndroidManager::minimumSDK(target());
|
2013-12-16 20:19:07 +01:00
|
|
|
AndroidDeviceInfo info = AndroidConfigurations::showDeviceDialog(project(), m_deviceAPILevel, m_targetArch);
|
2013-09-17 18:24:57 +02:00
|
|
|
if (info.serialNumber.isEmpty()) // aborted
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (info.type == AndroidDeviceInfo::Emulator) {
|
|
|
|
|
m_avdName = info.serialNumber;
|
|
|
|
|
m_serialNumber.clear();
|
|
|
|
|
m_deviceAPILevel = info.sdk;
|
|
|
|
|
} else {
|
|
|
|
|
m_avdName.clear();
|
|
|
|
|
m_serialNumber = info.serialNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 14:00:45 +02:00
|
|
|
QmakeProjectManager::QmakeBuildConfiguration *bc
|
|
|
|
|
= static_cast<QmakeProjectManager::QmakeBuildConfiguration *>(target()->activeBuildConfiguration());
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
if (m_signPackage) {
|
|
|
|
|
// check keystore and certificate passwords
|
|
|
|
|
while (!AndroidManager::checkKeystorePassword(m_keystorePath.toString(), m_keystorePasswd)) {
|
|
|
|
|
if (!keystorePassword())
|
|
|
|
|
return false; // user canceled
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!AndroidManager::checkCertificatePassword(m_keystorePath.toString(), m_keystorePasswd, m_certificateAlias, m_certificatePasswd)) {
|
|
|
|
|
if (!certificatePassword())
|
|
|
|
|
return false; // user canceled
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((bc->qmakeBuildConfiguration() & QtSupport::BaseQtVersion::DebugBuild))
|
|
|
|
|
emit addOutput(tr("Warning: Signing a debug package."), BuildStep::ErrorMessageOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
|
|
|
|
|
if (!version)
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-01-08 09:33:21 +01:00
|
|
|
QmakeProjectManager::QmakeProject *pro = static_cast<QmakeProjectManager::QmakeProject *>(project());
|
2013-09-17 18:24:57 +02:00
|
|
|
JavaParser *parser = new JavaParser;
|
2014-01-08 09:33:21 +01:00
|
|
|
parser->setProjectFileList(pro->files(ProjectExplorer::Project::AllFiles));
|
2013-09-17 18:24:57 +02:00
|
|
|
setOutputParser(parser);
|
|
|
|
|
|
|
|
|
|
QString command = version->qmakeProperty("QT_HOST_BINS");
|
|
|
|
|
if (!command.endsWith(QLatin1Char('/')))
|
|
|
|
|
command += QLatin1Char('/');
|
|
|
|
|
command += QLatin1String("androiddeployqt");
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
command += QLatin1String(".exe");
|
|
|
|
|
|
|
|
|
|
QString deploymentMethod;
|
|
|
|
|
if (m_deployAction == MinistroDeployment)
|
|
|
|
|
deploymentMethod = QLatin1String("ministro");
|
|
|
|
|
else if (m_deployAction == DebugDeployment)
|
|
|
|
|
deploymentMethod = QLatin1String("debug");
|
|
|
|
|
else if (m_deployAction == BundleLibrariesDeployment)
|
|
|
|
|
deploymentMethod = QLatin1String("bundled");
|
|
|
|
|
|
2013-11-06 13:06:10 +01:00
|
|
|
QString outputDir = bc->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY)).toString();
|
2014-01-08 09:33:21 +01:00
|
|
|
const QmakeProjectManager::QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePathForInputFile);
|
|
|
|
|
if (!node) { // should never happen
|
|
|
|
|
emit addOutput(tr("Internal Error: Could not find .pro file."), BuildStep::ErrorMessageOutput);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString inputFile = node->singleVariableValue(QmakeProjectManager::AndroidDeploySettingsFile);
|
|
|
|
|
if (inputFile.isEmpty()) { // should never happen
|
2014-03-06 14:35:30 +01:00
|
|
|
emit addOutput(tr("Internal Error: Unknown Android deployment JSON file location."), BuildStep::ErrorMessageOutput);
|
2014-01-08 09:33:21 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QLatin1String("--input")
|
2014-01-08 09:33:21 +01:00
|
|
|
<< inputFile
|
2013-09-17 18:24:57 +02:00
|
|
|
<< QLatin1String("--output")
|
|
|
|
|
<< outputDir
|
|
|
|
|
<< QLatin1String("--deployment")
|
|
|
|
|
<< deploymentMethod
|
|
|
|
|
<< QLatin1String("--install")
|
|
|
|
|
<< QLatin1String("--ant")
|
2013-12-16 20:19:07 +01:00
|
|
|
<< AndroidConfigurations::currentConfig().antToolPath().toString()
|
2013-09-17 18:24:57 +02:00
|
|
|
<< QLatin1String("--android-platform")
|
|
|
|
|
<< m_buildTargetSdk
|
|
|
|
|
<< QLatin1String("--jdk")
|
2013-12-16 20:19:07 +01:00
|
|
|
<< AndroidConfigurations::currentConfig().openJDKLocation().toString();
|
2013-09-17 18:24:57 +02:00
|
|
|
|
2014-01-08 09:33:21 +01:00
|
|
|
parser->setSourceDirectory(Utils::FileName::fromString(node->singleVariableValue(QmakeProjectManager::AndroidPackageSourceDir)));
|
|
|
|
|
parser->setBuildDirectory(Utils::FileName::fromString(outputDir));
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
if (m_verbose)
|
|
|
|
|
arguments << QLatin1String("--verbose");
|
|
|
|
|
if (m_avdName.isEmpty())
|
|
|
|
|
arguments << QLatin1String("--device")
|
|
|
|
|
<< info.serialNumber;
|
|
|
|
|
|
|
|
|
|
if (m_signPackage) {
|
|
|
|
|
arguments << QLatin1String("--sign")
|
|
|
|
|
<< m_keystorePath.toString()
|
|
|
|
|
<< m_certificateAlias
|
|
|
|
|
<< QLatin1String("--storepass")
|
|
|
|
|
<< m_keystorePasswd;
|
|
|
|
|
if (!m_certificatePasswd.isEmpty())
|
|
|
|
|
arguments << QLatin1String("--keypass")
|
|
|
|
|
<< m_certificatePasswd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ProcessParameters *pp = processParameters();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
m_openPackageLocationForRun = m_openPackageLocation;
|
|
|
|
|
m_apkPath = AndroidManager::apkPath(target(), m_signPackage ? AndroidManager::ReleaseBuildSigned
|
|
|
|
|
: AndroidManager::DebugBuild).toString();
|
|
|
|
|
m_buildDirectory = bc->buildDirectory().toString();
|
|
|
|
|
|
|
|
|
|
bool result = AbstractProcessStep::init();
|
|
|
|
|
if (!result)
|
|
|
|
|
return false;
|
|
|
|
|
|
2013-12-16 20:19:07 +01:00
|
|
|
if (AndroidConfigurations::currentConfig().findAvd(m_deviceAPILevel, m_targetArch).isEmpty())
|
|
|
|
|
AndroidConfigurations::currentConfig().startAVDAsync(m_avdName);
|
2013-09-17 18:24:57 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
|
|
|
|
|
{
|
|
|
|
|
if (!m_avdName.isEmpty()) {
|
2013-12-16 20:19:07 +01:00
|
|
|
QString serialNumber = AndroidConfigurations::currentConfig().waitForAvd(m_deviceAPILevel, m_targetArch, fi);
|
2013-09-17 18:24:57 +02:00
|
|
|
if (serialNumber.isEmpty()) {
|
|
|
|
|
fi.reportResult(false);
|
2013-11-14 13:20:03 +01:00
|
|
|
emit finished();
|
2013-09-17 18:24:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_serialNumber = serialNumber;
|
|
|
|
|
QString args = processParameters()->arguments();
|
|
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("--device"));
|
|
|
|
|
Utils::QtcProcess::addArg(&args, serialNumber);
|
|
|
|
|
processParameters()->setArguments(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractProcessStep::run(fi);
|
|
|
|
|
|
|
|
|
|
emit addOutput(tr("Pulling files necessary for debugging."), MessageOutput);
|
2013-12-16 20:19:07 +01:00
|
|
|
runCommand(AndroidConfigurations::currentConfig().adbToolPath().toString(),
|
2013-09-17 18:24:57 +02:00
|
|
|
AndroidDeviceInfo::adbSelector(m_serialNumber)
|
|
|
|
|
<< QLatin1String("pull") << QLatin1String("/system/bin/app_process")
|
|
|
|
|
<< QString::fromLatin1("%1/app_process").arg(m_buildDirectory));
|
2013-12-16 20:19:07 +01:00
|
|
|
runCommand(AndroidConfigurations::currentConfig().adbToolPath().toString(),
|
2013-09-17 18:24:57 +02:00
|
|
|
AndroidDeviceInfo::adbSelector(m_serialNumber) << QLatin1String("pull")
|
|
|
|
|
<< QLatin1String("/system/lib/libc.so")
|
|
|
|
|
<< QString::fromLatin1("%1/libc.so").arg(m_buildDirectory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::runCommand(const QString &program, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
QProcess buildProc;
|
|
|
|
|
emit addOutput(tr("Package deploy: Running command '%1 %2'.").arg(program).arg(arguments.join(QLatin1String(" "))), BuildStep::MessageOutput);
|
|
|
|
|
buildProc.start(program, arguments);
|
|
|
|
|
if (!buildProc.waitForStarted()) {
|
|
|
|
|
emit addOutput(tr("Packaging error: Could not start command '%1 %2'. Reason: %3")
|
|
|
|
|
.arg(program).arg(arguments.join(QLatin1String(" "))).arg(buildProc.errorString()), BuildStep::ErrorMessageOutput);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!buildProc.waitForFinished(2 * 60 * 1000)
|
|
|
|
|
|| buildProc.error() != QProcess::UnknownError
|
|
|
|
|
|| buildProc.exitCode() != 0) {
|
|
|
|
|
QString mainMessage = tr("Packaging Error: Command '%1 %2' failed.")
|
|
|
|
|
.arg(program).arg(arguments.join(QLatin1String(" ")));
|
|
|
|
|
if (buildProc.error() != QProcess::UnknownError)
|
2013-10-17 14:52:10 +02:00
|
|
|
mainMessage += QLatin1Char(' ') + tr("Reason: %1").arg(buildProc.errorString());
|
2013-09-17 18:24:57 +02:00
|
|
|
else
|
|
|
|
|
mainMessage += tr("Exit code: %1").arg(buildProc.exitCode());
|
|
|
|
|
emit addOutput(mainMessage, BuildStep::ErrorMessageOutput);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::updateInputFile()
|
|
|
|
|
{
|
2013-10-29 14:22:31 +01:00
|
|
|
QmakeProjectManager::QmakeProject *pro = static_cast<QmakeProjectManager::QmakeProject *>(project());
|
|
|
|
|
QList<QmakeProjectManager::QmakeProFileNode *> nodes = pro->applicationProFiles();
|
2013-09-17 18:24:57 +02:00
|
|
|
|
2014-01-08 09:33:21 +01:00
|
|
|
const QmakeProjectManager::QmakeProFileNode *node = pro->rootQmakeProjectNode()->findProFileFor(m_proFilePathForInputFile);
|
|
|
|
|
if (!nodes.contains(const_cast<QmakeProjectManager::QmakeProFileNode *>(node))) {
|
|
|
|
|
if (!nodes.isEmpty())
|
|
|
|
|
m_proFilePathForInputFile = nodes.first()->path();
|
|
|
|
|
else
|
|
|
|
|
m_proFilePathForInputFile.clear();
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit inputFileChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::showInGraphicalShell()
|
|
|
|
|
{
|
|
|
|
|
Core::FileUtils::showInGraphicalShell(Core::ICore::instance()->mainWindow(), m_apkPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStepConfigWidget *AndroidDeployQtStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return new AndroidDeployQtWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::processFinished(int exitCode, QProcess::ExitStatus status)
|
|
|
|
|
{
|
|
|
|
|
AbstractProcessStep::processFinished(exitCode, status);
|
|
|
|
|
if (m_openPackageLocationForRun)
|
|
|
|
|
QMetaObject::invokeMethod(this, "showInGraphicalShell", Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_deployAction = AndroidDeployQtAction(map.value(QLatin1String(DeployActionKey),
|
|
|
|
|
BundleLibrariesDeployment).toInt());
|
|
|
|
|
m_keystorePath = Utils::FileName::fromString(map.value(KeystoreLocationKey).toString());
|
2013-11-20 17:55:24 +01:00
|
|
|
m_signPackage = false; // don't restore this
|
2013-09-17 18:24:57 +02:00
|
|
|
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
|
|
|
|
|
m_verbose = map.value(VerboseOutputKey).toBool();
|
2014-01-08 09:33:21 +01:00
|
|
|
m_proFilePathForInputFile = map.value(ProFilePathForInputFile).toString();
|
2013-09-17 18:24:57 +02:00
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidDeployQtStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectExplorer::BuildStep::toMap();
|
|
|
|
|
map.insert(QLatin1String(DeployActionKey), m_deployAction);
|
|
|
|
|
map.insert(KeystoreLocationKey, m_keystorePath.toString());
|
|
|
|
|
map.insert(SignPackageKey, m_signPackage);
|
|
|
|
|
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
|
|
|
|
|
map.insert(VerboseOutputKey, m_verbose);
|
2014-01-08 09:33:21 +01:00
|
|
|
map.insert(ProFilePathForInputFile, m_proFilePathForInputFile);
|
2013-09-17 18:24:57 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setBuildTargetSdk(const QString &sdk)
|
|
|
|
|
{
|
|
|
|
|
m_buildTargetSdk = sdk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidDeployQtStep::buildTargetSdk() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargetSdk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileName AndroidDeployQtStep::keystorePath()
|
|
|
|
|
{
|
|
|
|
|
return m_keystorePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AndroidDeployQtStep::AndroidDeployQtAction AndroidDeployQtStep::deployAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_deployAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setDeployAction(AndroidDeployQtStep::AndroidDeployQtAction deploy)
|
|
|
|
|
{
|
|
|
|
|
m_deployAction = deploy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setKeystorePath(const Utils::FileName &path)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePath = path;
|
|
|
|
|
m_certificatePasswd.clear();
|
|
|
|
|
m_keystorePasswd.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setKeystorePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setCertificateAlias(const QString &alias)
|
|
|
|
|
{
|
|
|
|
|
m_certificateAlias = alias;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setCertificatePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_certificatePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::signPackage() const
|
|
|
|
|
{
|
|
|
|
|
return m_signPackage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setSignPackage(bool b)
|
|
|
|
|
{
|
|
|
|
|
m_signPackage = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidDeployQtStep::deviceSerialNumber()
|
|
|
|
|
{
|
|
|
|
|
return m_serialNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::openPackageLocation() const
|
|
|
|
|
{
|
|
|
|
|
return m_openPackageLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setOpenPackageLocation(bool open)
|
|
|
|
|
{
|
|
|
|
|
m_openPackageLocation = open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::setVerboseOutput(bool verbose)
|
|
|
|
|
{
|
|
|
|
|
m_verbose = verbose;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 09:33:21 +01:00
|
|
|
QString AndroidDeployQtStep::proFilePathForInputFile() const
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-01-08 09:33:21 +01:00
|
|
|
return m_proFilePathForInputFile;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-08 09:33:21 +01:00
|
|
|
void AndroidDeployQtStep::setProFilePathForInputFile(const QString &path)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-01-08 09:33:21 +01:00
|
|
|
m_proFilePathForInputFile = path;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-13 16:14:27 +01:00
|
|
|
bool AndroidDeployQtStep::runInGuiThread() const
|
|
|
|
|
{
|
2013-11-14 13:20:03 +01:00
|
|
|
return true;
|
2013-11-13 16:14:27 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
bool AndroidDeployQtStep::verboseOutput() const
|
|
|
|
|
{
|
|
|
|
|
return m_verbose;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note this functions is duplicated between AndroidDeployStep and AndroidDeployQtStep
|
|
|
|
|
// since it does modify the stored password in AndroidDeployQtStep it's not easily
|
|
|
|
|
// extractable. The situation will clean itself up once AndroidDeployStep is no longer
|
|
|
|
|
// necessary
|
|
|
|
|
QAbstractItemModel *AndroidDeployQtStep::keystoreCertificates()
|
|
|
|
|
{
|
|
|
|
|
QString rawCerts;
|
|
|
|
|
QProcess keytoolProc;
|
|
|
|
|
while (!rawCerts.length() || !m_keystorePasswd.length()) {
|
|
|
|
|
QStringList params;
|
|
|
|
|
params << QLatin1String("-list") << QLatin1String("-v") << QLatin1String("-keystore") << m_keystorePath.toUserOutput() << QLatin1String("-storepass");
|
|
|
|
|
if (!m_keystorePasswd.length())
|
|
|
|
|
keystorePassword();
|
|
|
|
|
if (!m_keystorePasswd.length())
|
|
|
|
|
return 0;
|
|
|
|
|
params << m_keystorePasswd;
|
2014-04-03 11:02:48 +03:00
|
|
|
params << QLatin1String("-J-Duser.language=en");
|
2013-12-16 20:19:07 +01:00
|
|
|
keytoolProc.start(AndroidConfigurations::currentConfig().keytoolPath().toString(), params);
|
2013-09-17 18:24:57 +02:00
|
|
|
if (!keytoolProc.waitForStarted() || !keytoolProc.waitForFinished()) {
|
|
|
|
|
QMessageBox::critical(0, tr("Error"),
|
2013-10-09 16:37:42 +02:00
|
|
|
tr("Failed to run keytool."));
|
2013-09-17 18:24:57 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keytoolProc.exitCode()) {
|
|
|
|
|
QMessageBox::critical(0, tr("Error"),
|
2013-10-09 16:37:42 +02:00
|
|
|
tr("Invalid password."));
|
2013-09-17 18:24:57 +02:00
|
|
|
m_keystorePasswd.clear();
|
|
|
|
|
}
|
|
|
|
|
rawCerts = QString::fromLatin1(keytoolProc.readAllStandardOutput());
|
|
|
|
|
}
|
|
|
|
|
return new CertificatesModel(rawCerts, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::keystorePassword()
|
|
|
|
|
{
|
|
|
|
|
m_keystorePasswd.clear();
|
|
|
|
|
bool ok;
|
|
|
|
|
QString text = QInputDialog::getText(0, tr("Keystore"),
|
|
|
|
|
tr("Keystore password:"), QLineEdit::Password,
|
|
|
|
|
QString(), &ok);
|
|
|
|
|
if (ok && !text.isEmpty()) {
|
|
|
|
|
m_keystorePasswd = text;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::certificatePassword()
|
|
|
|
|
{
|
|
|
|
|
m_certificatePasswd.clear();
|
|
|
|
|
bool ok;
|
|
|
|
|
QString text = QInputDialog::getText(0, tr("Certificate"),
|
|
|
|
|
tr("Certificate password (%1):").arg(m_certificateAlias), QLineEdit::Password,
|
|
|
|
|
QString(), &ok);
|
|
|
|
|
if (ok && !text.isEmpty()) {
|
|
|
|
|
m_certificatePasswd = text;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|