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,8 +347,10 @@ void AndroidConfig::updateAvailableSdkPlatforms() const ...@@ -347,8 +347,10 @@ void AndroidConfig::updateAvailableSdkPlatforms() const
m_availableSdkPlatforms.clear(); m_availableSdkPlatforms.clear();
AndroidSdkManager sdkManager(*this); AndroidSdkManager sdkManager(*this);
m_availableSdkPlatforms = sdkManager.availableSdkPlatforms(); bool success = false;
m_availableSdkPlatformsUpToDate = true; m_availableSdkPlatforms = sdkManager.availableSdkPlatforms(&success);
if (success)
m_availableSdkPlatformsUpToDate = true;
} }
QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms) QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms)
...@@ -358,7 +360,7 @@ QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms) ...@@ -358,7 +360,7 @@ QStringList AndroidConfig::apiLevelNamesFor(const QList<SdkPlatform> &platforms)
QString AndroidConfig::apiLevelNameFor(const SdkPlatform &platform) 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 QList<SdkPlatform> AndroidConfig::sdkTargets(int minApiLevel) const
......
...@@ -50,6 +50,8 @@ const char installLocationKey[] = "Installed Location:"; ...@@ -50,6 +50,8 @@ const char installLocationKey[] = "Installed Location:";
const char apiLevelPropertyKey[] = "AndroidVersion.ApiLevel"; const char apiLevelPropertyKey[] = "AndroidVersion.ApiLevel";
const char abiPropertyKey[] = "SystemImage.Abi"; const char abiPropertyKey[] = "SystemImage.Abi";
const int sdkManagerCmdTimeoutS = 60;
using namespace Utils; using namespace Utils;
/*! /*!
...@@ -72,11 +74,14 @@ static bool valueForKey(QString key, const QString &line, QString *value = nullp ...@@ -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 \c true if the command is successfully executed. Output is copied into \a output. The function
blocks the calling thread. 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(); QString sdkManagerToolPath = config.sdkManagerToolPath().toString();
SynchronousProcess proc; 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 (response.result == SynchronousProcessResponse::Finished) {
if (output) if (output)
*output = response.allOutput(); *output = response.allOutput();
...@@ -132,10 +137,6 @@ AndroidSdkManager::AndroidSdkManager(const AndroidConfig &config): ...@@ -132,10 +137,6 @@ AndroidSdkManager::AndroidSdkManager(const AndroidConfig &config):
m_config(config), m_config(config),
m_parser(new SdkManagerOutputParser) m_parser(new SdkManagerOutputParser)
{ {
QString packageListing;
if (sdkManagerCommand(config, QStringList({"--list", "--verbose"}), &packageListing)) {
m_parser->parsePackageListing(packageListing);
}
} }
AndroidSdkManager::~AndroidSdkManager() AndroidSdkManager::~AndroidSdkManager()
...@@ -143,13 +144,20 @@ AndroidSdkManager::~AndroidSdkManager() ...@@ -143,13 +144,20 @@ AndroidSdkManager::~AndroidSdkManager()
} }
SdkPlatformList AndroidSdkManager::availableSdkPlatforms() SdkPlatformList AndroidSdkManager::availableSdkPlatforms(bool *ok)
{ {
bool success = false;
if (m_config.sdkToolsVersion() < sdkManagerIntroVersion) { if (m_config.sdkToolsVersion() < sdkManagerIntroVersion) {
AndroidToolManager toolManager(m_config); 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; return m_parser->m_installedPlatforms;
} }
......
...@@ -40,7 +40,7 @@ public: ...@@ -40,7 +40,7 @@ public:
AndroidSdkManager(const AndroidConfig &config); AndroidSdkManager(const AndroidConfig &config);
~AndroidSdkManager(); ~AndroidSdkManager();
SdkPlatformList availableSdkPlatforms(); SdkPlatformList availableSdkPlatforms(bool *ok = nullptr);
private: private:
const AndroidConfig &m_config; const AndroidConfig &m_config;
......
...@@ -97,16 +97,22 @@ AndroidToolManager::~AndroidToolManager() ...@@ -97,16 +97,22 @@ AndroidToolManager::~AndroidToolManager()
} }
SdkPlatformList AndroidToolManager::availableSdkPlatforms() const SdkPlatformList AndroidToolManager::availableSdkPlatforms(bool *ok) const
{ {
bool success = false;
SdkPlatformList list; SdkPlatformList list;
QString targetListing; QString targetListing;
if (androidToolCommand(m_config.androidToolPath(), QStringList({"list", "target"}), if (androidToolCommand(m_config.androidToolPath(), QStringList({"list", "target"}),
androidToolEnvironment(), &targetListing)) { androidToolEnvironment(), &targetListing)) {
m_parser->parseTargetListing(targetListing, m_config.sdkLocation(), &list); m_parser->parseTargetListing(targetListing, m_config.sdkLocation(), &list);
success = true;
} else { } else {
qCDebug(androidToolLog) << "Android tool target listing failed"; qCDebug(androidToolLog) << "Android tool target listing failed";
} }
if (ok)
*ok = success;
return list; return list;
} }
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
AndroidToolManager(const AndroidConfig &config); AndroidToolManager(const AndroidConfig &config);
~AndroidToolManager(); ~AndroidToolManager();
SdkPlatformList availableSdkPlatforms() const; SdkPlatformList availableSdkPlatforms(bool *ok = nullptr) const;
void launchAvdManager() const; void launchAvdManager() const;
QFuture<AndroidConfig::CreateAvdInfo> createAvd(AndroidConfig::CreateAvdInfo info) const; QFuture<AndroidConfig::CreateAvdInfo> createAvd(AndroidConfig::CreateAvdInfo info) const;
......
...@@ -158,6 +158,13 @@ bool QmakeAndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps) ...@@ -158,6 +158,13 @@ bool QmakeAndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps)
return true; 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; QStringList arguments;
arguments << QLatin1String("--input") arguments << QLatin1String("--input")
<< inputFile << 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