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"
|
2019-01-18 18:07:54 +01:00
|
|
|
|
|
|
|
#include "androidbuildapkstep.h"
|
2015-03-05 11:56:15 +01:00
|
|
|
#include "androidconstants.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
#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-25 15:42:11 +02:00
|
|
|
#include "androidqtversion.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>
|
2018-12-05 10:29:48 +01:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2020-07-23 15:48:56 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
#include <projectexplorer/target.h>
|
2021-08-23 21:36:55 +03:00
|
|
|
#include <projectexplorer/buildsystem.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>
|
2021-09-09 11:45:48 +03:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
|
|
|
#include <cmakeprojectmanager/cmakeprojectconstants.h>
|
2018-07-27 11:18:06 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2018-07-27 11:18:06 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2021-05-05 18:21:22 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2020-06-17 06:35:31 +02:00
|
|
|
#include <utils/stringutils.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2020-01-20 11:20:09 +02:00
|
|
|
#include <QApplication>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QDir>
|
2020-01-20 11:20:09 +02:00
|
|
|
#include <QDomDocument>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QFileSystemWatcher>
|
2020-01-20 11:20:09 +02:00
|
|
|
#include <QJsonDocument>
|
2020-02-12 13:41:34 +01:00
|
|
|
#include <QJsonObject>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QList>
|
2018-06-18 11:49:14 +02:00
|
|
|
#include <QLoggingCategory>
|
2020-01-20 11:20:09 +02:00
|
|
|
#include <QMessageBox>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QProcess>
|
2018-07-03 11:53:25 +02:00
|
|
|
#include <QRegularExpression>
|
2020-01-20 11:20:09 +02:00
|
|
|
#include <QVersionNumber>
|
2018-06-18 11:49:14 +02:00
|
|
|
|
2018-12-05 10:29:48 +01:00
|
|
|
using namespace ProjectExplorer;
|
2018-05-31 10:51:37 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
using namespace Android::Internal;
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
namespace Android {
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
const QLatin1String AndroidManifestName("AndroidManifest.xml");
|
|
|
|
const QLatin1String AndroidDeviceSn("AndroidDeviceSerialNumber");
|
|
|
|
const QLatin1String AndroidDeviceAbis("AndroidDeviceAbis");
|
|
|
|
const QLatin1String ApiLevelKey("AndroidVersion.ApiLevel");
|
2021-05-28 18:22:44 +03:00
|
|
|
const char qtcSignature[] = "This file is generated by QtCreator to be read by androiddeployqt "
|
|
|
|
"and should not be modified by hand.";
|
2020-05-18 16:38:18 +02:00
|
|
|
|
|
|
|
static Q_LOGGING_CATEGORY(androidManagerLog, "qtc.android.androidManager", QtWarningMsg)
|
|
|
|
|
2014-07-22 13:45:41 +02:00
|
|
|
class Library
|
|
|
|
{
|
|
|
|
public:
|
2020-05-18 16:38:18 +02:00
|
|
|
int level = -1;
|
2014-07-22 13:45:41 +02:00
|
|
|
QStringList dependencies;
|
|
|
|
QString name;
|
|
|
|
};
|
|
|
|
|
2018-07-25 12:19:15 +02:00
|
|
|
using LibrariesMap = QMap<QString, Library>;
|
2014-07-22 13:45:41 +02:00
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
static bool openXmlFile(QDomDocument &doc, const FilePath &fileName);
|
|
|
|
static bool openManifest(const 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
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
static const ProjectNode *currentProjectNode(const Target *target)
|
2017-12-08 17:20:48 +01:00
|
|
|
{
|
2018-12-05 10:29:48 +01:00
|
|
|
if (RunConfiguration *rc = target->activeRunConfiguration())
|
|
|
|
return target->project()->findNodeForBuildKey(rc->buildKey());
|
|
|
|
return nullptr;
|
2017-12-08 17:20:48 +01:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
QString AndroidManager::packageName(const Target *target)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
QString AndroidManager::packageName(const FilePath &manifestFile)
|
2014-10-24 17:53:05 +02:00
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openXmlFile(doc, manifestFile))
|
|
|
|
return QString();
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("package"));
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
QString AndroidManager::activityName(const 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
|
2018-10-22 16:34:31 +02:00
|
|
|
of the kit is returned if the manifest file of the APK cannot be found
|
2016-08-17 18:46:12 +02:00
|
|
|
or parsed.
|
|
|
|
*/
|
2020-05-18 16:38:18 +02:00
|
|
|
int AndroidManager::minimumSDK(const Target *target)
|
2013-08-28 15:23:04 +02:00
|
|
|
{
|
|
|
|
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());
|
2021-09-05 19:16:49 +03:00
|
|
|
const int minSdkVersion = parseMinSdk(doc.documentElement());
|
|
|
|
if (minSdkVersion == 0)
|
|
|
|
return AndroidManager::defaultMinimumSDK(QtSupport::QtKitAspect::qtVersion(target->kit()));
|
|
|
|
return minSdkVersion;
|
2016-08-17 18:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the minimum Android API level required by the kit to compile. -1 is
|
|
|
|
returned if the kit does not support Android.
|
|
|
|
*/
|
2020-05-18 16:38:18 +02:00
|
|
|
int AndroidManager::minimumSDK(const Kit *kit)
|
2016-08-17 18:46:12 +02:00
|
|
|
{
|
2021-09-05 19:16:49 +03:00
|
|
|
int minSdkVersion = -1;
|
2019-02-06 12:50:51 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
|
2017-12-19 10:32:39 +01:00
|
|
|
if (version && version->targetDeviceTypes().contains(Constants::ANDROID_DEVICE_TYPE)) {
|
2020-05-18 16:38:18 +02:00
|
|
|
FilePath stockManifestFilePath = FilePath::fromUserInput(
|
2019-09-30 14:34:31 +02:00
|
|
|
version->prefix().toString() + "/src/android/templates/AndroidManifest.xml");
|
2016-08-17 18:46:12 +02:00
|
|
|
QDomDocument doc;
|
|
|
|
if (openXmlFile(doc, stockManifestFilePath)) {
|
2021-09-05 19:16:49 +03:00
|
|
|
minSdkVersion = parseMinSdk(doc.documentElement());
|
2016-08-17 18:46:12 +02:00
|
|
|
}
|
2013-08-28 15:23:04 +02:00
|
|
|
}
|
2021-09-05 19:16:49 +03:00
|
|
|
if (minSdkVersion == 0)
|
|
|
|
return AndroidManager::defaultMinimumSDK(version);
|
|
|
|
return minSdkVersion;
|
2013-08-28 15:23:04 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
QString AndroidManager::buildTargetSDK(const Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2019-12-20 10:54:54 +01:00
|
|
|
if (auto bc = target->activeBuildConfiguration()) {
|
|
|
|
if (auto androidBuildApkStep = bc->buildSteps()->firstOfType<AndroidBuildApkStep>())
|
|
|
|
return androidBuildApkStep->buildTargetSdk();
|
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-26 14:19:07 +03:00
|
|
|
QStringList AndroidManager::applicationAbis(const Target *target)
|
2013-05-03 15:10:21 +02:00
|
|
|
{
|
2021-03-26 07:46:25 +01:00
|
|
|
auto qt = dynamic_cast<AndroidQtVersion *>(QtSupport::QtKitAspect::qtVersion(target->kit()));
|
2020-06-25 15:17:50 +02:00
|
|
|
return qt ? qt->androidAbis() : QStringList();
|
2013-05-03 15:10:21 +02:00
|
|
|
}
|
|
|
|
|
2020-01-20 11:20:09 +02:00
|
|
|
QString AndroidManager::archTriplet(const QString &abi)
|
|
|
|
{
|
2020-07-23 15:48:56 +02:00
|
|
|
if (abi == ProjectExplorer::Constants::ANDROID_ABI_X86) {
|
2020-01-21 06:57:40 +01:00
|
|
|
return {"i686-linux-android"};
|
2020-07-23 15:48:56 +02:00
|
|
|
} else if (abi == ProjectExplorer::Constants::ANDROID_ABI_X86_64) {
|
2020-01-21 06:57:40 +01:00
|
|
|
return {"x86_64-linux-android"};
|
2020-07-23 15:48:56 +02:00
|
|
|
} else if (abi == ProjectExplorer::Constants::ANDROID_ABI_ARM64_V8A) {
|
2020-01-21 06:57:40 +01:00
|
|
|
return {"aarch64-linux-android"};
|
2020-01-20 11:20:09 +02:00
|
|
|
}
|
2020-01-21 06:57:40 +01:00
|
|
|
return {"arm-linux-androideabi"};
|
2020-01-20 11:20:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
QJsonObject AndroidManager::deploymentSettings(const Target *target)
|
|
|
|
{
|
|
|
|
QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(target->kit());
|
|
|
|
if (!qt)
|
|
|
|
return {};
|
|
|
|
|
2020-02-18 18:25:26 +01:00
|
|
|
auto tc = ToolChainKitAspect::cxxToolChain(target->kit());
|
2019-06-14 11:12:19 +02:00
|
|
|
if (!tc || tc->typeId() != Constants::ANDROID_TOOLCHAIN_TYPEID)
|
2019-03-06 14:17:17 +02:00
|
|
|
return {};
|
|
|
|
QJsonObject settings;
|
2020-01-20 11:20:09 +02:00
|
|
|
settings["_description"] = qtcSignature;
|
2019-09-30 14:34:31 +02:00
|
|
|
settings["qt"] = qt->prefix().toString();
|
2020-02-16 20:46:23 +02:00
|
|
|
settings["ndk"] = AndroidConfigurations::currentConfig().ndkLocation(qt).toString();
|
2019-03-06 14:17:17 +02:00
|
|
|
settings["sdk"] = AndroidConfigurations::currentConfig().sdkLocation().toString();
|
2020-08-20 13:58:21 +02:00
|
|
|
if (!qt->supportsMultipleQtAbis()) {
|
2020-01-20 11:20:09 +02:00
|
|
|
const QStringList abis = applicationAbis(target);
|
|
|
|
QTC_ASSERT(abis.size() == 1, return {});
|
2020-02-19 17:35:56 +01:00
|
|
|
settings["stdcpp-path"] = (AndroidConfigurations::currentConfig().toolchainPath(qt)
|
2021-08-13 11:41:52 +02:00
|
|
|
/ "sysroot/usr/lib"
|
2020-02-19 17:35:56 +01:00
|
|
|
/ archTriplet(abis.first())
|
|
|
|
/ "libc++_shared.so").toString();
|
2020-01-20 11:20:09 +02:00
|
|
|
} else {
|
2020-02-16 20:46:23 +02:00
|
|
|
settings["stdcpp-path"] = AndroidConfigurations::currentConfig()
|
|
|
|
.toolchainPath(qt)
|
2021-08-13 11:41:52 +02:00
|
|
|
.pathAppended("sysroot/usr/lib")
|
2020-02-16 20:46:23 +02:00
|
|
|
.toString();
|
2020-01-20 11:20:09 +02:00
|
|
|
}
|
2019-03-06 14:17:17 +02:00
|
|
|
settings["toolchain-prefix"] = "llvm";
|
|
|
|
settings["tool-prefix"] = "llvm";
|
|
|
|
settings["useLLVM"] = true;
|
2020-02-16 20:46:23 +02:00
|
|
|
settings["ndk-host"] = AndroidConfigurations::currentConfig().toolchainHost(qt);
|
2019-03-06 14:17:17 +02:00
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2020-01-20 11:20:09 +02:00
|
|
|
bool AndroidManager::isQtCreatorGenerated(const FilePath &deploymentFile)
|
|
|
|
{
|
|
|
|
QFile f{deploymentFile.toString()};
|
|
|
|
if (!f.open(QIODevice::ReadOnly))
|
|
|
|
return false;
|
|
|
|
return QJsonDocument::fromJson(f.readAll()).object()["_description"].toString() == qtcSignature;
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
FilePath AndroidManager::dirPath(const Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2021-08-23 21:36:55 +03:00
|
|
|
return androidBuildDirectory(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
FilePath AndroidManager::androidBuildDirectory(const Target *target)
|
|
|
|
{
|
|
|
|
return buildDirectory(target) / Constants::ANDROID_BUILD_DIRECTORY;
|
|
|
|
}
|
|
|
|
|
2021-09-09 11:45:48 +03:00
|
|
|
bool AndroidManager::isQt5CmakeProject(const ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(target->kit());
|
|
|
|
const bool isQt5 = qt && qt->qtVersion() < QtSupport::QtVersionNumber{6, 0, 0};
|
|
|
|
const Core::Context cmakeCtx = Core::Context(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
|
|
|
|
const bool isCmakeProject = (target->project()->projectContext() == cmakeCtx);
|
|
|
|
return isQt5 && isCmakeProject;
|
|
|
|
}
|
|
|
|
|
2021-08-23 21:36:55 +03:00
|
|
|
FilePath AndroidManager::buildDirectory(const Target *target)
|
|
|
|
{
|
2021-09-09 11:45:48 +03:00
|
|
|
if (const BuildSystem *bs = target->buildSystem()) {
|
|
|
|
const QString buildKey = target->activeBuildKey();
|
|
|
|
const FilePath buildDir = bs->buildTarget(target->activeBuildKey()).workingDirectory;
|
|
|
|
if (isQt5CmakeProject(target)) {
|
|
|
|
// Return the main build dir and not the android libs dir
|
|
|
|
const QString libsDir = QString(Constants::ANDROID_BUILD_DIRECTORY) + "/libs";
|
|
|
|
Utils::FilePath parentDuildDir = buildDir.parentDir();
|
|
|
|
if (parentDuildDir.endsWith(libsDir) || libsDir.endsWith(libsDir + "/"))
|
|
|
|
return parentDuildDir.parentDir().parentDir();
|
|
|
|
}
|
|
|
|
return buildDir;
|
|
|
|
}
|
2020-05-18 16:38:18 +02:00
|
|
|
return {};
|
2015-01-27 18:46:40 +01:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
FilePath AndroidManager::apkPath(const Target *target)
|
2018-07-27 11:18:06 +02:00
|
|
|
{
|
2020-05-18 16:38:18 +02:00
|
|
|
QTC_ASSERT(target, return {});
|
2018-07-27 11:18:06 +02:00
|
|
|
|
2019-12-20 10:54:54 +01:00
|
|
|
auto bc = target->activeBuildConfiguration();
|
|
|
|
if (!bc)
|
|
|
|
return {};
|
|
|
|
auto buildApkStep = bc->buildSteps()->firstOfType<AndroidBuildApkStep>();
|
2018-07-27 11:18:06 +02:00
|
|
|
if (!buildApkStep)
|
2020-05-18 16:38:18 +02:00
|
|
|
return {};
|
2018-07-27 11:18:06 +02:00
|
|
|
|
|
|
|
QString apkPath("build/outputs/apk/android-build-");
|
|
|
|
if (buildApkStep->signPackage())
|
|
|
|
apkPath += QLatin1String("release.apk");
|
|
|
|
else
|
|
|
|
apkPath += QLatin1String("debug.apk");
|
|
|
|
|
2021-08-23 21:36:55 +03:00
|
|
|
return androidBuildDirectory(target) / apkPath;
|
2018-07-27 11:18:06 +02:00
|
|
|
}
|
|
|
|
|
2019-08-26 14:19:07 +03:00
|
|
|
bool AndroidManager::matchedAbis(const QStringList &deviceAbis, const QStringList &appAbis)
|
|
|
|
{
|
|
|
|
for (const auto &abi : appAbis) {
|
|
|
|
if (deviceAbis.contains(abi))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AndroidManager::devicePreferredAbi(const QStringList &deviceAbis, const QStringList &appAbis)
|
|
|
|
{
|
|
|
|
for (const auto &abi : appAbis) {
|
|
|
|
if (deviceAbis.contains(abi))
|
|
|
|
return abi;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Abi AndroidManager::androidAbi2Abi(const QString &androidAbi)
|
|
|
|
{
|
2020-07-23 15:48:56 +02:00
|
|
|
if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_ARM64_V8A) {
|
2019-08-26 14:19:07 +03:00
|
|
|
return Abi{Abi::Architecture::ArmArchitecture,
|
|
|
|
Abi::OS::LinuxOS,
|
|
|
|
Abi::OSFlavor::AndroidLinuxFlavor,
|
|
|
|
Abi::BinaryFormat::ElfFormat,
|
|
|
|
64, androidAbi};
|
2020-07-23 15:48:56 +02:00
|
|
|
} else if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_ARMEABI_V7A) {
|
2019-08-26 14:19:07 +03:00
|
|
|
return Abi{Abi::Architecture::ArmArchitecture,
|
|
|
|
Abi::OS::LinuxOS,
|
|
|
|
Abi::OSFlavor::AndroidLinuxFlavor,
|
|
|
|
Abi::BinaryFormat::ElfFormat,
|
|
|
|
32, androidAbi};
|
2020-07-23 15:48:56 +02:00
|
|
|
} else if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_X86_64) {
|
2019-08-26 14:19:07 +03:00
|
|
|
return Abi{Abi::Architecture::X86Architecture,
|
|
|
|
Abi::OS::LinuxOS,
|
|
|
|
Abi::OSFlavor::AndroidLinuxFlavor,
|
|
|
|
Abi::BinaryFormat::ElfFormat,
|
|
|
|
64, androidAbi};
|
2020-07-23 15:48:56 +02:00
|
|
|
} else if (androidAbi == ProjectExplorer::Constants::ANDROID_ABI_X86) {
|
2019-08-26 14:19:07 +03:00
|
|
|
return Abi{Abi::Architecture::X86Architecture,
|
|
|
|
Abi::OS::LinuxOS,
|
|
|
|
Abi::OSFlavor::AndroidLinuxFlavor,
|
|
|
|
Abi::BinaryFormat::ElfFormat,
|
|
|
|
32, androidAbi};
|
|
|
|
} else {
|
|
|
|
return Abi{Abi::Architecture::UnknownArchitecture,
|
|
|
|
Abi::OS::LinuxOS,
|
|
|
|
Abi::OSFlavor::AndroidLinuxFlavor,
|
|
|
|
Abi::BinaryFormat::ElfFormat,
|
|
|
|
0, androidAbi};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
FilePath AndroidManager::manifestSourcePath(const Target *target)
|
2015-01-27 18:46:40 +01:00
|
|
|
{
|
2018-12-05 10:29:48 +01:00
|
|
|
if (const ProjectNode *node = currentProjectNode(target)) {
|
2018-07-27 12:58:10 +02:00
|
|
|
const QString packageSource
|
2018-12-18 17:52:19 +01:00
|
|
|
= node->data(Android::Constants::AndroidPackageSourceDir).toString();
|
2018-05-31 10:51:37 +02:00
|
|
|
if (!packageSource.isEmpty()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath manifest = FilePath::fromUserInput(packageSource + "/AndroidManifest.xml");
|
2018-05-31 10:51:37 +02:00
|
|
|
if (manifest.exists())
|
|
|
|
return manifest;
|
|
|
|
}
|
2018-01-30 18:19:46 +01:00
|
|
|
}
|
2015-01-27 18:46:40 +01:00
|
|
|
return manifestPath(target);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
FilePath AndroidManager::manifestPath(const Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2019-04-03 18:10:35 +02:00
|
|
|
QVariant manifest = target->namedSettings(AndroidManifestName);
|
|
|
|
if (manifest.isValid())
|
2019-05-28 13:49:26 +02:00
|
|
|
return manifest.value<FilePath>();
|
2021-08-23 21:36:55 +03:00
|
|
|
return androidBuildDirectory(target).pathAppended(AndroidManifestName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void AndroidManager::setManifestPath(Target *target, const FilePath &path)
|
2019-04-03 18:10:35 +02:00
|
|
|
{
|
|
|
|
target->setNamedSettings(AndroidManifestName, QVariant::fromValue(path));
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
QString AndroidManager::deviceSerialNumber(const Target *target)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2014-06-25 15:42:11 +02:00
|
|
|
return target->namedSettings(AndroidDeviceSn).toString();
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
void AndroidManager::setDeviceSerialNumber(Target *target, const QString &deviceSerialNumber)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2020-07-01 18:10:02 +03:00
|
|
|
qCDebug(androidManagerLog) << "Target device serial changed:"
|
2018-06-18 11:49:14 +02:00
|
|
|
<< target->displayName() << deviceSerialNumber;
|
2014-06-25 15:42:11 +02:00
|
|
|
target->setNamedSettings(AndroidDeviceSn, deviceSerialNumber);
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:20:21 +02:00
|
|
|
static QString preferredAbi(const QStringList &appAbis, const Target *target)
|
2019-08-26 14:19:07 +03:00
|
|
|
{
|
|
|
|
const auto deviceAbis = target->namedSettings(AndroidDeviceAbis).toStringList();
|
|
|
|
for (const auto &abi : deviceAbis) {
|
|
|
|
if (appAbis.contains(abi))
|
|
|
|
return abi;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:20:21 +02:00
|
|
|
QString AndroidManager::apkDevicePreferredAbi(const Target *target)
|
2019-11-21 11:03:03 +02:00
|
|
|
{
|
2021-08-23 21:36:55 +03:00
|
|
|
auto libsPath = androidBuildDirectory(target).pathAppended("libs");
|
2020-11-27 19:39:20 +01:00
|
|
|
if (!libsPath.exists()) {
|
|
|
|
if (const ProjectNode *node = currentProjectNode(target))
|
|
|
|
return preferredAbi(node->data(Android::Constants::ANDROID_ABIS).toStringList(),
|
|
|
|
target);
|
|
|
|
}
|
2019-11-21 11:03:03 +02:00
|
|
|
QStringList apkAbis;
|
2021-05-28 18:22:44 +03:00
|
|
|
const auto libsPaths = QDir{libsPath.toString()}.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
for (const auto &abi : libsPaths)
|
2020-01-15 19:10:34 +01:00
|
|
|
if (!QDir{libsPath.pathAppended(abi).toString()}.entryList(QStringList("*.so"), QDir::Files | QDir::NoDotAndDotDot).isEmpty())
|
2019-11-21 11:03:03 +02:00
|
|
|
apkAbis << abi;
|
|
|
|
return preferredAbi(apkAbis, target);
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
void AndroidManager::setDeviceAbis(Target *target, const QStringList &deviceAbis)
|
2019-08-26 14:19:07 +03:00
|
|
|
{
|
|
|
|
target->setNamedSettings(AndroidDeviceAbis, deviceAbis);
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
int AndroidManager::deviceApiLevel(const Target *target)
|
2018-03-17 09:31:56 +02:00
|
|
|
{
|
|
|
|
return target->namedSettings(ApiLevelKey).toInt();
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
void AndroidManager::setDeviceApiLevel(Target *target, int level)
|
2018-03-17 09:31:56 +02:00
|
|
|
{
|
2020-07-01 18:10:02 +03:00
|
|
|
qCDebug(androidManagerLog) << "Target device API level changed:"
|
2018-06-18 11:49:14 +02:00
|
|
|
<< target->displayName() << level;
|
2018-03-17 09:31:56 +02:00
|
|
|
target->setNamedSettings(ApiLevelKey, level);
|
|
|
|
}
|
|
|
|
|
2021-08-16 20:19:46 +03:00
|
|
|
int AndroidManager::defaultMinimumSDK(const QtSupport::BaseQtVersion *qtVersion)
|
2013-08-14 13:39:45 +02:00
|
|
|
{
|
2021-08-16 20:19:46 +03:00
|
|
|
if (qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber{6, 0})
|
|
|
|
return 23;
|
|
|
|
else if (qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber{5, 13})
|
|
|
|
return 21;
|
|
|
|
else
|
|
|
|
return 16;
|
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");
|
2018-06-18 13:17:49 +02:00
|
|
|
case 27:
|
|
|
|
return QLatin1String("Android 8.1");
|
2018-11-22 14:17:11 +01:00
|
|
|
case 28:
|
|
|
|
return QLatin1String("Android 9");
|
2019-08-27 16:01:27 +03:00
|
|
|
case 29:
|
|
|
|
return QLatin1String("Android 10");
|
2020-02-20 14:42:12 +02:00
|
|
|
case 30:
|
|
|
|
return QLatin1String("Android 11");
|
2021-07-14 11:38:54 +03:00
|
|
|
case 31:
|
|
|
|
return QLatin1String("Android 12");
|
2013-08-14 13:39:45 +02:00
|
|
|
default:
|
2020-05-18 16:38:18 +02:00
|
|
|
return tr("Unknown Android version. API Level: %1").arg(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
|
|
|
{
|
2018-07-25 12:19:15 +02:00
|
|
|
QMessageBox::critical(nullptr, AndroidManager::tr("Error creating Android templates."), reason);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
static bool openXmlFile(QDomDocument &doc, const FilePath &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
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
static bool openManifest(const 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;
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
void AndroidManager::installQASIPackage(Target *target, const QString &packagePath)
|
2013-09-17 18:24:57 +02:00
|
|
|
{
|
2019-08-26 14:19:07 +03:00
|
|
|
const QStringList appAbis = AndroidManager::applicationAbis(target);
|
|
|
|
if (appAbis.isEmpty())
|
2013-10-09 16:24:25 +02:00
|
|
|
return;
|
2015-06-10 10:34:03 +02:00
|
|
|
const int deviceAPILevel = AndroidManager::minimumSDK(target);
|
2019-08-26 14:19:07 +03:00
|
|
|
AndroidDeviceInfo info = AndroidConfigurations::showDeviceDialog(target->project(), deviceAPILevel, appAbis);
|
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())
|
2020-12-01 14:54:29 +01:00
|
|
|
Core::MessageManager::writeDisrupting(tr("Starting Android virtual device failed."));
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
2018-08-07 11:12:45 +02:00
|
|
|
arguments << "install" << "-r " << packagePath;
|
|
|
|
QString error;
|
|
|
|
if (!runAdbCommandDetached(arguments, &error, true))
|
2020-12-01 14:54:29 +01:00
|
|
|
Core::MessageManager::writeDisrupting(
|
|
|
|
tr("Android package installation failed.\n%1").arg(error));
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AndroidManager::checkKeystorePassword(const QString &keystorePath, const QString &keystorePasswd)
|
|
|
|
{
|
|
|
|
if (keystorePasswd.isEmpty())
|
|
|
|
return false;
|
2019-06-06 16:27:55 +02:00
|
|
|
const CommandLine cmd(AndroidConfigurations::currentConfig().keytoolPath(),
|
|
|
|
{"-list", "-keystore", keystorePath, "--storepass", keystorePasswd});
|
2021-06-22 04:33:47 +02:00
|
|
|
QtcProcess proc;
|
2016-04-29 16:52:58 +02:00
|
|
|
proc.setTimeoutS(10);
|
2021-05-17 12:02:42 +02:00
|
|
|
proc.setCommand(cmd);
|
2021-05-20 13:14:15 +02:00
|
|
|
proc.setProcessUserEventWhileRunning();
|
|
|
|
proc.runBlocking();
|
2021-05-28 13:29:05 +02:00
|
|
|
return proc.result() == QtcProcess::FinishedWithSuccess;
|
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;
|
|
|
|
|
2021-06-22 04:33:47 +02:00
|
|
|
QtcProcess proc;
|
2016-04-29 16:52:58 +02:00
|
|
|
proc.setTimeoutS(10);
|
2021-05-17 12:02:42 +02:00
|
|
|
proc.setCommand({AndroidConfigurations::currentConfig().keytoolPath(), arguments});
|
2021-05-20 13:14:15 +02:00
|
|
|
proc.setProcessUserEventWhileRunning();
|
|
|
|
proc.runBlocking();
|
2021-05-28 13:29:05 +02:00
|
|
|
return proc.result() == QtcProcess::FinishedWithSuccess;
|
2017-01-10 16:33:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-06-22 04:33:47 +02:00
|
|
|
QtcProcess proc;
|
2017-01-10 16:33:56 +01:00
|
|
|
proc.setTimeoutS(10);
|
2021-05-17 12:02:42 +02:00
|
|
|
proc.setCommand({AndroidConfigurations::currentConfig().keytoolPath(), arguments});
|
2021-05-20 13:14:15 +02:00
|
|
|
proc.setProcessUserEventWhileRunning();
|
|
|
|
proc.runBlocking();
|
2021-05-28 13:29:05 +02:00
|
|
|
return proc.result() == QtcProcess::FinishedWithSuccess;
|
2013-09-17 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 12:19:15 +02:00
|
|
|
using GradleProperties = QMap<QByteArray, QByteArray>;
|
2014-09-22 16:20:51 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 16:38:18 +02:00
|
|
|
bool AndroidManager::updateGradleProperties(Target *target, const QString &buildKey)
|
2014-09-22 16:20:51 +03:00
|
|
|
{
|
2019-02-06 12:50:51 +01:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(target->kit());
|
2014-09-22 16:20:51 +03:00
|
|
|
if (!version)
|
|
|
|
return false;
|
|
|
|
|
2019-08-01 10:12:34 +02:00
|
|
|
QString key = buildKey;
|
|
|
|
if (key.isEmpty()) {
|
|
|
|
// FIXME: This case is triggered from AndroidBuildApkWidget::createApplicationGroup
|
|
|
|
// and should be avoided.
|
|
|
|
if (RunConfiguration *rc = target->activeRunConfiguration())
|
|
|
|
key = rc->buildKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
QTC_ASSERT(!key.isEmpty(), return false);
|
|
|
|
const ProjectNode *node = target->project()->findNodeForBuildKey(key);
|
2018-12-05 10:29:48 +01:00
|
|
|
if (!node)
|
2018-05-09 09:55:37 +02:00
|
|
|
return false;
|
2014-09-22 16:20:51 +03:00
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
const QString sourceDirName = node->data(Constants::AndroidPackageSourceDir).toString();
|
|
|
|
QFileInfo sourceDirInfo(sourceDirName);
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath packageSourceDir = FilePath::fromString(sourceDirInfo.canonicalFilePath())
|
2019-05-20 17:28:20 +02:00
|
|
|
.pathAppended("gradlew");
|
|
|
|
if (!packageSourceDir.exists())
|
2014-09-22 16:20:51 +03:00
|
|
|
return false;
|
|
|
|
|
2020-02-19 17:35:56 +01:00
|
|
|
const FilePath wrapperProps = packageSourceDir / "gradle/wrapper/gradle-wrapper.properties";
|
2016-01-05 15:48:51 +02:00
|
|
|
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();
|
2020-02-19 17:35:56 +01:00
|
|
|
const FilePath localPropertiesFile = packageSourceDir / "local.properties";
|
2019-05-20 17:28:20 +02:00
|
|
|
if (!mergeGradleProperties(localPropertiesFile.toString(), localProperties))
|
2014-09-22 16:20:51 +03:00
|
|
|
return false;
|
|
|
|
|
2019-05-20 17:28:20 +02:00
|
|
|
const QString gradlePropertiesPath = packageSourceDir.pathAppended("gradle.properties").toString();
|
2014-09-22 16:20:51 +03:00
|
|
|
GradleProperties gradleProperties = readGradleProperties(gradlePropertiesPath);
|
2019-09-30 14:34:31 +02:00
|
|
|
gradleProperties["qt5AndroidDir"] = (version->prefix().toString() + "/src/android/java")
|
|
|
|
.toLocal8Bit();
|
2014-09-22 16:20:51 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-08-07 11:12:45 +02:00
|
|
|
QProcess *AndroidManager::runAdbCommandDetached(const QStringList &args, QString *err,
|
|
|
|
bool deleteOnFinish)
|
2018-07-03 11:51:28 +02:00
|
|
|
{
|
2018-08-07 11:12:45 +02:00
|
|
|
std::unique_ptr<QProcess> p(new QProcess);
|
2018-07-03 11:51:28 +02:00
|
|
|
const QString adb = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
2019-12-05 10:32:35 +01:00
|
|
|
qCDebug(androidManagerLog) << "Running command (async):" << CommandLine(adb, args).toUserOutput();
|
2018-08-07 11:12:45 +02:00
|
|
|
p->start(adb, args);
|
|
|
|
if (p->waitForStarted(500) && p->state() == QProcess::Running) {
|
|
|
|
if (deleteOnFinish) {
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(p.get(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
2018-08-07 11:12:45 +02:00
|
|
|
p.get(), &QObject::deleteLater);
|
|
|
|
}
|
|
|
|
return p.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString errorStr = QString::fromUtf8(p->readAllStandardError());
|
2019-12-05 10:32:35 +01:00
|
|
|
qCDebug(androidManagerLog) << "Running command (async) failed:"
|
|
|
|
<< CommandLine(adb, args).toUserOutput()
|
|
|
|
<< "Output:" << errorStr;
|
2018-08-07 11:12:45 +02:00
|
|
|
if (err)
|
|
|
|
*err = errorStr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-06 16:27:55 +02:00
|
|
|
SdkToolResult AndroidManager::runCommand(const CommandLine &command,
|
2018-08-07 11:12:45 +02:00
|
|
|
const QByteArray &writeData, int timeoutS)
|
|
|
|
{
|
|
|
|
Android::SdkToolResult cmdResult;
|
2021-06-22 04:33:47 +02:00
|
|
|
QtcProcess cmdProc;
|
2018-08-07 11:12:45 +02:00
|
|
|
cmdProc.setTimeoutS(timeoutS);
|
2021-05-06 17:54:28 +02:00
|
|
|
cmdProc.setWriteData(writeData);
|
2019-12-05 10:32:35 +01:00
|
|
|
qCDebug(androidManagerLog) << "Running command (sync):" << command.toUserOutput();
|
2021-05-17 12:02:42 +02:00
|
|
|
cmdProc.setCommand(command);
|
2021-05-20 13:14:15 +02:00
|
|
|
cmdProc.setProcessUserEventWhileRunning();
|
|
|
|
cmdProc.runBlocking();
|
2021-05-12 14:25:50 +02:00
|
|
|
cmdResult.m_stdOut = cmdProc.stdOut().trimmed();
|
|
|
|
cmdResult.m_stdErr = cmdProc.stdErr().trimmed();
|
2021-05-28 13:19:38 +02:00
|
|
|
cmdResult.m_success = cmdProc.result() == QtcProcess::FinishedWithSuccess;
|
2020-07-01 18:10:02 +03:00
|
|
|
qCDebug(androidManagerLog) << "Command finshed (sync):" << command.toUserOutput()
|
2018-08-07 11:12:45 +02:00
|
|
|
<< "Success:" << cmdResult.m_success
|
2021-05-12 14:25:50 +02:00
|
|
|
<< "Output:" << cmdProc.allRawOutput();
|
2018-08-07 11:12:45 +02:00
|
|
|
if (!cmdResult.success())
|
2021-05-14 13:12:46 +02:00
|
|
|
cmdResult.m_exitMessage = cmdProc.exitMessage();
|
2018-08-07 11:12:45 +02:00
|
|
|
return cmdResult;
|
2018-07-03 11:51:28 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 11:12:45 +02:00
|
|
|
SdkToolResult AndroidManager::runAdbCommand(const QStringList &args,
|
|
|
|
const QByteArray &writeData, int timeoutS)
|
2018-07-03 11:51:28 +02:00
|
|
|
{
|
2019-06-06 16:27:55 +02:00
|
|
|
return runCommand({AndroidConfigurations::currentConfig().adbToolPath(), args},
|
2018-08-07 11:12:45 +02:00
|
|
|
writeData, timeoutS);
|
2018-07-03 11:51:28 +02:00
|
|
|
}
|
2013-10-16 11:02:37 +02:00
|
|
|
} // namespace Android
|