Commit 3881ff94 authored by Vikas Pachdha's avatar Vikas Pachdha

Android: Fix sdkmanager timing out on slower machines

sdkmanager times out on slower machines or with slower network
connection. Increase the timeout and show timeout message box

Task-number: QTCREATORBUG-18458
Change-Id: I9118024ec1438ef9c18842df2f7431e696c73f92
Reviewed-by: Riitta-Leena Miettinen's avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 7d884710
......@@ -347,7 +347,9 @@ void AndroidConfig::updateAvailableSdkPlatforms() const
m_availableSdkPlatforms.clear();
AndroidSdkManager sdkManager(*this);
m_availableSdkPlatforms = sdkManager.availableSdkPlatforms();
bool success = false;
m_availableSdkPlatforms = sdkManager.availableSdkPlatforms(&success);
if (success)
m_availableSdkPlatformsUpToDate = true;
}
......@@ -358,7 +360,7 @@ QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms)
QString AndroidConfig::apiLevelNameFor(const SdkPlatform &platform)
{
return QLatin1String("android-") + QString::number(platform.apiLevel);
return platform.apiLevel > 0 ? QString("android-%1").arg(platform.apiLevel) : "";
}
QList<SdkPlatform> AndroidConfig::sdkTargets(int minApiLevel) const
......
......@@ -50,6 +50,8 @@ const char installLocationKey[] = "Installed Location:";
const char apiLevelPropertyKey[] = "AndroidVersion.ApiLevel";
const char abiPropertyKey[] = "SystemImage.Abi";
const int sdkManagerCmdTimeoutS = 60;
using namespace Utils;
/*!
......@@ -72,11 +74,14 @@ static bool valueForKey(QString key, const QString &line, QString *value = nullp
\c true if the command is successfully executed. Output is copied into \a output. The function
blocks the calling thread.
*/
static bool sdkManagerCommand(const AndroidConfig config, const QStringList &args, QString *output)
static bool sdkManagerCommand(const AndroidConfig config, const QStringList &args, QString *output,
int timeout = sdkManagerCmdTimeoutS)
{
QString sdkManagerToolPath = config.sdkManagerToolPath().toString();
SynchronousProcess proc;
SynchronousProcessResponse response = proc.runBlocking(sdkManagerToolPath, args);
proc.setTimeoutS(timeout);
proc.setTimeOutMessageBoxEnabled(true);
SynchronousProcessResponse response = proc.run(sdkManagerToolPath, args);
if (response.result == SynchronousProcessResponse::Finished) {
if (output)
*output = response.allOutput();
......@@ -132,10 +137,6 @@ AndroidSdkManager::AndroidSdkManager(const AndroidConfig &config):
m_config(config),
m_parser(new SdkManagerOutputParser)
{
QString packageListing;
if (sdkManagerCommand(config, QStringList({"--list", "--verbose"}), &packageListing)) {
m_parser->parsePackageListing(packageListing);
}
}
AndroidSdkManager::~AndroidSdkManager()
......@@ -143,13 +144,20 @@ AndroidSdkManager::~AndroidSdkManager()
}
SdkPlatformList AndroidSdkManager::availableSdkPlatforms()
SdkPlatformList AndroidSdkManager::availableSdkPlatforms(bool *ok)
{
bool success = false;
if (m_config.sdkToolsVersion() < sdkManagerIntroVersion) {
AndroidToolManager toolManager(m_config);
return toolManager.availableSdkPlatforms();
return toolManager.availableSdkPlatforms(ok);
}
QString packageListing;
if (sdkManagerCommand(m_config, QStringList({"--list", "--verbose"}), &packageListing))
m_parser->parsePackageListing(packageListing);
if (ok)
*ok = success;
return m_parser->m_installedPlatforms;
}
......
......@@ -40,7 +40,7 @@ public:
AndroidSdkManager(const AndroidConfig &config);
~AndroidSdkManager();
SdkPlatformList availableSdkPlatforms();
SdkPlatformList availableSdkPlatforms(bool *ok = nullptr);
private:
const AndroidConfig &m_config;
......
......@@ -97,16 +97,22 @@ AndroidToolManager::~AndroidToolManager()
}
SdkPlatformList AndroidToolManager::availableSdkPlatforms() const
SdkPlatformList AndroidToolManager::availableSdkPlatforms(bool *ok) const
{
bool success = false;
SdkPlatformList list;
QString targetListing;
if (androidToolCommand(m_config.androidToolPath(), QStringList({"list", "target"}),
androidToolEnvironment(), &targetListing)) {
m_parser->parseTargetListing(targetListing, m_config.sdkLocation(), &list);
success = true;
} else {
qCDebug(androidToolLog) << "Android tool target listing failed";
}
if (ok)
*ok = success;
return list;
}
......
......@@ -48,7 +48,7 @@ public:
AndroidToolManager(const AndroidConfig &config);
~AndroidToolManager();
SdkPlatformList availableSdkPlatforms() const;
SdkPlatformList availableSdkPlatforms(bool *ok = nullptr) const;
void launchAvdManager() const;
QFuture<AndroidConfig::CreateAvdInfo> createAvd(AndroidConfig::CreateAvdInfo info) const;
......
......@@ -158,6 +158,13 @@ bool QmakeAndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps)
return true;
}
QString buildTargetSdk = AndroidManager::buildTargetSDK(target());
if (buildTargetSdk.isEmpty()) {
emit addOutput(tr("Android build SDK not defined. Check Android settings."),
OutputFormat::Stderr);
return false;
}
QStringList arguments;
arguments << QLatin1String("--input")
<< inputFile
......
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