Commit 27e740ca authored by Vikas Pachdha's avatar Vikas Pachdha
Browse files

Android: Extend Android SDK sanity



Verify the essential tools and packages required for development

Task-number: QTCREATORBUG-18837
Change-Id: Ie89e8fcf3bf75f1db9cc5eac50859cf6f3e5fafd
Reviewed-by: default avatarBogDan Vatra <bogdan@kdab.com>
Reviewed-by: Riitta-Leena Miettinen's avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
parent afc0192c
......@@ -775,6 +775,17 @@ QVersionNumber AndroidConfig::sdkToolsVersion() const
return version;
}
QVersionNumber AndroidConfig::buildToolsVersion() const
{
QVersionNumber maxVersion;
Utils::FileName buildtoolsDir = m_sdkLocation;
buildtoolsDir.appendPath("build-tools");
QDir buildToolsDir(buildtoolsDir.toString());
for (const QFileInfo &file: buildToolsDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot))
maxVersion = qMax(maxVersion, QVersionNumber::fromString(file.fileName()));
return maxVersion;
}
FileName AndroidConfig::ndkLocation() const
{
return m_ndkLocation;
......
......@@ -113,6 +113,7 @@ public:
Utils::FileName sdkLocation() const;
void setSdkLocation(const Utils::FileName &sdkLocation);
QVersionNumber sdkToolsVersion() const;
QVersionNumber buildToolsVersion() const;
Utils::FileName ndkLocation() const;
QVersionNumber ndkVersion() const;
......
......@@ -570,16 +570,10 @@ bool AndroidManager::updateGradleProperties(ProjectExplorer::Target *target)
gradleProperties["buildDir"] = ".build";
gradleProperties["androidCompileSdkVersion"] = buildTargetSDK(target).split(QLatin1Char('-')).last().toLocal8Bit();
if (gradleProperties["androidBuildToolsVersion"].isEmpty()) {
QVersionNumber maxVersion;
QDir buildToolsDir(AndroidConfigurations::currentConfig().sdkLocation().appendPath(QLatin1String("build-tools")).toString());
foreach (const QFileInfo &file, buildToolsDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot)) {
QVersionNumber ver = QVersionNumber::fromString(file.fileName());
if (maxVersion < ver)
maxVersion = ver;
}
if (maxVersion.isNull())
QVersionNumber buildtoolVersion = AndroidConfigurations::currentConfig().buildToolsVersion();
if (buildtoolVersion.isNull())
return false;
gradleProperties["androidBuildToolsVersion"] = maxVersion.toString().toLocal8Bit();
gradleProperties["androidBuildToolsVersion"] = buildtoolVersion.toString().toLocal8Bit();
}
return mergeGradleProperties(gradlePropertiesPath, gradleProperties);
}
......
......@@ -287,11 +287,7 @@ static QPair<QStringList, bool> checkGdbForBrokenPython(const QStringList &paths
void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
{
if (mode & Sdk) {
m_sdkState = Okay;
if (m_androidConfig.sdkLocation().isEmpty())
m_sdkState = NotSet;
else if (!(sdkLocationIsValid() && sdkPlatformToolsInstalled()))
m_sdkState = Error;
m_sdkState = verifySdkInstallation(&m_sdkInstallationError) ? Okay : Error;
}
if (mode & Ndk) {
......@@ -386,11 +382,7 @@ void AndroidSettingsWidget::applyToUi(AndroidSettingsWidget::Mode mode)
if (m_sdkState == Error) {
m_ui->sdkWarningIconLabel->setVisible(true);
m_ui->sdkWarningLabel->setVisible(true);
Utils::FileName location = Utils::FileName::fromUserInput(m_ui->SDKLocationPathChooser->rawPath());
if (sdkLocationIsValid())
m_ui->sdkWarningLabel->setText(tr("The Platform tools are missing. Please use the Android SDK Manager to install them."));
else
m_ui->sdkWarningLabel->setText(tr("\"%1\" does not seem to be an Android SDK top folder.").arg(location.toUserOutput()));
m_ui->sdkWarningLabel->setText(m_sdkInstallationError);
} else {
m_ui->sdkWarningIconLabel->setVisible(false);
m_ui->sdkWarningLabel->setVisible(false);
......@@ -488,20 +480,42 @@ void AndroidSettingsWidget::updateGradleBuildUi()
m_androidConfig.useGrandle());
}
bool AndroidSettingsWidget::sdkLocationIsValid() const
bool AndroidSettingsWidget::verifySdkInstallation(QString *errorDetails) const
{
Utils::FileName androidExe = m_androidConfig.sdkLocation();
Utils::FileName androidBat = m_androidConfig.sdkLocation();
Utils::FileName emulator = m_androidConfig.sdkLocation();
return (androidExe.appendPath(QLatin1String("/tools/android" QTC_HOST_EXE_SUFFIX)).exists()
|| androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).exists())
&& emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).exists();
}
if (m_androidConfig.sdkLocation().isEmpty()) {
if (errorDetails)
*errorDetails = tr("Android SDK path not set.");
return false;
}
bool AndroidSettingsWidget::sdkPlatformToolsInstalled() const
{
Utils::FileName adb = m_androidConfig.sdkLocation();
return adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).exists();
if (!m_androidConfig.sdkLocation().exists()) {
if (errorDetails)
*errorDetails = tr("Android SDK path does not exist.");
return false;
}
if (m_androidConfig.sdkToolsVersion().isNull()) {
if (errorDetails)
*errorDetails = tr("The SDK path does not seem to be a valid Android SDK top folder.");
return false;
}
QStringList missingComponents;
if (!m_androidConfig.adbToolPath().exists())
missingComponents << "Platform Tools";
if (m_androidConfig.buildToolsVersion().isNull())
missingComponents << "Build Tools";
if (m_androidConfig.sdkTargets().isEmpty())
missingComponents << "Platform SDK";
if (!missingComponents.isEmpty() && errorDetails) {
*errorDetails = tr("Android SDK components missing (%1).\nUse Android SDK Manager to "
"manage SDK components.").arg(missingComponents.join(", "));
}
return missingComponents.isEmpty();
}
void AndroidSettingsWidget::saveSettings()
......
......@@ -100,15 +100,15 @@ private:
private:
enum Mode { Sdk = 1, Ndk = 2, Java = 4, All = Sdk | Ndk | Java };
enum State { NotSet = 0, Okay = 1, Error = 2 };
bool verifySdkInstallation(QString *errorDetails = nullptr) const;
void check(Mode mode);
void applyToUi(Mode mode);
bool sdkLocationIsValid() const;
bool sdkPlatformToolsInstalled() const;
void startUpdateAvd();
void enableAvdControls();
void disableAvdControls();
State m_sdkState;
QString m_sdkInstallationError;
State m_ndkState;
QString m_ndkErrorMessage;
int m_ndkCompilerCount;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment