2013-09-17 18:24:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-09-17 18:24:57 +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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-09-17 18:24:57 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-09-17 18:24:57 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-09-17 18:24:57 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androiddeployqtstep.h"
|
|
|
|
|
#include "androiddeployqtwidget.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "androidqtsupport.h"
|
2013-09-17 18:24:57 +02:00
|
|
|
#include "certificatesmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "javaparser.h"
|
|
|
|
|
#include "androidmanager.h"
|
2013-11-06 13:06:10 +01:00
|
|
|
#include "androidconstants.h"
|
2014-08-08 20:03:47 +03:00
|
|
|
#include "androidglobal.h"
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/messagemanager.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2013-09-17 18:24:57 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
using namespace Android;
|
|
|
|
|
using namespace Android::Internal;
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
const QLatin1String UninstallPreviousPackageKey("UninstallPreviousPackage");
|
2013-09-17 18:24:57 +02:00
|
|
|
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");
|
2014-06-25 15:42:11 +02:00
|
|
|
const QLatin1String InstallFailedInconsistentCertificatesString("INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES");
|
2015-04-16 15:35:02 +02:00
|
|
|
const QLatin1String InstallFailedInconsistentCertificatesString2("INSTALL_FAILED_UPDATE_INCOMPATIBLE");
|
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>();
|
|
|
|
|
return QList<Core::Id>() << AndroidDeployQtStep::Id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
QString AndroidDeployQtStepFactory::displayNameForId(Core::Id id) const
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
|
if (id == AndroidDeployQtStep::Id)
|
|
|
|
|
return tr("Deploy to Android device or emulator");
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
bool AndroidDeployQtStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
|
return availableCreationIds(parent).contains(id);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::create(ProjectExplorer::BuildStepList *parent, Core::Id id)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
|
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)
|
2014-11-26 12:19:46 +01:00
|
|
|
: ProjectExplorer::BuildStep(parent, Id)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AndroidDeployQtStep::AndroidDeployQtStep(ProjectExplorer::BuildStepList *parent,
|
|
|
|
|
AndroidDeployQtStep *other)
|
2014-11-26 12:19:46 +01:00
|
|
|
: ProjectExplorer::BuildStep(parent, other)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
|
ctor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::ctor()
|
|
|
|
|
{
|
2014-10-03 10:18:14 +03:00
|
|
|
m_uninstallPreviousPackage = QtSupport::QtKitInformation::qtVersion(target()->kit())->qtVersion() < QtSupport::QtVersionNumber(5, 4, 0);
|
2014-06-25 15:42:11 +02:00
|
|
|
m_uninstallPreviousPackageRun = false;
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
//: AndroidDeployQtStep default display name
|
|
|
|
|
setDefaultDisplayName(tr("Deploy to Android device"));
|
2014-11-26 12:19:46 +01:00
|
|
|
|
|
|
|
|
connect(this, &AndroidDeployQtStep::askForUninstall,
|
|
|
|
|
this, &AndroidDeployQtStep::slotAskForUninstall,
|
|
|
|
|
Qt::BlockingQueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(this, &AndroidDeployQtStep::setSerialNumber,
|
|
|
|
|
this, &AndroidDeployQtStep::slotSetSerialNumber);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::init()
|
|
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
m_androiddeployqtArgs.clear();
|
|
|
|
|
|
2014-06-24 16:47:10 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2014-11-17 16:22:28 +01:00
|
|
|
|
|
|
|
|
AndroidBuildApkStep *androidBuildApkStep
|
|
|
|
|
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target()->activeBuildConfiguration());
|
|
|
|
|
if (!androidBuildApkStep) {
|
|
|
|
|
emit addOutput(tr("Cannot find the android build step."), ErrorOutput);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
int deviceAPILevel = AndroidManager::minimumSDK(target());
|
2014-11-17 16:22:28 +01:00
|
|
|
AndroidConfigurations::Options options = AndroidConfigurations::None;
|
|
|
|
|
if (androidBuildApkStep->deployAction() == AndroidBuildApkStep::DebugDeployment)
|
|
|
|
|
options = AndroidConfigurations::FilterAndroid5;
|
2015-04-23 16:25:44 +02:00
|
|
|
AndroidDeviceInfo info = AndroidConfigurations::showDeviceDialog(project(), deviceAPILevel, m_targetArch, options);
|
|
|
|
|
if (info.serialNumber.isEmpty() && info.avdname.isEmpty()) // aborted
|
2013-09-17 18:24:57 +02:00
|
|
|
return false;
|
|
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
m_avdName = info.avdname;
|
|
|
|
|
m_serialNumber = info.serialNumber;
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
AndroidManager::setDeviceSerialNumber(target(), m_serialNumber);
|
2013-09-17 18:24:57 +02:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
ProjectExplorer::BuildConfiguration *bc = target()->activeBuildConfiguration();
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
|
|
|
|
|
if (!version)
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
m_uninstallPreviousPackageRun = m_uninstallPreviousPackage;
|
|
|
|
|
if (m_uninstallPreviousPackageRun)
|
2014-10-24 17:53:05 +02:00
|
|
|
m_manifestName = AndroidManager::manifestPath(target());
|
2014-11-26 12:19:46 +01:00
|
|
|
|
2014-08-08 20:03:47 +03:00
|
|
|
m_useAndroiddeployqt = version->qtVersion() >= QtSupport::QtVersionNumber(5, 4, 0);
|
|
|
|
|
if (m_useAndroiddeployqt) {
|
|
|
|
|
Utils::FileName tmp = AndroidManager::androidQtSupport(target())->androiddeployqtPath(target());
|
|
|
|
|
if (tmp.isEmpty()) {
|
|
|
|
|
emit addOutput(tr("Cannot find the androiddeployqt tool."), ErrorOutput);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
m_command = tmp.toString();
|
|
|
|
|
m_workingDirectory = bc->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY)).toString();
|
2014-08-08 20:03:47 +03:00
|
|
|
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--verbose"));
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--output"));
|
2014-11-26 12:19:46 +01:00
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, m_workingDirectory);
|
2014-08-08 20:03:47 +03:00
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--no-build"));
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--input"));
|
|
|
|
|
tmp = AndroidManager::androidQtSupport(target())->androiddeployJsonPath(target());
|
|
|
|
|
if (tmp.isEmpty()) {
|
|
|
|
|
emit addOutput(tr("Cannot find the androiddeploy Json file."), ErrorOutput);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, tmp.toString());
|
|
|
|
|
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--deployment"));
|
|
|
|
|
switch (androidBuildApkStep->deployAction()) {
|
|
|
|
|
case AndroidBuildApkStep::MinistroDeployment:
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("ministro"));
|
|
|
|
|
break;
|
|
|
|
|
case AndroidBuildApkStep::DebugDeployment:
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("debug"));
|
|
|
|
|
break;
|
|
|
|
|
case AndroidBuildApkStep::BundleLibrariesDeployment:
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("bundled"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
if (androidBuildApkStep->useGradle())
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--gradle"));
|
2014-11-18 12:08:31 +01:00
|
|
|
|
|
|
|
|
if (androidBuildApkStep->signPackage()) {
|
|
|
|
|
// The androiddeployqt tool is not really written to do stand-alone installations.
|
|
|
|
|
// This hack forces it to use the correct filename for the apk file when installing
|
|
|
|
|
// as a temporary fix until androiddeployqt gets the support. Since the --sign is
|
|
|
|
|
// only used to get the correct file name of the apk, its parameters are ignored.
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("--sign"));
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("foo"));
|
|
|
|
|
Utils::QtcProcess::addArg(&m_androiddeployqtArgs, QLatin1String("bar"));
|
|
|
|
|
}
|
2014-08-08 20:03:47 +03:00
|
|
|
} else {
|
2014-09-16 14:25:34 +03:00
|
|
|
m_uninstallPreviousPackageRun = true;
|
2014-11-26 12:19:46 +01:00
|
|
|
m_command = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
2014-09-22 16:20:51 +03:00
|
|
|
m_apkPath = AndroidManager::androidQtSupport(target())->apkPath(target()).toString();
|
2014-11-26 12:19:46 +01:00
|
|
|
m_workingDirectory = bc->buildDirectory().toString();
|
2014-08-08 20:03:47 +03:00
|
|
|
}
|
2014-11-26 12:19:46 +01:00
|
|
|
m_environment = bc->environment();
|
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
m_buildDirectory = bc->buildDirectory().toString();
|
2014-11-26 12:19:46 +01:00
|
|
|
|
|
|
|
|
m_adbPath = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
2013-09-17 18:24:57 +02:00
|
|
|
|
2015-04-23 16:25:44 +02:00
|
|
|
if (AndroidConfigurations::currentConfig().findAvd(m_avdName).isEmpty())
|
2013-12-16 20:19:07 +01:00
|
|
|
AndroidConfigurations::currentConfig().startAVDAsync(m_avdName);
|
2013-09-17 18:24:57 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
AndroidDeployQtStep::DeployResult AndroidDeployQtStep::runDeploy(QFutureInterface<bool> &fi)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
m_installOk = true;
|
2014-11-26 12:19:46 +01:00
|
|
|
QString args;
|
2014-08-08 20:03:47 +03:00
|
|
|
if (m_useAndroiddeployqt) {
|
2014-11-26 12:19:46 +01:00
|
|
|
args = m_androiddeployqtArgs;
|
|
|
|
|
if (m_uninstallPreviousPackageRun)
|
|
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("--install"));
|
|
|
|
|
else
|
|
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("--reinstall"));
|
|
|
|
|
|
2014-08-08 20:03:47 +03:00
|
|
|
if (!m_serialNumber.isEmpty() && !m_serialNumber.startsWith(QLatin1String("????"))) {
|
2014-11-26 12:19:46 +01:00
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("--device"));
|
|
|
|
|
Utils::QtcProcess::addArg(&args, m_serialNumber);
|
2014-08-08 20:03:47 +03:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (m_uninstallPreviousPackageRun) {
|
2014-10-24 17:53:05 +02:00
|
|
|
const QString packageName = AndroidManager::packageName(m_manifestName);
|
2014-11-26 12:19:46 +01:00
|
|
|
if (packageName.isEmpty()) {
|
2014-10-24 17:53:05 +02:00
|
|
|
emit addOutput(tr("Cannot find the package name."), ErrorOutput);
|
2014-11-26 12:19:46 +01:00
|
|
|
return Failure;
|
2014-10-24 17:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit addOutput(tr("Uninstall previous package %1.").arg(packageName), MessageOutput);
|
2014-11-26 12:19:46 +01:00
|
|
|
runCommand(m_adbPath,
|
2014-08-08 20:03:47 +03:00
|
|
|
AndroidDeviceInfo::adbSelector(m_serialNumber)
|
2014-10-24 17:53:05 +02:00
|
|
|
<< QLatin1String("uninstall") << packageName);
|
2014-08-08 20:03:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (const QString &arg, AndroidDeviceInfo::adbSelector(m_serialNumber))
|
|
|
|
|
Utils::QtcProcess::addArg(&args, arg);
|
|
|
|
|
|
|
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("install"));
|
|
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("-r"));
|
|
|
|
|
Utils::QtcProcess::addArg(&args, m_apkPath);
|
|
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
m_process = new Utils::QtcProcess;
|
|
|
|
|
m_process->setCommand(m_command, args);
|
|
|
|
|
m_process->setWorkingDirectory(m_workingDirectory);
|
|
|
|
|
m_process->setEnvironment(m_environment);
|
|
|
|
|
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
m_process->setUseCtrlCStub(true);
|
|
|
|
|
|
|
|
|
|
connect(m_process, &Utils::QtcProcess::readyReadStandardOutput,
|
|
|
|
|
this, &AndroidDeployQtStep::processReadyReadStdOutput, Qt::DirectConnection);
|
|
|
|
|
connect(m_process, &Utils::QtcProcess::readyReadStandardError,
|
|
|
|
|
this, &AndroidDeployQtStep::processReadyReadStdError, Qt::DirectConnection);
|
|
|
|
|
|
|
|
|
|
m_process->start();
|
|
|
|
|
|
|
|
|
|
emit addOutput(tr("Starting: \"%1\" %2")
|
|
|
|
|
.arg(QDir::toNativeSeparators(m_command), args),
|
|
|
|
|
BuildStep::MessageOutput);
|
|
|
|
|
|
|
|
|
|
while (!m_process->waitForFinished(200)) {
|
|
|
|
|
if (fi.isCanceled()) {
|
|
|
|
|
m_process->kill();
|
|
|
|
|
m_process->waitForFinished();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString line = QString::fromLocal8Bit(m_process->readAllStandardError());
|
|
|
|
|
if (!line.isEmpty())
|
|
|
|
|
stdError(line);
|
|
|
|
|
|
|
|
|
|
line = QString::fromLocal8Bit(m_process->readAllStandardOutput());
|
|
|
|
|
if (!line.isEmpty())
|
|
|
|
|
stdOutput(line);
|
|
|
|
|
|
|
|
|
|
QProcess::ExitStatus exitStatus = m_process->exitStatus();
|
|
|
|
|
int exitCode = m_process->exitCode();
|
|
|
|
|
delete m_process;
|
|
|
|
|
m_process = 0;
|
|
|
|
|
|
|
|
|
|
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
|
|
|
|
|
emit addOutput(tr("The process \"%1\" exited normally.").arg(m_command),
|
|
|
|
|
BuildStep::MessageOutput);
|
|
|
|
|
} else if (exitStatus == QProcess::NormalExit) {
|
|
|
|
|
emit addOutput(tr("The process \"%1\" exited with code %2.")
|
|
|
|
|
.arg(m_command, QString::number(exitCode)),
|
|
|
|
|
BuildStep::ErrorMessageOutput);
|
|
|
|
|
} else {
|
|
|
|
|
emit addOutput(tr("The process \"%1\" crashed.").arg(m_command), BuildStep::ErrorMessageOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
|
|
|
|
|
if (!m_installOk) {
|
|
|
|
|
if (!m_uninstallPreviousPackageRun)
|
|
|
|
|
return AskUinstall;
|
|
|
|
|
else
|
|
|
|
|
return Failure;
|
|
|
|
|
}
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
return Failure;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::slotAskForUninstall()
|
|
|
|
|
{
|
|
|
|
|
int button = QMessageBox::critical(0, tr("Install failed"),
|
|
|
|
|
tr("Another application with the same package id but signed with "
|
|
|
|
|
"different certificate already exists.\n"
|
|
|
|
|
"Do you want to uninstall the existing package?"),
|
|
|
|
|
QMessageBox::Yes, QMessageBox::No);
|
|
|
|
|
m_askForUinstall = button == QMessageBox::Yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::slotSetSerialNumber(const QString &serialNumber)
|
|
|
|
|
{
|
|
|
|
|
AndroidManager::setDeviceSerialNumber(target(), serialNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
|
|
|
|
|
{
|
|
|
|
|
if (!m_avdName.isEmpty()) {
|
2015-04-23 16:25:44 +02:00
|
|
|
QString serialNumber = AndroidConfigurations::currentConfig().waitForAvd(m_avdName, fi);
|
2014-11-26 12:19:46 +01:00
|
|
|
if (serialNumber.isEmpty()) {
|
|
|
|
|
fi.reportResult(false);
|
|
|
|
|
emit finished();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_serialNumber = serialNumber;
|
|
|
|
|
emit setSerialNumber(serialNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeployResult returnValue = runDeploy(fi);
|
|
|
|
|
if (returnValue == AskUinstall) {
|
|
|
|
|
emit askForUninstall();
|
|
|
|
|
if (m_askForUinstall) {
|
|
|
|
|
m_uninstallPreviousPackageRun = true;
|
|
|
|
|
returnValue = runDeploy(fi);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-17 18:24:57 +02:00
|
|
|
|
|
|
|
|
emit addOutput(tr("Pulling files necessary for debugging."), MessageOutput);
|
2015-03-27 11:38:34 +01:00
|
|
|
|
2015-04-22 14:10:12 +02:00
|
|
|
const QString remoteAppProcessFile = systemAppProcessFilePath();
|
2015-03-27 11:38:34 +01:00
|
|
|
QString localAppProcessFile = QString::fromLatin1("%1/app_process").arg(m_buildDirectory);
|
2014-11-26 12:19:46 +01:00
|
|
|
runCommand(m_adbPath,
|
2013-09-17 18:24:57 +02:00
|
|
|
AndroidDeviceInfo::adbSelector(m_serialNumber)
|
2015-04-22 14:10:12 +02:00
|
|
|
<< QLatin1String("pull") << remoteAppProcessFile
|
2015-03-27 11:38:34 +01:00
|
|
|
<< localAppProcessFile);
|
|
|
|
|
if (!QFileInfo::exists(localAppProcessFile)) {
|
2015-04-22 14:10:12 +02:00
|
|
|
returnValue = Failure;
|
|
|
|
|
emit addOutput(tr("Package deploy: Failed to pull \"%1\" to \"%2\".")
|
|
|
|
|
.arg(remoteAppProcessFile).arg(localAppProcessFile), ErrorMessageOutput);
|
2015-03-27 11:38:34 +01:00
|
|
|
}
|
2014-11-26 12:19:46 +01:00
|
|
|
runCommand(m_adbPath,
|
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));
|
2014-11-26 12:19:46 +01:00
|
|
|
|
|
|
|
|
fi.reportResult(returnValue == Success ? true : false);
|
|
|
|
|
fi.reportFinished();
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::runCommand(const QString &program, const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
QProcess buildProc;
|
2014-08-23 01:19:53 +02:00
|
|
|
emit addOutput(tr("Package deploy: Running command \"%1 %2\".").arg(program).arg(arguments.join(QLatin1Char(' '))), BuildStep::MessageOutput);
|
2013-09-17 18:24:57 +02:00
|
|
|
buildProc.start(program, arguments);
|
|
|
|
|
if (!buildProc.waitForStarted()) {
|
2014-06-25 15:42:11 +02:00
|
|
|
emit addOutput(tr("Packaging error: Could not start command \"%1 %2\". Reason: %3")
|
2014-08-23 01:19:53 +02:00
|
|
|
.arg(program).arg(arguments.join(QLatin1Char(' '))).arg(buildProc.errorString()), BuildStep::ErrorMessageOutput);
|
2013-09-17 18:24:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!buildProc.waitForFinished(2 * 60 * 1000)
|
|
|
|
|
|| buildProc.error() != QProcess::UnknownError
|
|
|
|
|
|| buildProc.exitCode() != 0) {
|
2015-01-05 14:21:59 +01:00
|
|
|
QString mainMessage = tr("Packaging error: Command \"%1 %2\" failed.")
|
2014-08-23 01:19:53 +02:00
|
|
|
.arg(program).arg(arguments.join(QLatin1Char(' ')));
|
2013-09-17 18:24:57 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-22 14:10:12 +02:00
|
|
|
QString AndroidDeployQtStep::systemAppProcessFilePath() const
|
|
|
|
|
{
|
|
|
|
|
QProcess proc;
|
|
|
|
|
const QStringList args =
|
|
|
|
|
QStringList() << QLatin1String("shell")
|
|
|
|
|
<< QLatin1String("readlink -f -s /system/bin/app_process");
|
|
|
|
|
proc.start(m_adbPath, args);
|
|
|
|
|
proc.waitForFinished();
|
|
|
|
|
return QString::fromUtf8(proc.readAll()).trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
ProjectExplorer::BuildStepConfigWidget *AndroidDeployQtStep::createConfigWidget()
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
return new AndroidDeployQtWidget(this);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
void AndroidDeployQtStep::processReadyReadStdOutput()
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-11-26 12:19:46 +01:00
|
|
|
m_process->setReadChannel(QProcess::StandardOutput);
|
|
|
|
|
while (m_process->canReadLine()) {
|
|
|
|
|
QString line = QString::fromLocal8Bit(m_process->readLine());
|
|
|
|
|
stdOutput(line);
|
|
|
|
|
}
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
void AndroidDeployQtStep::stdOutput(const QString &line)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2015-04-16 15:35:02 +02:00
|
|
|
if (line.contains(InstallFailedInconsistentCertificatesString)
|
|
|
|
|
|| line.contains(InstallFailedInconsistentCertificatesString2))
|
2014-06-25 15:42:11 +02:00
|
|
|
m_installOk = false;
|
2014-11-26 12:19:46 +01:00
|
|
|
emit addOutput(line, BuildStep::NormalOutput, BuildStep::DontAppendNewline);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-26 12:19:46 +01:00
|
|
|
void AndroidDeployQtStep::processReadyReadStdError()
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-11-26 12:19:46 +01:00
|
|
|
m_process->setReadChannel(QProcess::StandardError);
|
|
|
|
|
while (m_process->canReadLine()) {
|
|
|
|
|
QString line = QString::fromLocal8Bit(m_process->readLine());
|
|
|
|
|
stdError(line);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
2014-11-26 12:19:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidDeployQtStep::stdError(const QString &line)
|
|
|
|
|
{
|
2015-04-16 15:35:02 +02:00
|
|
|
if (line.contains(InstallFailedInconsistentCertificatesString)
|
|
|
|
|
|| line.contains(InstallFailedInconsistentCertificatesString2))
|
2014-11-26 12:19:46 +01:00
|
|
|
m_installOk = false;
|
|
|
|
|
emit addOutput(line, BuildStep::ErrorOutput, BuildStep::DontAppendNewline);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidDeployQtStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2014-10-03 10:18:14 +03:00
|
|
|
m_uninstallPreviousPackage = map.value(UninstallPreviousPackageKey, m_uninstallPreviousPackage).toBool();
|
2013-09-17 18:24:57 +02:00
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidDeployQtStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectExplorer::BuildStep::toMap();
|
2014-06-25 15:42:11 +02:00
|
|
|
map.insert(UninstallPreviousPackageKey, m_uninstallPreviousPackage);
|
2013-09-17 18:24:57 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
void AndroidDeployQtStep::setUninstallPreviousPackage(bool uninstall)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
m_uninstallPreviousPackage = uninstall;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-13 16:14:27 +01:00
|
|
|
bool AndroidDeployQtStep::runInGuiThread() const
|
|
|
|
|
{
|
2014-11-26 12:19:46 +01:00
|
|
|
return false;
|
2013-11-13 16:14:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-16 14:25:34 +03:00
|
|
|
AndroidDeployQtStep::UninstallType AndroidDeployQtStep::uninstallPreviousPackage()
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-09-16 14:25:34 +03:00
|
|
|
if (QtSupport::QtKitInformation::qtVersion(target()->kit())->qtVersion() < QtSupport::QtVersionNumber(5, 4, 0))
|
|
|
|
|
return ForceUnintall;
|
|
|
|
|
return m_uninstallPreviousPackage ? Uninstall : Keep;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|