From 3881ff94f7c6386fe43c8e8cc2e47e317a382641 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Mon, 24 Jul 2017 15:27:19 +0200 Subject: [PATCH] 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: Leena Miettinen Reviewed-by: Tobias Hunger --- src/plugins/android/androidconfigurations.cpp | 8 ++++--- src/plugins/android/androidsdkmanager.cpp | 24 ++++++++++++------- src/plugins/android/androidsdkmanager.h | 2 +- src/plugins/android/androidtoolmanager.cpp | 8 ++++++- src/plugins/android/androidtoolmanager.h | 2 +- .../qmakeandroidbuildapkstep.cpp | 7 ++++++ 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index be5f6df9619..ccefeef4e24 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -347,8 +347,10 @@ void AndroidConfig::updateAvailableSdkPlatforms() const m_availableSdkPlatforms.clear(); AndroidSdkManager sdkManager(*this); - m_availableSdkPlatforms = sdkManager.availableSdkPlatforms(); - m_availableSdkPlatformsUpToDate = true; + bool success = false; + m_availableSdkPlatforms = sdkManager.availableSdkPlatforms(&success); + if (success) + m_availableSdkPlatformsUpToDate = true; } QStringList AndroidConfig::apiLevelNamesFor(const QList &platforms) @@ -358,7 +360,7 @@ QStringList AndroidConfig::apiLevelNamesFor(const QList &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 AndroidConfig::sdkTargets(int minApiLevel) const diff --git a/src/plugins/android/androidsdkmanager.cpp b/src/plugins/android/androidsdkmanager.cpp index 0ed23660a61..c28fef27a18 100644 --- a/src/plugins/android/androidsdkmanager.cpp +++ b/src/plugins/android/androidsdkmanager.cpp @@ -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; } diff --git a/src/plugins/android/androidsdkmanager.h b/src/plugins/android/androidsdkmanager.h index 2c111480723..b1da078b6ef 100644 --- a/src/plugins/android/androidsdkmanager.h +++ b/src/plugins/android/androidsdkmanager.h @@ -40,7 +40,7 @@ public: AndroidSdkManager(const AndroidConfig &config); ~AndroidSdkManager(); - SdkPlatformList availableSdkPlatforms(); + SdkPlatformList availableSdkPlatforms(bool *ok = nullptr); private: const AndroidConfig &m_config; diff --git a/src/plugins/android/androidtoolmanager.cpp b/src/plugins/android/androidtoolmanager.cpp index 19f7cbc97b9..39fa2a2c426 100644 --- a/src/plugins/android/androidtoolmanager.cpp +++ b/src/plugins/android/androidtoolmanager.cpp @@ -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; } diff --git a/src/plugins/android/androidtoolmanager.h b/src/plugins/android/androidtoolmanager.h index befb095b92a..faaa9428ab6 100644 --- a/src/plugins/android/androidtoolmanager.h +++ b/src/plugins/android/androidtoolmanager.h @@ -48,7 +48,7 @@ public: AndroidToolManager(const AndroidConfig &config); ~AndroidToolManager(); - SdkPlatformList availableSdkPlatforms() const; + SdkPlatformList availableSdkPlatforms(bool *ok = nullptr) const; void launchAvdManager() const; QFuture createAvd(AndroidConfig::CreateAvdInfo info) const; diff --git a/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkstep.cpp b/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkstep.cpp index ce087ff9df2..4ca9ef9653a 100644 --- a/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkstep.cpp +++ b/src/plugins/qmakeandroidsupport/qmakeandroidbuildapkstep.cpp @@ -158,6 +158,13 @@ bool QmakeAndroidBuildApkStep::init(QList &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