Commit 1df66a18 authored by Daniel Teske's avatar Daniel Teske

Android: Rework sdkTargets() to cache the output of adb

Also rename/change highestAvailablePlatform to highestAvailableSdk.
This fixes a bug reported on irc, where the lists for sdk and ndk
were different and the highestAvailablePlatform was not available
as in the sdk.

Change-Id: I17fec9e8ce1913e933ddcf8eaa21d6bb6e14c5be
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent 723d4a97
...@@ -224,6 +224,7 @@ void AndroidConfigurations::setConfig(const AndroidConfig &devConfigs) ...@@ -224,6 +224,7 @@ void AndroidConfigurations::setConfig(const AndroidConfig &devConfigs)
save(); save();
updateAvailableNdkPlatforms(); updateAvailableNdkPlatforms();
updateAvailableSdkPlatforms();
updateAutomaticKitList(); updateAutomaticKitList();
updateAndroidDevice(); updateAndroidDevice();
emit updated(); emit updated();
...@@ -241,25 +242,38 @@ void AndroidConfigurations::updateAvailableNdkPlatforms() ...@@ -241,25 +242,38 @@ void AndroidConfigurations::updateAvailableNdkPlatforms()
qSort(m_availableNdkPlatforms.begin(), m_availableNdkPlatforms.end(), qGreater<int>()); qSort(m_availableNdkPlatforms.begin(), m_availableNdkPlatforms.end(), qGreater<int>());
} }
QStringList AndroidConfigurations::sdkTargets(int minApiLevel) const void AndroidConfigurations::updateAvailableSdkPlatforms()
{ {
QStringList targets; m_availableSdkPlatforms.clear();
QProcess proc; QProcess proc;
proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
if (!proc.waitForFinished(-1)) { if (!proc.waitForFinished(-1)) {
proc.terminate(); proc.terminate();
return targets; return;
} }
while (proc.canReadLine()) { while (proc.canReadLine()) {
const QString line = QString::fromLocal8Bit(proc.readLine().trimmed()); const QString line = QString::fromLocal8Bit(proc.readLine().trimmed());
int index = line.indexOf(QLatin1String("\"android-")); int index = line.indexOf(QLatin1String("\"android-"));
if (index == -1) if (index == -1)
continue; continue;
QString apiLevel = line.mid(index + 1, line.length() - index - 2); QString androidTarget = line.mid(index + 1, line.length() - index - 2);
if (apiLevel.mid(apiLevel.lastIndexOf(QLatin1Char('-')) + 1).toInt() >= minApiLevel) int apiLevel = androidTarget.mid(androidTarget.lastIndexOf(QLatin1Char('-')) + 1).toInt();
targets.push_back(apiLevel); QVector<int>::iterator it = qLowerBound(m_availableSdkPlatforms.begin(), m_availableSdkPlatforms.end(), apiLevel, qGreater<int>());
m_availableSdkPlatforms.insert(it, apiLevel);
} }
return targets; }
QStringList AndroidConfigurations::sdkTargets(int minApiLevel) const
{
QStringList result;
for (int i = 0; i < m_availableSdkPlatforms.size(); ++i) {
if (m_availableSdkPlatforms.at(i) >= minApiLevel)
result << QLatin1String("android-") + QString::number(m_availableSdkPlatforms.at(i));
else
break;
}
return result;
} }
FileName AndroidConfigurations::adbToolPath() const FileName AndroidConfigurations::adbToolPath() const
...@@ -470,6 +484,8 @@ QString AndroidConfigurations::createAVD(int minApiLevel, QString targetArch) co ...@@ -470,6 +484,8 @@ QString AndroidConfigurations::createAVD(int minApiLevel, QString targetArch) co
QDialog d; QDialog d;
Ui::AddNewAVDDialog avdDialog; Ui::AddNewAVDDialog avdDialog;
avdDialog.setupUi(&d); avdDialog.setupUi(&d);
// NOTE: adb list targets does actually include information on which abis are supported per apilevel
// we aren't using that information here
avdDialog.targetComboBox->addItems(sdkTargets(minApiLevel)); avdDialog.targetComboBox->addItems(sdkTargets(minApiLevel));
if (targetArch.isEmpty()) if (targetArch.isEmpty())
...@@ -735,11 +751,11 @@ QStringList AndroidConfigurations::getAbis(const QString &device) const ...@@ -735,11 +751,11 @@ QStringList AndroidConfigurations::getAbis(const QString &device) const
return result; return result;
} }
QString AndroidConfigurations::highestAvailableAndroidPlatform() const QString AndroidConfigurations::highestAndroidSdk() const
{ {
if (m_availableNdkPlatforms.isEmpty()) if (m_availableSdkPlatforms.isEmpty())
return QString(); return QString();
return QLatin1String("android-") + QString::number(m_availableNdkPlatforms.first()); return QLatin1String("android-") + QString::number(m_availableSdkPlatforms.first());
} }
QString AndroidConfigurations::bestNdkPlatformMatch(const QString &targetAPI) const QString AndroidConfigurations::bestNdkPlatformMatch(const QString &targetAPI) const
...@@ -902,6 +918,7 @@ AndroidConfigurations::AndroidConfigurations(QObject *parent) ...@@ -902,6 +918,7 @@ AndroidConfigurations::AndroidConfigurations(QObject *parent)
{ {
load(); load();
updateAvailableNdkPlatforms(); updateAvailableNdkPlatforms();
updateAvailableSdkPlatforms();
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)), connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(clearDefaultDevices(ProjectExplorer::Project*))); this, SLOT(clearDefaultDevices(ProjectExplorer::Project*)));
......
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi); AndroidDeviceInfo showDeviceDialog(ProjectExplorer::Project *project, int apiLevel, const QString &abi);
void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name void setDefaultDevice(ProjectExplorer::Project *project, const QString &abi, const QString &serialNumber); // serial number or avd name
QString defaultDevice(ProjectExplorer::Project *project, const QString &abi) const; // serial number or avd name QString defaultDevice(ProjectExplorer::Project *project, const QString &abi) const; // serial number or avd name
QString highestAvailableAndroidPlatform() const; QString highestAndroidSdk() const;
public slots: public slots:
void clearDefaultDevices(ProjectExplorer::Project *project); void clearDefaultDevices(ProjectExplorer::Project *project);
...@@ -146,11 +146,14 @@ private: ...@@ -146,11 +146,14 @@ private:
int getSDKVersion(const QString &device) const; int getSDKVersion(const QString &device) const;
QStringList getAbis(const QString &device) const; QStringList getAbis(const QString &device) const;
void updateAvailableNdkPlatforms(); void updateAvailableNdkPlatforms();
void updateAvailableSdkPlatforms();
static AndroidConfigurations *m_instance; static AndroidConfigurations *m_instance;
AndroidConfig m_config; AndroidConfig m_config;
QVector<int> m_availableNdkPlatforms; QVector<int> m_availableNdkPlatforms;
QVector<int> m_availableSdkPlatforms;
mutable QHash<QString, QString> m_serialNumberToDeviceName; mutable QHash<QString, QString> m_serialNumberToDeviceName;
QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi; QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi;
......
...@@ -158,7 +158,7 @@ void AndroidDeployQtStep::ctor() ...@@ -158,7 +158,7 @@ void AndroidDeployQtStep::ctor()
m_verbose = false; m_verbose = false;
// will be overwriten by settings if the user choose something different // will be overwriten by settings if the user choose something different
m_buildTargetSdk = AndroidConfigurations::instance().highestAvailableAndroidPlatform(); m_buildTargetSdk = AndroidConfigurations::instance().highestAndroidSdk();
connect(project(), SIGNAL(proFilesEvaluated()), connect(project(), SIGNAL(proFilesEvaluated()),
this, SLOT(updateInputFile())); this, SLOT(updateInputFile()));
......
...@@ -620,7 +620,7 @@ bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target * ...@@ -620,7 +620,7 @@ bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target *
return false; return false;
} }
updateTarget(target, AndroidConfigurations::instance().sdkTargets(minApiLevel).at(0)); updateTarget(target, sdks.first());
QStringList apps = availableTargetApplications(target); QStringList apps = availableTargetApplications(target);
if (!apps.isEmpty()) if (!apps.isEmpty())
setTargetApplication(target, apps.at(0)); setTargetApplication(target, apps.at(0));
......
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