forked from qt-creator/qt-creator
Android: Remove gradle.properties file handling
The modification of gradle.properties files was originally a feature of the Android plugin which eventually moved over to androiddeployqt. Moreover, this code got accidentally disabled in Qt Creator 4.10 and was appartently not missed till now. I only noticed it while "FilePath- ifying" code in the Andsroid plugin. This change removes the gradle.properties file handling code from Qt Creator. Fixes: QTCREATORBUG-28494 Change-Id: Id4f2722f4965c877a065386b34a71d8368147b08 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
@@ -166,7 +166,6 @@ QWidget *AndroidBuildApkWidget::createApplicationGroup()
|
||||
connect(targetSDKComboBox, &QComboBox::activated, this, [this, targetSDKComboBox](int idx) {
|
||||
const QString sdk = targetSDKComboBox->itemText(idx);
|
||||
m_step->setBuildTargetSdk(sdk);
|
||||
AndroidManager::updateGradleProperties(m_step->target(), QString()); // FIXME: Use real key.
|
||||
});
|
||||
|
||||
auto formLayout = new QFormLayout(group);
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <cmakeprojectmanager/cmakeprojectconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -619,126 +620,6 @@ bool AndroidManager::checkCertificateExists(const FilePath &keystorePath,
|
||||
return proc.result() == ProcessResult::FinishedWithSuccess;
|
||||
}
|
||||
|
||||
using GradleProperties = QMap<QByteArray, QByteArray>;
|
||||
|
||||
static GradleProperties readGradleProperties(const QString &path)
|
||||
{
|
||||
GradleProperties properties;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return properties;
|
||||
|
||||
const QList<QByteArray> lines = file.readAll().split('\n');
|
||||
for (const QByteArray &line : lines) {
|
||||
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) {
|
||||
const auto it = properties.constFind(prop.at(0).trimmed());
|
||||
if (it != properties.constEnd()) {
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
for (GradleProperties::const_iterator it = properties.constBegin(); it != properties.constEnd();
|
||||
++it)
|
||||
file.write(it.key() + '=' + it.value() + '\n');
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AndroidManager::updateGradleProperties(Target *target, const QString &buildKey)
|
||||
{
|
||||
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(target->kit());
|
||||
if (!version)
|
||||
return false;
|
||||
|
||||
QString key = buildKey;
|
||||
if (key.isEmpty()) {
|
||||
// FIXME: This case is triggered from AndroidBuildApkWidget::createApplicationGroup
|
||||
// and should be avoided.
|
||||
key = target->activeBuildKey();
|
||||
}
|
||||
|
||||
QTC_ASSERT(!key.isEmpty(), return false);
|
||||
const ProjectNode *node = target->project()->findNodeForBuildKey(key);
|
||||
if (!node)
|
||||
return false;
|
||||
|
||||
const QString sourceDirName = node->data(Constants::AndroidPackageSourceDir).toString();
|
||||
QFileInfo sourceDirInfo(sourceDirName);
|
||||
const FilePath packageSourceDir = FilePath::fromString(sourceDirInfo.canonicalFilePath());
|
||||
|
||||
const FilePath gradleWFile = packageSourceDir / "gradlew";
|
||||
if (!gradleWFile.exists())
|
||||
return false;
|
||||
|
||||
const FilePath wrapperProps = packageSourceDir / "gradle/wrapper/gradle-wrapper.properties";
|
||||
if (wrapperProps.exists()) {
|
||||
GradleProperties wrapperProperties = readGradleProperties(wrapperProps.toString());
|
||||
QString distributionUrl = QString::fromLocal8Bit(wrapperProperties["distributionUrl"]);
|
||||
// Update only old gradle distributionUrl
|
||||
if (distributionUrl.endsWith(QLatin1String("distributions/gradle-1.12-all.zip"))) {
|
||||
wrapperProperties["distributionUrl"] = "https\\://services.gradle.org/distributions/gradle-2.2.1-all.zip";
|
||||
mergeGradleProperties(wrapperProps.toString(), wrapperProperties);
|
||||
}
|
||||
}
|
||||
|
||||
GradleProperties localProperties;
|
||||
localProperties["sdk.dir"] = AndroidConfigurations::currentConfig().sdkLocation().toString().toLocal8Bit();
|
||||
const FilePath localPropertiesFile = packageSourceDir / "local.properties";
|
||||
if (!mergeGradleProperties(localPropertiesFile.toString(), localProperties))
|
||||
return false;
|
||||
|
||||
const QString gradlePropertiesPath = packageSourceDir.pathAppended("gradle.properties").toString();
|
||||
GradleProperties gradleProperties = readGradleProperties(gradlePropertiesPath);
|
||||
gradleProperties["qt5AndroidDir"] = (version->prefix().toString() + "/src/android/java")
|
||||
.toLocal8Bit();
|
||||
gradleProperties["buildDir"] = ".build";
|
||||
gradleProperties["androidCompileSdkVersion"] = buildTargetSDK(target).split(QLatin1Char('-')).last().toLocal8Bit();
|
||||
if (gradleProperties["androidBuildToolsVersion"].isEmpty()) {
|
||||
QVersionNumber buildtoolVersion = AndroidConfigurations::currentConfig().buildToolsVersion();
|
||||
if (buildtoolVersion.isNull())
|
||||
return false;
|
||||
gradleProperties["androidBuildToolsVersion"] = buildtoolVersion.toString().toLocal8Bit();
|
||||
}
|
||||
return mergeGradleProperties(gradlePropertiesPath, gradleProperties);
|
||||
}
|
||||
|
||||
QProcess *AndroidManager::runAdbCommandDetached(const QStringList &args, QString *err,
|
||||
bool deleteOnFinish)
|
||||
{
|
||||
|
@@ -94,7 +94,6 @@ public:
|
||||
const QString &alias, const QString &certificatePasswd);
|
||||
static bool checkCertificateExists(const Utils::FilePath &keystorePath,
|
||||
const QString &keystorePasswd, const QString &alias);
|
||||
static bool updateGradleProperties(ProjectExplorer::Target *target, const QString &buildKey);
|
||||
|
||||
static QProcess *runAdbCommandDetached(const QStringList &args, QString *err = nullptr,
|
||||
bool deleteOnFinish = false);
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "androidconstants.h"
|
||||
#include "androidglobal.h"
|
||||
#include "androidmanager.h"
|
||||
#include "androidrunconfiguration.h"
|
||||
#include "androidtoolchain.h"
|
||||
#include "androidtr.h"
|
||||
@@ -83,11 +82,10 @@ AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Utils::Id id)
|
||||
postStartShellCmdAspect->setSettingsKey("Android.PostStartShellCmdListKey");
|
||||
postStartShellCmdAspect->setLabelText(Tr::tr("Post-quit on-device shell commands:"));
|
||||
|
||||
setUpdater([this, target] {
|
||||
setUpdater([this] {
|
||||
const BuildTargetInfo bti = buildTargetInfo();
|
||||
setDisplayName(bti.displayName);
|
||||
setDefaultDisplayName(bti.displayName);
|
||||
AndroidManager::updateGradleProperties(target, buildKey());
|
||||
});
|
||||
|
||||
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
||||
|
@@ -293,11 +293,8 @@ void CreateAndroidManifestWizard::createAndroidTemplateFiles()
|
||||
QTC_ASSERT(gradlePath.exists(), return);
|
||||
FileUtils::copyRecursively(gradlePath, m_directory, nullptr, copy);
|
||||
}
|
||||
|
||||
AndroidManager::updateGradleProperties(target, m_buildKey);
|
||||
}
|
||||
|
||||
|
||||
QString androidPackageDir;
|
||||
ProjectNode *node = target->project()->findNodeForBuildKey(m_buildKey);
|
||||
if (node) {
|
||||
|
Reference in New Issue
Block a user