Android: update gradle wrapper properties

We need to call it when QmakeProject emits proFilesEvaluated to be sure
AndroidPackageSourceDir is set.

Task-number: QTCREATORBUG-15568
Change-Id: Ia70e0cff1b5fb8f2003ba2c2799a694873b2ad19
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
BogDan Vatra
2016-01-05 15:48:51 +02:00
parent 4c16632f8e
commit 6ff1296822
2 changed files with 24 additions and 1 deletions

View File

@@ -700,9 +700,21 @@ bool AndroidManager::updateGradleProperties(ProjectExplorer::Target *target)
AndroidBuildApkStep *buildApkStep
= AndroidGlobal::buildStep<AndroidBuildApkStep>(target->activeBuildConfiguration());
if (!buildApkStep || !buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradlew")).exists())
if (!buildApkStep || !buildApkStep->useGradle() || !buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("gradlew")).exists())
return false;
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"]);
QRegExp re(QLatin1String(".*services.gradle.org/distributions/gradle-2..*.zip"));
if (!re.exactMatch(distributionUrl)) {
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();
if (!mergeGradleProperties(buildApkStep->androidPackageSourceDir().appendPath(QLatin1String("local.properties")).toString(), localProperties))

View File

@@ -39,8 +39,10 @@
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakebuildinfo.h>
#include <qmakeprojectmanager/qmakeproject.h>
using namespace QmakeAndroidSupport::Internal;
@@ -96,7 +98,16 @@ ProjectExplorer::BuildConfiguration *AndroidQmakeBuildConfigurationFactory::rest
AndroidQmakeBuildConfiguration::AndroidQmakeBuildConfiguration(ProjectExplorer::Target *target)
: QmakeProjectManager::QmakeBuildConfiguration(target)
{
using QmakeProjectManager::QmakeProject;
auto updateGrade = [this] {
Android::AndroidManager::updateGradleProperties(BuildConfiguration::target());
};
QmakeProject *project = qobject_cast<QmakeProject *>(target->project());
if (project)
connect(project, &QmakeProject::proFilesEvaluated, this, updateGrade);
else
connect(this, &AndroidQmakeBuildConfiguration::enabledChanged, this, updateGrade);
}
AndroidQmakeBuildConfiguration::AndroidQmakeBuildConfiguration(ProjectExplorer::Target *target, AndroidQmakeBuildConfiguration *source)