2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2012-04-18 20:30:57 +03: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.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "androidmanager.h"
|
2015-03-05 11:56:15 +01:00
|
|
|
#include "androidconstants.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
#include "androiddeployconfiguration.h"
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
#include "androidrunconfiguration.h"
|
|
|
|
#include "androidglobal.h"
|
2013-01-25 16:49:22 +01:00
|
|
|
#include "androidtoolchain.h"
|
2013-09-17 18:24:57 +02:00
|
|
|
#include "androiddeployqtstep.h"
|
2014-06-24 16:47:38 +02:00
|
|
|
#include "androidqtsupport.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "androidqtversion.h"
|
|
|
|
#include "androidbuildapkstep.h"
|
2017-04-03 11:11:17 +02:00
|
|
|
#include "androidavdmanager.h"
|
2017-08-18 08:22:34 +02:00
|
|
|
#include "androidsdkmanager.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-04-16 17:27:06 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2013-09-17 18:24:57 +02:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2014-03-11 18:09:23 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2014-06-24 16:47:38 +02:00
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
#include <projectexplorer/project.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
#include <projectexplorer/target.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QList>
|
|
|
|
#include <QProcess>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDomDocument>
|
2017-04-10 15:02:57 +03:00
|
|
|
#include <QVersionNumber>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
const QLatin1String AndroidManifestName("AndroidManifest.xml");
|
|
|
|
const QLatin1String AndroidDefaultPropertiesName("project.properties");
|
2014-06-25 15:42:11 +02:00
|
|
|
const QLatin1String AndroidDeviceSn("AndroidDeviceSerialNumber");
|
2017-03-30 14:43:13 +02:00
|
|
|
const QLatin1String ApiLevelKey("AndroidVersion.ApiLevel");
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
2014-07-22 13:45:41 +02:00
|
|
|
class Library
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Library()
|
|
|
|
{ level = -1; }
|
|
|
|
int level;
|
|
|
|
QStringList dependencies;
|
|
|
|
QString name;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QMap<QString, Library> LibrariesMap;
|
|
|
|
|
|
|
|
static bool openXmlFile(QDomDocument &doc, const Utils::FileName &fileName);
|
|
|
|
static bool openManifest(ProjectExplorer::Target *target, QDomDocument &doc);
|
2016-08-17 18:46:12 +02:00
|
|
|
static int parseMinSdk(const QDomElement &manifestElem);
|
2014-07-22 13:45:41 +02:00
|
|
|
|
2017-12-08 17:20:48 +01:00
|
|
|
static QList<AndroidQtSupport *> g_androidQtSupportProviders;
|
|
|
|
|
|
|
|
AndroidQtSupport::AndroidQtSupport()
|
|
|
|
{
|
|
|
|
g_androidQtSupportProviders.append(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AndroidQtSupport::~AndroidQtSupport()
|
|
|
|
{
|
|
|
|
g_androidQtSupportProviders.removeOne(this);
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::packageName(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("package"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-10-24 17:53:05 +02:00
|
|
|
QString AndroidManager::packageName(const Utils::FileName &manifestFile)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openXmlFile(doc, manifestFile))
|
|
|
|
return QString();
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("package"));
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::intentName(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return packageName(target) + QLatin1Char('/') + activityName(target);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::activityName(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement activityElem = doc.documentElement().firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity"));
|
|
|
|
return activityElem.attribute(QLatin1String("android:name"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2016-08-17 18:46:12 +02:00
|
|
|
/*!
|
|
|
|
Returns the minimum Android API level set for the APK. Minimum API level
|
|
|
|
of the kit is returned if the manifest file of the APK can not be found
|
|
|
|
or parsed.
|
|
|
|
*/
|
2013-08-28 15:23:04 +02:00
|
|
|
int AndroidManager::minimumSDK(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
2015-01-27 18:46:40 +01:00
|
|
|
if (!openXmlFile(doc, AndroidManager::manifestSourcePath(target)))
|
2016-08-17 18:46:12 +02:00
|
|
|
return minimumSDK(target->kit());
|
|
|
|
return parseMinSdk(doc.documentElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the minimum Android API level required by the kit to compile. -1 is
|
|
|
|
returned if the kit does not support Android.
|
|
|
|
*/
|
|
|
|
int AndroidManager::minimumSDK(const ProjectExplorer::Kit *kit)
|
|
|
|
{
|
|
|
|
int minSDKVersion = -1;
|
2017-12-19 10:32:39 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
|
|
|
if (version && version->targetDeviceTypes().contains(Constants::ANDROID_DEVICE_TYPE)) {
|
2016-08-17 18:46:12 +02:00
|
|
|
Utils::FileName stockManifestFilePath =
|
|
|
|
Utils::FileName::fromUserInput(version->qmakeProperty("QT_INSTALL_PREFIX") +
|
|
|
|
QLatin1String("/src/android/templates/AndroidManifest.xml"));
|
|
|
|
QDomDocument doc;
|
|
|
|
if (openXmlFile(doc, stockManifestFilePath)) {
|
|
|
|
minSDKVersion = parseMinSdk(doc.documentElement());
|
|
|
|
}
|
2013-08-28 15:23:04 +02:00
|
|
|
}
|
2016-08-17 18:46:12 +02:00
|
|
|
return minSDKVersion;
|
2013-08-28 15:23:04 +02:00
|
|
|
}
|
|
|
|
|
2013-08-28 15:20:54 +02:00
|
|
|
QString AndroidManager::buildTargetSDK(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
AndroidBuildApkStep *androidBuildApkStep
|
|
|
|
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
|
|
|
|
if (androidBuildApkStep)
|
|
|
|
return androidBuildApkStep->buildTargetSdk();
|
|
|
|
|
2017-08-18 08:22:34 +02:00
|
|
|
QString fallback = AndroidConfig::apiLevelNameFor(
|
|
|
|
AndroidConfigurations::sdkManager()->latestAndroidSdkPlatform());
|
2014-06-25 15:42:11 +02:00
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidManager::signPackage(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
AndroidBuildApkStep *androidBuildApkStep
|
|
|
|
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
|
|
|
|
if (androidBuildApkStep)
|
|
|
|
return androidBuildApkStep->signPackage();
|
|
|
|
return false;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-05-03 15:10:21 +02:00
|
|
|
QString AndroidManager::targetArch(ProjectExplorer::Target *target)
|
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
AndroidQtVersion *qt = static_cast<AndroidQtVersion *>(QtSupport::QtKitInformation::qtVersion(target->kit()));
|
|
|
|
return qt->targetArch();
|
2013-05-03 15:10:21 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::dirPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2015-01-27 18:46:40 +01:00
|
|
|
if (target->activeBuildConfiguration())
|
|
|
|
return target->activeBuildConfiguration()->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY));
|
|
|
|
return Utils::FileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::FileName AndroidManager::manifestSourcePath(ProjectExplorer::Target *target)
|
|
|
|
{
|
2018-01-30 18:19:46 +01:00
|
|
|
if (AndroidQtSupport *androidQtSupport = AndroidManager::androidQtSupport(target)) {
|
|
|
|
Utils::FileName source = androidQtSupport->manifestSourcePath(target);
|
|
|
|
if (!source.isEmpty())
|
|
|
|
return source;
|
|
|
|
}
|
2015-01-27 18:46:40 +01:00
|
|
|
return manifestPath(target);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::manifestPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(AndroidManifestName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::defaultPropertiesPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(AndroidDefaultPropertiesName);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-04-19 12:27:58 +02:00
|
|
|
bool AndroidManager::bundleQt(ProjectExplorer::Target *target)
|
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
AndroidBuildApkStep *androidBuildApkStep
|
|
|
|
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
|
|
|
|
if (androidBuildApkStep)
|
2017-09-27 18:24:04 -07:00
|
|
|
return !androidBuildApkStep->useMinistro();
|
2013-04-19 12:27:58 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
QString AndroidManager::deviceSerialNumber(ProjectExplorer::Target *target)
|
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
return target->namedSettings(AndroidDeviceSn).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidManager::setDeviceSerialNumber(ProjectExplorer::Target *target, const QString &deviceSerialNumber)
|
|
|
|
{
|
|
|
|
target->setNamedSettings(AndroidDeviceSn, deviceSerialNumber);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2018-03-17 09:31:56 +02:00
|
|
|
int AndroidManager::deviceApiLevel(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
return target->namedSettings(ApiLevelKey).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidManager::setDeviceApiLevel(ProjectExplorer::Target *target, int level)
|
|
|
|
{
|
|
|
|
target->setNamedSettings(ApiLevelKey, level);
|
|
|
|
}
|
|
|
|
|
2014-05-07 15:03:43 +03:00
|
|
|
QPair<int, int> AndroidManager::apiLevelRange()
|
2013-08-14 13:39:45 +02:00
|
|
|
{
|
2017-08-16 12:47:00 +02:00
|
|
|
return qMakePair(9, 26);
|
2013-08-14 13:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString AndroidManager::androidNameForApiLevel(int x)
|
|
|
|
{
|
|
|
|
switch (x) {
|
|
|
|
case 4:
|
|
|
|
return QLatin1String("Android 1.6");
|
|
|
|
case 5:
|
|
|
|
return QLatin1String("Android 2.0");
|
|
|
|
case 6:
|
|
|
|
return QLatin1String("Android 2.0.1");
|
|
|
|
case 7:
|
|
|
|
return QLatin1String("Android 2.1.x");
|
|
|
|
case 8:
|
|
|
|
return QLatin1String("Android 2.2.x");
|
|
|
|
case 9:
|
|
|
|
return QLatin1String("Android 2.3, 2.3.1, 2.3.2");
|
|
|
|
case 10:
|
|
|
|
return QLatin1String("Android 2.3.3, 2.3.4");
|
|
|
|
case 11:
|
|
|
|
return QLatin1String("Android 3.0.x");
|
|
|
|
case 12:
|
|
|
|
return QLatin1String("Android 3.1.x");
|
|
|
|
case 13:
|
|
|
|
return QLatin1String("Android 3.2");
|
|
|
|
case 14:
|
|
|
|
return QLatin1String("Android 4.0, 4.0.1, 4.0.2");
|
|
|
|
case 15:
|
|
|
|
return QLatin1String("Android 4.0.3, 4.0.4");
|
|
|
|
case 16:
|
|
|
|
return QLatin1String("Android 4.1, 4.1.1");
|
|
|
|
case 17:
|
|
|
|
return QLatin1String("Android 4.2, 4.2.2");
|
|
|
|
case 18:
|
|
|
|
return QLatin1String("Android 4.3");
|
2013-11-12 12:14:33 +01:00
|
|
|
case 19:
|
|
|
|
return QLatin1String("Android 4.4");
|
2014-07-16 17:39:24 +02:00
|
|
|
case 20:
|
2014-11-25 11:37:09 +01:00
|
|
|
return QLatin1String("Android 4.4W");
|
2014-11-14 15:29:48 +02:00
|
|
|
case 21:
|
|
|
|
return QLatin1String("Android 5.0");
|
2015-05-20 15:10:50 +03:00
|
|
|
case 22:
|
|
|
|
return QLatin1String("Android 5.1");
|
2015-12-01 11:29:47 +01:00
|
|
|
case 23:
|
|
|
|
return QLatin1String("Android 6.0");
|
2016-09-04 19:28:58 +03:00
|
|
|
case 24:
|
|
|
|
return QLatin1String("Android 7.0");
|
2016-12-07 11:20:37 +02:00
|
|
|
case 25:
|
|
|
|
return QLatin1String("Android 7.1");
|
2017-08-16 12:47:00 +02:00
|
|
|
case 26:
|
|
|
|
return QLatin1String("Android 8.0");
|
2013-08-14 13:39:45 +02:00
|
|
|
default:
|
2014-07-16 17:36:21 +02:00
|
|
|
return tr("Unknown Android version. API Level: %1").arg(QString::number(x));
|
2013-08-14 13:39:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:45:41 +02:00
|
|
|
static void raiseError(const QString &reason)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-07-22 13:45:41 +02:00
|
|
|
QMessageBox::critical(0, AndroidManager::tr("Error creating Android templates."), reason);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:45:41 +02:00
|
|
|
static bool openXmlFile(QDomDocument &doc, const Utils::FileName &fileName)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QFile f(fileName.toString());
|
|
|
|
if (!f.open(QIODevice::ReadOnly))
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!doc.setContent(f.readAll())) {
|
2014-07-22 13:45:41 +02:00
|
|
|
raiseError(AndroidManager::tr("Cannot parse \"%1\".").arg(fileName.toUserOutput()));
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return true;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2014-07-22 13:45:41 +02:00
|
|
|
static bool openManifest(ProjectExplorer::Target *target, QDomDocument &doc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2014-07-22 13:45:41 +02:00
|
|
|
return openXmlFile(doc, AndroidManager::manifestPath(target));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2016-08-17 18:46:12 +02:00
|
|
|
static int parseMinSdk(const QDomElement &manifestElem)
|
|
|
|
{
|
|
|
|
QDomElement usesSdk = manifestElem.firstChildElement(QLatin1String("uses-sdk"));
|
|
|
|
if (usesSdk.isNull())
|
|
|
|
return 0;
|
|
|
|
if (usesSdk.hasAttribute(QLatin1String("android:minSdkVersion"))) {
|
|
|
|
bool ok;
|
|
|
|
int tmp = usesSdk.attribute(QLatin1String("android:minSdkVersion")).toInt(&ok);
|
|
|
|
if (ok)
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-17 18:24:57 +02:00
|
|
|
void AndroidManager::cleanLibsOnDevice(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
const QString targetArch = AndroidManager::targetArch(target);
|
2013-10-09 16:24:25 +02:00
|
|
|
if (targetArch.isEmpty())
|
|
|
|
return;
|
2015-06-10 10:34:03 +02:00
|
|
|
const int deviceAPILevel = AndroidManager::minimumSDK(target);
|
2017-09-04 15:21:16 -07:00
|
|
|
AndroidDeviceInfo info = AndroidConfigurations::showDeviceDialog(target->project(), deviceAPILevel, targetArch);
|
2015-12-04 10:03:45 +02:00
|
|
|
if (!info.isValid()) // aborted
|
2013-09-17 18:24:57 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
QString deviceSerialNumber = info.serialNumber;
|
|
|
|
|
|
|
|
if (info.type == AndroidDeviceInfo::Emulator) {
|
2017-04-03 11:11:17 +02:00
|
|
|
deviceSerialNumber = AndroidAvdManager().startAvd(info.avdname);
|
2013-09-17 18:24:57 +02:00
|
|
|
if (deviceSerialNumber.isEmpty())
|
2013-10-09 16:37:42 +02:00
|
|
|
Core::MessageManager::write(tr("Starting Android virtual device failed."));
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QProcess *process = new QProcess();
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
|
|
|
arguments << QLatin1String("shell") << QLatin1String("rm") << QLatin1String("-r") << QLatin1String("/data/local/tmp/qt");
|
2016-06-26 22:52:59 +03:00
|
|
|
QObject::connect(process, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
|
|
|
process, &QObject::deleteLater);
|
2013-12-16 20:19:07 +01:00
|
|
|
const QString adb = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
2014-08-23 01:19:53 +02:00
|
|
|
Core::MessageManager::write(adb + QLatin1Char(' ') + arguments.join(QLatin1Char(' ')));
|
2013-09-17 18:24:57 +02:00
|
|
|
process->start(adb, arguments);
|
|
|
|
if (!process->waitForStarted(500))
|
|
|
|
delete process;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AndroidManager::installQASIPackage(ProjectExplorer::Target *target, const QString &packagePath)
|
|
|
|
{
|
|
|
|
const QString targetArch = AndroidManager::targetArch(target);
|
2013-10-09 16:24:25 +02:00
|
|
|
if (targetArch.isEmpty())
|
|
|
|
return;
|
2015-06-10 10:34:03 +02:00
|
|
|
const int deviceAPILevel = AndroidManager::minimumSDK(target);
|
2017-09-04 15:21:16 -07:00
|
|
|
AndroidDeviceInfo info = AndroidConfigurations::showDeviceDialog(target->project(), deviceAPILevel, targetArch);
|
2015-12-04 10:03:45 +02:00
|
|
|
if (!info.isValid()) // aborted
|
2013-09-17 18:24:57 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
QString deviceSerialNumber = info.serialNumber;
|
|
|
|
if (info.type == AndroidDeviceInfo::Emulator) {
|
2017-04-03 11:11:17 +02:00
|
|
|
deviceSerialNumber = AndroidAvdManager().startAvd(info.avdname);
|
2013-09-17 18:24:57 +02:00
|
|
|
if (deviceSerialNumber.isEmpty())
|
2013-10-09 16:37:42 +02:00
|
|
|
Core::MessageManager::write(tr("Starting Android virtual device failed."));
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QProcess *process = new QProcess();
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
|
|
|
arguments << QLatin1String("install") << QLatin1String("-r ") << packagePath;
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
connect(process, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
|
|
|
process, &QObject::deleteLater);
|
2013-12-16 20:19:07 +01:00
|
|
|
const QString adb = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
2014-08-23 01:19:53 +02:00
|
|
|
Core::MessageManager::write(adb + QLatin1Char(' ') + arguments.join(QLatin1Char(' ')));
|
2013-09-17 18:24:57 +02:00
|
|
|
process->start(adb, arguments);
|
2016-04-29 16:52:58 +02:00
|
|
|
if (!process->waitForStarted(500) && process->state() != QProcess::Running)
|
2013-09-17 18:24:57 +02:00
|
|
|
delete process;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidManager::checkKeystorePassword(const QString &keystorePath, const QString &keystorePasswd)
|
|
|
|
{
|
|
|
|
if (keystorePasswd.isEmpty())
|
|
|
|
return false;
|
|
|
|
QStringList arguments;
|
|
|
|
arguments << QLatin1String("-list")
|
|
|
|
<< QLatin1String("-keystore")
|
|
|
|
<< keystorePath
|
|
|
|
<< QLatin1String("--storepass")
|
|
|
|
<< keystorePasswd;
|
2016-04-29 16:52:58 +02:00
|
|
|
Utils::SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(10);
|
|
|
|
Utils::SynchronousProcessResponse response = proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
|
|
|
return (response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const QString &keystorePasswd, const QString &alias, const QString &certificatePasswd)
|
|
|
|
{
|
|
|
|
// assumes that the keystore password is correct
|
2017-02-22 15:09:35 +01:00
|
|
|
QStringList arguments = {"-certreq", "-keystore", keystorePath,
|
|
|
|
"--storepass", keystorePasswd, "-alias", alias, "-keypass"};
|
2013-09-17 18:24:57 +02:00
|
|
|
if (certificatePasswd.isEmpty())
|
|
|
|
arguments << keystorePasswd;
|
|
|
|
else
|
|
|
|
arguments << certificatePasswd;
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
Utils::SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(10);
|
2017-01-10 16:33:56 +01:00
|
|
|
Utils::SynchronousProcessResponse response
|
|
|
|
= proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
|
|
|
return response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidManager::checkCertificateExists(const QString &keystorePath,
|
|
|
|
const QString &keystorePasswd, const QString &alias)
|
|
|
|
{
|
|
|
|
// assumes that the keystore password is correct
|
2017-02-07 16:59:21 +01:00
|
|
|
QStringList arguments = { "-list", "-keystore", keystorePath,
|
|
|
|
"--storepass", keystorePasswd, "-alias", alias };
|
2017-01-10 16:33:56 +01:00
|
|
|
|
|
|
|
Utils::SynchronousProcess proc;
|
|
|
|
proc.setTimeoutS(10);
|
2016-04-29 16:52:58 +02:00
|
|
|
Utils::SynchronousProcessResponse response
|
|
|
|
= proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
|
|
|
return response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:47:10 +02:00
|
|
|
bool AndroidManager::checkForQt51Files(Utils::FileName fileName)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
fileName.appendPath(QLatin1String("android")).appendPath(QLatin1String("version.xml"));
|
2014-10-24 13:15:54 +02:00
|
|
|
if (!fileName.exists())
|
2013-09-17 18:24:57 +02:00
|
|
|
return false;
|
|
|
|
QDomDocument dstVersionDoc;
|
2014-07-22 13:45:41 +02:00
|
|
|
if (!openXmlFile(dstVersionDoc, fileName))
|
2013-09-17 18:24:57 +02:00
|
|
|
return false;
|
|
|
|
return dstVersionDoc.documentElement().attribute(QLatin1String("value")).toDouble() < 5.2;
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:47:38 +02:00
|
|
|
AndroidQtSupport *AndroidManager::androidQtSupport(ProjectExplorer::Target *target)
|
|
|
|
{
|
2017-12-08 17:20:48 +01:00
|
|
|
for (AndroidQtSupport *provider : g_androidQtSupportProviders) {
|
2014-06-24 16:47:38 +02:00
|
|
|
if (provider->canHandle(target))
|
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
typedef QMap<QByteArray, QByteArray> GradleProperties;
|
|
|
|
|
|
|
|
static GradleProperties readGradleProperties(const QString &path)
|
|
|
|
{
|
|
|
|
GradleProperties properties;
|
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return properties;
|
|
|
|
|
|
|
|
foreach (const QByteArray &line, file.readAll().split('\n')) {
|
|
|
|
if (line.trimmed().startsWith('#'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QList<QByteArray> prop(line.split('='));
|
|
|
|
if (prop.size() > 1)
|
|
|
|
properties[prop.at(0).trimmed()] = prop.at(1).trimmed();
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool mergeGradleProperties(const QString &path, GradleProperties properties)
|
|
|
|
{
|
|
|
|
QFile::remove(path + QLatin1Char('~'));
|
|
|
|
QFile::rename(path, path + QLatin1Char('~'));
|
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QFile oldFile(path + QLatin1Char('~'));
|
|
|
|
if (oldFile.open(QIODevice::ReadOnly)) {
|
|
|
|
while (!oldFile.atEnd()) {
|
|
|
|
QByteArray line(oldFile.readLine());
|
|
|
|
QList<QByteArray> prop(line.split('='));
|
|
|
|
if (prop.size() > 1) {
|
|
|
|
GradleProperties::iterator it = properties.find(prop.at(0).trimmed());
|
|
|
|
if (it != properties.end()) {
|
|
|
|
file.write(it.key() + '=' + it.value() + '\n');
|
|
|
|
properties.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.write(line);
|
|
|
|
}
|
|
|
|
oldFile.close();
|
|
|
|
} else {
|
|
|
|
file.write("## This file is automatically generated by QtCreator.\n"
|
|
|
|
"#\n"
|
|
|
|
"# This file must *NOT* be checked into Version Control Systems,\n"
|
|
|
|
"# as it contains information specific to your local configuration.\n\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-01 11:19:32 +02:00
|
|
|
for (GradleProperties::const_iterator it = properties.constBegin(); it != properties.constEnd();
|
|
|
|
++it)
|
2014-09-22 16:20:51 +03:00
|
|
|
file.write(it.key() + '=' + it.value() + '\n');
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AndroidManager::updateGradleProperties(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
|
|
|
|
if (!version)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AndroidBuildApkStep *buildApkStep
|
|
|
|
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
|
|
|
|
|
2017-09-08 23:36:13 +02:00
|
|
|
if (!buildApkStep || !buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradlew")).exists())
|
2014-09-22 16:20:51 +03:00
|
|
|
return false;
|
|
|
|
|
2016-01-05 15:48:51 +02:00
|
|
|
Utils::FileName wrapperProps(buildApkStep->androidPackageSourceDir());
|
|
|
|
wrapperProps.appendPath(QLatin1String("gradle/wrapper/gradle-wrapper.properties"));
|
|
|
|
if (wrapperProps.exists()) {
|
|
|
|
GradleProperties wrapperProperties = readGradleProperties(wrapperProps.toString());
|
|
|
|
QString distributionUrl = QString::fromLocal8Bit(wrapperProperties["distributionUrl"]);
|
2017-03-22 13:45:20 +02:00
|
|
|
// Update only old gradle distributionUrl
|
|
|
|
if (distributionUrl.endsWith(QLatin1String("distributions/gradle-1.12-all.zip"))) {
|
2016-01-05 15:48:51 +02:00
|
|
|
wrapperProperties["distributionUrl"] = "https\\://services.gradle.org/distributions/gradle-2.2.1-all.zip";
|
|
|
|
mergeGradleProperties(wrapperProps.toString(), wrapperProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
GradleProperties localProperties;
|
|
|
|
localProperties["sdk.dir"] = AndroidConfigurations::currentConfig().sdkLocation().toString().toLocal8Bit();
|
|
|
|
if (!mergeGradleProperties(buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("local.properties")).toString(), localProperties))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QString gradlePropertiesPath = buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradle.properties")).toString();
|
|
|
|
GradleProperties gradleProperties = readGradleProperties(gradlePropertiesPath);
|
|
|
|
gradleProperties["qt5AndroidDir"] = version->qmakeProperty("QT_INSTALL_PREFIX")
|
|
|
|
.append(QLatin1String("/src/android/java")).toLocal8Bit();
|
|
|
|
gradleProperties["buildDir"] = ".build";
|
|
|
|
gradleProperties["androidCompileSdkVersion"] = buildTargetSDK(target).split(QLatin1Char('-')).last().toLocal8Bit();
|
|
|
|
if (gradleProperties["androidBuildToolsVersion"].isEmpty()) {
|
2017-09-04 14:54:50 +02:00
|
|
|
QVersionNumber buildtoolVersion = AndroidConfigurations::currentConfig().buildToolsVersion();
|
|
|
|
if (buildtoolVersion.isNull())
|
2014-09-22 16:20:51 +03:00
|
|
|
return false;
|
2017-09-04 14:54:50 +02:00
|
|
|
gradleProperties["androidBuildToolsVersion"] = buildtoolVersion.toString().toLocal8Bit();
|
2014-09-22 16:20:51 +03:00
|
|
|
}
|
|
|
|
return mergeGradleProperties(gradlePropertiesPath, gradleProperties);
|
|
|
|
}
|
|
|
|
|
2017-03-30 14:43:13 +02:00
|
|
|
int AndroidManager::findApiLevel(const Utils::FileName &platformPath)
|
|
|
|
{
|
|
|
|
int apiLevel = -1;
|
|
|
|
Utils::FileName propertiesPath = platformPath;
|
|
|
|
propertiesPath.appendPath("/source.properties");
|
|
|
|
if (propertiesPath.exists()) {
|
|
|
|
QSettings sdkProperties(propertiesPath.toString(), QSettings::IniFormat);
|
|
|
|
bool validInt = false;
|
|
|
|
apiLevel = sdkProperties.value(ApiLevelKey).toInt(&validInt);
|
|
|
|
if (!validInt)
|
|
|
|
apiLevel = -1;
|
|
|
|
}
|
|
|
|
return apiLevel;
|
|
|
|
}
|
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
} // namespace Android
|