Android: Add option to set the build-tools version in project settings

Allow QC to directly set the build-tools version for the project.
Such setting could be in qmake/cmake, however, ideally this value
should be the latest available version, and doesn't need to be written
to the project file. Thus, it is convenient to have this selectable
from QC UI for convience, while developing.

Apart from the first reason for avoiding writing this into the project
file, there is QC limitation which doesn't allow writing such value
to CMake project file.

Task-number: QTBUG-97002
Change-Id: I5d54d36f7900f8445359188d6ae7a8ba14bd3a05
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Assam Boudjelthia
2021-10-03 22:15:33 +03:00
parent b1ef25b208
commit 5bbc7ea0f5
5 changed files with 77 additions and 2 deletions

View File

@@ -71,6 +71,7 @@ static Q_LOGGING_CATEGORY(buildapkstepLog, "qtc.android.build.androidbuildapkste
const char KeystoreLocationKey[] = "KeystoreLocation";
const char BuildTargetSdkKey[] = "BuildTargetSdk";
const char BuildToolsVersionKey[] = "BuildToolsVersion";
const char VerboseOutputKey[] = "VerboseOutput";
class PasswordInputDialog : public QDialog
@@ -167,8 +168,29 @@ QWidget *AndroidBuildApkWidget::createApplicationGroup()
const QString sdk = targetSDKComboBox->itemText(idx);
m_step->setBuildTargetSdk(sdk);
});
targetSDKComboBox->setCurrentIndex(targets.indexOf(m_step->buildTargetSdk()));
const QList<QVersionNumber> buildToolsVersions = Utils::transform(
AndroidConfigurations::sdkManager()->filteredBuildTools(minApiSupported),
[](const BuildTools *pkg) {
return pkg->revision();
});
auto buildToolsSdkComboBox = new QComboBox();
for (const QVersionNumber &version : buildToolsVersions)
buildToolsSdkComboBox->addItem(version.toString(), QVariant::fromValue(version));
connect(buildToolsSdkComboBox, &QComboBox::activated, this,
[this, buildToolsSdkComboBox](int idx) {
m_step->setBuildToolsVersion(buildToolsSdkComboBox->itemData(idx).value<QVersionNumber>());
});
const int initIdx = (m_step->buildToolsVersion().majorVersion() < 1)
? buildToolsVersions.indexOf(buildToolsVersions.last())
: buildToolsVersions.indexOf(m_step->buildToolsVersion());
buildToolsSdkComboBox->setCurrentIndex(initIdx);
auto formLayout = new QFormLayout(group);
formLayout->addRow(Tr::tr("Android build-tools version:"), buildToolsSdkComboBox);
formLayout->addRow(Tr::tr("Android build platform SDK:"), targetSDKComboBox);
auto createAndroidTemplatesButton = new QPushButton(Tr::tr("Create Templates"));
@@ -540,6 +562,8 @@ bool AndroidBuildApkStep::init()
return false;
}
updateBuildToolsVersionInJsonFile();
QStringList arguments = {"--input", m_inputFile.toString(),
"--output", outputDir.toString(),
"--android-platform", m_buildTargetSdk,
@@ -841,11 +865,28 @@ void AndroidBuildApkStep::reportWarningOrError(const QString &message, Task::Tas
TaskHub::addTask(BuildSystemTask(type, message));
}
void AndroidBuildApkStep::updateBuildToolsVersionInJsonFile()
{
expected_str<QByteArray> contents = m_inputFile.fileContents();
if (!contents)
return;
QRegularExpression regex(QLatin1String("\"sdkBuildToolsRevision\":.\"[0-9.]+\""));
QRegularExpressionMatch match = regex.match(QString::fromUtf8(contents.value()));
const QString version = buildToolsVersion().toString();
if (match.hasMatch() && !version.isEmpty()) {
const auto newStr = QLatin1String("\"sdkBuildToolsRevision\": \"%1\"").arg(version).toUtf8();
contents->replace(match.captured(0).toUtf8(), newStr);
m_inputFile.writeFileContents(contents.value());
}
}
bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
{
m_keystorePath = FilePath::fromSettings(map.value(KeystoreLocationKey));
m_signPackage = false; // don't restore this
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
m_buildToolsVersion = QVersionNumber::fromString(map.value(BuildToolsVersionKey).toString());
if (m_buildTargetSdk.isEmpty()) {
m_buildTargetSdk = AndroidConfig::apiLevelNameFor(AndroidConfigurations::
sdkManager()->latestAndroidSdkPlatform());
@@ -859,6 +900,7 @@ QVariantMap AndroidBuildApkStep::toMap() const
QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap();
map.insert(KeystoreLocationKey, m_keystorePath.toSettings());
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
map.insert(BuildToolsVersionKey, m_buildToolsVersion.toString());
map.insert(VerboseOutputKey, m_verbose);
return map;
}
@@ -878,6 +920,16 @@ void AndroidBuildApkStep::setBuildTargetSdk(const QString &sdk)
m_buildTargetSdk = sdk;
}
QVersionNumber AndroidBuildApkStep::buildToolsVersion() const
{
return m_buildToolsVersion;
}
void AndroidBuildApkStep::setBuildToolsVersion(const QVersionNumber &version)
{
m_buildToolsVersion = version;
}
void AndroidBuildApkStep::stdError(const QString &output)
{
QString newOutput = output;