Commit 12623107 authored by Daniel Teske's avatar Daniel Teske
Browse files

Android: androiddeployqt support



Change-Id: I37d706b4e11c6e1353a8ee73378b7d080080678c
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent 455d597a
......@@ -42,7 +42,10 @@ HEADERS += \
androidmanifesteditor.h \
androidmanifesteditorwidget.h \
androidmanifestdocument.h \
androiddevicedialog.h
androiddevicedialog.h \
androiddeployqtstep.h \
certificatesmodel.h \
androiddeployqtwidget.h
SOURCES += \
androidconfigurations.cpp \
......@@ -79,7 +82,10 @@ SOURCES += \
androidmanifesteditor.cpp \
androidmanifesteditorwidget.cpp \
androidmanifestdocument.cpp \
androiddevicedialog.cpp
androiddevicedialog.cpp \
androiddeployqtstep.cpp \
certificatesmodel.cpp \
androiddeployqtwidget.cpp
FORMS += \
androidsettingswidget.ui \
......@@ -87,7 +93,8 @@ FORMS += \
androiddeploystepwidget.ui \
addnewavddialog.ui \
androidcreatekeystorecertificate.ui \
androiddevicedialog.ui
androiddevicedialog.ui \
androiddeployqtwidget.ui
exists(../../shared/qbs/qbs.pro) {
HEADERS += \
......
......@@ -36,6 +36,8 @@ QtcPlugin {
"androidcreatekeystorecertificate.cpp",
"androidcreatekeystorecertificate.h",
"androidcreatekeystorecertificate.ui",
"androiddeployqtstep.cpp",
"androiddeployqtstep.h",
"androiddebugsupport.cpp",
"androiddebugsupport.h",
"androiddevicedialog.cpp",
......@@ -50,6 +52,9 @@ QtcPlugin {
"androiddeploystepwidget.cpp",
"androiddeploystepwidget.h",
"androiddeploystepwidget.ui",
"androiddeployqtwidget.cpp",
"androiddeployqtwidget.h",
"androiddeployqtwidget.ui",
"androiddevice.cpp",
"androiddevice.h",
"androiddevicefactory.cpp",
......@@ -103,6 +108,8 @@ QtcPlugin {
"androidsettingswidget.ui",
"androidtoolchain.cpp",
"androidtoolchain.h",
"certificatesmodel.cpp",
"certificatesmodel.h",
"javaparser.cpp",
"javaparser.h",
]
......
......@@ -715,6 +715,13 @@ QStringList AndroidConfigurations::getAbis(const QString &device) const
return result;
}
QString AndroidConfigurations::highestAvailableAndroidPlatform() const
{
if (m_availablePlatforms.isEmpty())
return QString();
return QLatin1String("android-") + QString::number(m_availablePlatforms.first());
}
QString AndroidConfigurations::bestMatch(const QString &targetAPI) const
{
int target = targetAPI.mid(targetAPI.lastIndexOf(QLatin1Char('-')) + 1).toInt();
......
......@@ -124,6 +124,7 @@ public:
AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi);
void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name
QString defaultDevice(ProjectExplorer::Project *project, const QString &abi) const; // serial number or avd name
QString highestAvailableAndroidPlatform() const;
public slots:
void clearDefaultDevices(ProjectExplorer::Project *project);
......
......@@ -32,6 +32,7 @@
#include "androiddeploystep.h"
#include "androidpackageinstallationstep.h"
#include "androidpackagecreationstep.h"
#include "androiddeployqtstep.h"
#include "androidmanager.h"
#include <projectexplorer/buildsteplist.h>
......@@ -76,9 +77,15 @@ DeployConfiguration *AndroidDeployConfigurationFactory::create(Target *parent, c
AndroidDeployConfiguration *dc = new AndroidDeployConfiguration(parent, id);
if (!dc)
return 0;
dc->stepList()->insertStep(0, new AndroidPackageInstallationStep(dc->stepList()));
dc->stepList()->insertStep(1, new AndroidPackageCreationStep(dc->stepList()));
dc->stepList()->insertStep(2, new AndroidDeployStep(dc->stepList()));
if (id == ANDROID_DEPLOYCONFIGURATION_ID) {
dc->stepList()->insertStep(0, new AndroidPackageInstallationStep(AndroidPackageInstallationStep::ProjectDirectory, dc->stepList()));
dc->stepList()->insertStep(1, new AndroidPackageCreationStep(dc->stepList()));
dc->stepList()->insertStep(2, new AndroidDeployStep(dc->stepList()));
} else {
dc->stepList()->insertStep(0, new AndroidPackageInstallationStep(AndroidPackageInstallationStep::BuildDirectory, dc->stepList()));
dc->stepList()->insertStep(1, new AndroidDeployQtStep(dc->stepList()));
}
return dc;
}
......@@ -104,7 +111,7 @@ bool AndroidDeployConfigurationFactory::canClone(Target *parent, DeployConfigura
{
if (!AndroidManager::supportsAndroid(parent))
return false;
return source->id() == ANDROID_DEPLOYCONFIGURATION_ID;
return canCreate(parent, source->id());
}
DeployConfiguration *AndroidDeployConfigurationFactory::clone(Target *parent, DeployConfiguration *source)
......@@ -128,16 +135,20 @@ QList<Core::Id> AndroidDeployConfigurationFactory::availableCreationIds(Target *
if (!tc || tc->targetAbi().osFlavor() != Abi::AndroidLinuxFlavor)
return ids;
if (QtSupport::QtKitInformation::qtVersion(parent->kit())->type() != QLatin1String(Constants::ANDROIDQT))
QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(parent->kit());
if (qt->type() != QLatin1String(Constants::ANDROIDQT))
return ids;
ids << Core::Id(ANDROID_DEPLOYCONFIGURATION_ID);
if (qt->qtVersion() < QtSupport::QtVersionNumber(5, 2, 0))
ids << Core::Id(ANDROID_DEPLOYCONFIGURATION_ID);
else
ids << Core::Id(ANDROID_DEPLOYCONFIGURATION2_ID);
return ids;
}
QString AndroidDeployConfigurationFactory::displayNameForId(const Core::Id id) const
{
if (id.name().startsWith(ANDROID_DC_PREFIX))
if (id.name().startsWith(ANDROID_DC_PREFIX)
|| id.name().startsWith(ANDROID_DC2_PREFIX))
return tr("Deploy on Android");
return QString();
}
......
......@@ -38,6 +38,10 @@ namespace Internal {
const char ANDROID_DEPLOYCONFIGURATION_ID[] = "Qt4ProjectManager.AndroidDeployConfiguration";
const char ANDROID_DC_PREFIX[] = "Qt4ProjectManager.AndroidDeployConfiguration.";
// Qt 5.2 has a new form of deployment
const char ANDROID_DEPLOYCONFIGURATION2_ID[] = "Qt4ProjectManager.AndroidDeployConfiguration2";
const char ANDROID_DC2_PREFIX[] = "Qt4ProjectManager.AndroidDeployConfiguration2.";
class AndroidDeployConfiguration : public ProjectExplorer::DeployConfiguration
{
Q_OBJECT
......
/**************************************************************************
**
** Copyright (c) 2013 BogDan Vatra <bog_dan_ro@yahoo.com>
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** 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"
#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>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4project.h>
#include <qt4projectmanager/qt4nodes.h>
#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");
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;
}
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
m_buildTargetSdk = AndroidConfigurations::instance().highestAvailableAndroidPlatform();
connect(project(), SIGNAL(proFilesEvaluated()),
this, SLOT(updateInputFile()));
}
bool AndroidDeployQtStep::init()
{
if (AndroidManager::checkForQt51Files(project()->projectDirectory()))
emit addOutput(tr("Found old android folder in source directory. Qt 5.2 does not use that folder by default."), ErrorOutput);
m_targetArch = AndroidManager::targetArch(target());
m_deviceAPILevel = AndroidManager::minimumSDK(target());
AndroidDeviceInfo info = AndroidConfigurations::instance().showDeviceDialog(project(), m_deviceAPILevel, m_targetArch);
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;
}
Qt4ProjectManager::Qt4BuildConfiguration *bc
= static_cast<Qt4ProjectManager::Qt4BuildConfiguration *>(target()->activeBuildConfiguration());
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;
ProjectExplorer::Project *project = target()->project();
JavaParser *parser = new JavaParser;
parser->setProjectFileList(project->files(ProjectExplorer::Project::AllFiles));
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");
QString outputDir = bc->buildDirectory().appendPath(QLatin1String("android")).toString();
QStringList arguments;
arguments << QLatin1String("--input")
<< m_inputFile
<< QLatin1String("--output")
<< outputDir
<< QLatin1String("--deployment")
<< deploymentMethod
<< QLatin1String("--install")
<< QLatin1String("--ant")
<< AndroidConfigurations::instance().antToolPath().toString()
<< QLatin1String("--android-platform")
<< m_buildTargetSdk
<< QLatin1String("--jdk")
<< AndroidConfigurations::instance().openJDKPath().toString();
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();
// Force output to english for the parsers. Do this here and not in the toolchain's
// addToEnvironment() to not screw up the users run environment.
env.set(QLatin1String("LC_ALL"), QLatin1String("C"));
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;
AndroidConfigurations::instance().startAVDAsync(m_avdName);
return true;
}
void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
{
if (!m_avdName.isEmpty()) {
QString serialNumber = AndroidConfigurations::instance().waitForAvd(m_deviceAPILevel, m_targetArch);
if (serialNumber.isEmpty()) {
fi.reportResult(false);
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);
runCommand(AndroidConfigurations::instance().adbToolPath().toString(),
AndroidDeviceInfo::adbSelector(m_serialNumber)
<< QLatin1String("pull") << QLatin1String("/system/bin/app_process")
<< QString::fromLatin1("%1/app_process").arg(m_buildDirectory));
runCommand(AndroidConfigurations::instance().adbToolPath().toString(),
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)
mainMessage += tr(" Reason: %1").arg(buildProc.errorString());
else
mainMessage += tr("Exit code: %1").arg(buildProc.exitCode());
emit addOutput(mainMessage, BuildStep::ErrorMessageOutput);
}
}
void AndroidDeployQtStep::updateInputFile()
{
Qt4ProjectManager::Qt4Project *pro = static_cast<Qt4ProjectManager::Qt4Project *>(project());
QList<Qt4ProjectManager::Qt4ProFileNode *> nodes = pro->applicationProFiles();
QStringList inputFiles;
foreach (Qt4ProjectManager::Qt4ProFileNode *node, nodes)
inputFiles << node->singleVariableValue(Qt4ProjectManager::AndroidDeploySettingsFile);
if (!inputFiles.contains(m_inputFile))
m_inputFile.clear();
if (m_inputFile.isEmpty()) {
// not yet selected one or no longer exists
if (!inputFiles.isEmpty())
m_inputFile = inputFiles.first();
}
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());
m_signPackage = map.value(SignPackageKey).toBool();
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
m_verbose = map.value(VerboseOutputKey).toBool();
m_inputFile = map.value(InputFile).toString();
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);
map.insert(InputFile, m_inputFile);
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)
{