Android: More accurate Android Sdk location error messages

If the user installs a fresh Android SDK and selects its path in
the Android options, Qt Creator will still say that this is not
a valid Android SDK.

The reason is that Qt Creator also checks for the platform tools
to be installed. Installing those is a separate step which needs
to be done after installing the SDK.

This patch enables Qt Creator to tell the user if the platform
tools are missing, but the SDK is otherwise fine.

Change-Id: I3557fb93d46e8677498843250302d12c8babb1df
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
This commit is contained in:
Alessandro Portale
2014-03-04 23:38:21 +01:00
parent c375436847
commit c1b2ed036f
2 changed files with 25 additions and 14 deletions

View File

@@ -155,21 +155,11 @@ void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
{ {
if (mode & Sdk) { if (mode & Sdk) {
m_sdkState = Okay; m_sdkState = Okay;
if (m_androidConfig.sdkLocation().isEmpty()) { if (m_androidConfig.sdkLocation().isEmpty())
m_sdkState = NotSet; m_sdkState = NotSet;
} else { else if (!(sdkLocationIsValid() && sdkPlatformToolsInstalled()))
Utils::FileName adb = m_androidConfig.sdkLocation();
Utils::FileName androidExe = m_androidConfig.sdkLocation();
Utils::FileName androidBat = m_androidConfig.sdkLocation();
Utils::FileName emulator = m_androidConfig.sdkLocation();
if (!adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists()
|| (!androidExe.appendPath(QLatin1String("/tools/android" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists()
&& !androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).toFileInfo().exists())
|| !emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists()) {
m_sdkState = Error; m_sdkState = Error;
} }
}
}
if (mode & Ndk) { if (mode & Ndk) {
m_ndkState = Okay; m_ndkState = Okay;
@@ -241,6 +231,9 @@ void AndroidSettingsWidget::applyToUi(AndroidSettingsWidget::Mode mode)
m_ui->sdkWarningIconLabel->setVisible(true); m_ui->sdkWarningIconLabel->setVisible(true);
m_ui->sdkWarningLabel->setVisible(true); m_ui->sdkWarningLabel->setVisible(true);
Utils::FileName location = Utils::FileName::fromUserInput(m_ui->SDKLocationLineEdit->text()); Utils::FileName location = Utils::FileName::fromUserInput(m_ui->SDKLocationLineEdit->text());
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(tr("\"%1\" does not seem to be an Android SDK top folder.").arg(location.toUserOutput()));
} else { } else {
m_ui->sdkWarningIconLabel->setVisible(false); m_ui->sdkWarningIconLabel->setVisible(false);
@@ -300,6 +293,22 @@ void AndroidSettingsWidget::applyToUi(AndroidSettingsWidget::Mode mode)
} }
} }
bool AndroidSettingsWidget::sdkLocationIsValid() 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)).toFileInfo().exists()
|| androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).toFileInfo().exists())
&& emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
}
bool AndroidSettingsWidget::sdkPlatformToolsInstalled() const
{
Utils::FileName adb = m_androidConfig.sdkLocation();
return adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
}
void AndroidSettingsWidget::saveSettings() void AndroidSettingsWidget::saveSettings()
{ {
sdkLocationEditingFinished(); sdkLocationEditingFinished();

View File

@@ -98,6 +98,8 @@ private:
enum State { NotSet = 0, Okay = 1, Error = 2 }; enum State { NotSet = 0, Okay = 1, Error = 2 };
void check(Mode mode); void check(Mode mode);
void applyToUi(Mode mode); void applyToUi(Mode mode);
bool sdkLocationIsValid() const;
bool sdkPlatformToolsInstalled() const;
State m_sdkState; State m_sdkState;
State m_ndkState; State m_ndkState;