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)
save();
updateAvailableNdkPlatforms();
updateAvailableSdkPlatforms();
updateAutomaticKitList();
updateAndroidDevice();
emit updated();
......@@ -241,25 +242,38 @@ void AndroidConfigurations::updateAvailableNdkPlatforms()
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;
proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
if (!proc.waitForFinished(-1)) {
proc.terminate();
return targets;
return;
}
while (proc.canReadLine()) {
const QString line = QString::fromLocal8Bit(proc.readLine().trimmed());
int index = line.indexOf(QLatin1String("\"android-"));
if (index == -1)
continue;
QString apiLevel = line.mid(index + 1, line.length() - index - 2);
if (apiLevel.mid(apiLevel.lastIndexOf(QLatin1Char('-')) + 1).toInt() >= minApiLevel)
targets.push_back(apiLevel);
QString androidTarget = line.mid(index + 1, line.length() - index - 2);
int apiLevel = androidTarget.mid(androidTarget.lastIndexOf(QLatin1Char('-')) + 1).toInt();
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
......@@ -470,6 +484,8 @@ QString AndroidConfigurations::createAVD(int minApiLevel, QString targetArch) co
QDialog d;
Ui::AddNewAVDDialog avdDialog;
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));
if (targetArch.isEmpty())
......@@ -735,11 +751,11 @@ QStringList AndroidConfigurations::getAbis(const QString &device) const
return result;
}
QString AndroidConfigurations::highestAvailableAndroidPlatform() const
QString AndroidConfigurations::highestAndroidSdk() const
{
if (m_availableNdkPlatforms.isEmpty())
if (m_availableSdkPlatforms.isEmpty())
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
......@@ -902,6 +918,7 @@ AndroidConfigurations::AndroidConfigurations(QObject *parent)
{
load();
updateAvailableNdkPlatforms();
updateAvailableSdkPlatforms();
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(clearDefaultDevices(ProjectExplorer::Project*)));
......
......@@ -124,7 +124,7 @@ public:
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
QString defaultDevice(ProjectExplorer::Project *project, const QString &abi) const; // serial number or avd name
QString highestAvailableAndroidPlatform() const;
QString highestAndroidSdk() const;
public slots:
void clearDefaultDevices(ProjectExplorer::Project *project);
......@@ -146,11 +146,14 @@ private:
int getSDKVersion(const QString &device) const;
QStringList getAbis(const QString &device) const;
void updateAvailableNdkPlatforms();
void updateAvailableSdkPlatforms();
static AndroidConfigurations *m_instance;
AndroidConfig m_config;
QVector<int> m_availableNdkPlatforms;
QVector<int> m_availableSdkPlatforms;
mutable QHash<QString, QString> m_serialNumberToDeviceName;
QMap<ProjectExplorer::Project *, QMap<QString, QString> > m_defaultDeviceForAbi;
......
......@@ -158,7 +158,7 @@ void AndroidDeployQtStep::ctor()
m_verbose = false;
// 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()),
this, SLOT(updateInputFile()));
......
......@@ -620,7 +620,7 @@ bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target *
return false;
}
updateTarget(target, AndroidConfigurations::instance().sdkTargets(minApiLevel).at(0));
updateTarget(target, sdks.first());
QStringList apps = availableTargetApplications(target);
if (!apps.isEmpty())
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