2012-04-18 20:30:57 +03:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (c) 2012 BogDan Vatra <bog_dan_ro@yahoo.com>
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-18 20:30:57 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "androidmanager.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
#include "androiddeployconfiguration.h"
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
#include "androidrunconfiguration.h"
|
|
|
|
#include "androiddeploystep.h"
|
|
|
|
#include "androidglobal.h"
|
|
|
|
#include "androidpackagecreationstep.h"
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
#include <projectexplorer/target.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <qt4projectmanager/qt4nodes.h>
|
|
|
|
#include <qt4projectmanager/qt4project.h>
|
|
|
|
#include <qt4projectmanager/qt4projectmanagerconstants.h>
|
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
2012-05-16 16:24:16 +02:00
|
|
|
#include <qtsupport/customexecutablerunconfiguration.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QList>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDomDocument>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const QLatin1String AndroidDirName("android");
|
|
|
|
const QLatin1String AndroidManifestName("AndroidManifest.xml");
|
|
|
|
const QLatin1String AndroidLibsFileName("/res/values/libs.xml");
|
|
|
|
const QLatin1String AndroidStringsFileName("/res/values/strings.xml");
|
|
|
|
const QLatin1String AndroidDefaultPropertiesName("project.properties");
|
|
|
|
|
|
|
|
QString cleanPackageName(QString packageName)
|
|
|
|
{
|
2012-04-30 12:01:15 +02:00
|
|
|
QRegExp legalChars(QLatin1String("[a-zA-Z0-9_\\.]"));
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < packageName.length(); ++i)
|
|
|
|
if (!legalChars.exactMatch(packageName.mid(i, 1)))
|
|
|
|
packageName[i] = QLatin1Char('_');
|
|
|
|
|
|
|
|
return packageName;
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
namespace Internal {
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::supportsAndroid(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!qobject_cast<Qt4ProjectManager::Qt4Project *>(target->project()))
|
|
|
|
return false;
|
2012-09-03 18:31:44 +02:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
|
2012-07-16 11:04:42 +02:00
|
|
|
return version && version->platformName() == QLatin1String(QtSupport::Constants::ANDROID_PLATFORM);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::packageName(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("package"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setPackageName(ProjectExplorer::Target *target, const QString &name)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return false;
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
manifestElem.setAttribute(QLatin1String("package"), cleanPackageName(name));
|
|
|
|
return saveManifest(target, doc);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::applicationName(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument doc;
|
2012-11-06 16:22:53 +01:00
|
|
|
if (!openXmlFile(doc, stringsPath(target)))
|
2012-04-24 15:49:09 +02:00
|
|
|
return QString();
|
|
|
|
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("string"));
|
|
|
|
while (!metadataElem.isNull()) {
|
|
|
|
if (metadataElem.attribute(QLatin1String("name")) == QLatin1String("app_name"))
|
|
|
|
return metadataElem.text();
|
|
|
|
metadataElem = metadataElem.nextSiblingElement(QLatin1String("string"));
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setApplicationName(ProjectExplorer::Target *target, const QString &name)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
Utils::FileName path = stringsPath(target);
|
2012-11-06 16:22:53 +01:00
|
|
|
if (!openXmlFile(doc, path))
|
2012-04-24 15:49:09 +02:00
|
|
|
return false;
|
|
|
|
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("string"));
|
|
|
|
while (!metadataElem.isNull()) {
|
|
|
|
if (metadataElem.attribute(QLatin1String("name")) == QLatin1String("app_name")) {
|
|
|
|
metadataElem.removeChild(metadataElem.firstChild());
|
|
|
|
metadataElem.appendChild(doc.createTextNode(name));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
metadataElem = metadataElem.nextSiblingElement(QLatin1String("string"));
|
|
|
|
}
|
|
|
|
return saveXmlFile(target, doc, path);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::permissions(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QStringList per;
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return per;
|
|
|
|
QDomElement permissionElem = doc.documentElement().firstChildElement(QLatin1String("uses-permission"));
|
|
|
|
while (!permissionElem.isNull()) {
|
|
|
|
per << permissionElem.attribute(QLatin1String("android:name"));
|
|
|
|
permissionElem = permissionElem.nextSiblingElement(QLatin1String("uses-permission"));
|
|
|
|
}
|
|
|
|
return per;
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setPermissions(ProjectExplorer::Target *target, const QStringList &permissions)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return false;
|
|
|
|
QDomElement docElement = doc.documentElement();
|
|
|
|
QDomElement permissionElem = docElement.firstChildElement(QLatin1String("uses-permission"));
|
|
|
|
while (!permissionElem.isNull()) {
|
|
|
|
docElement.removeChild(permissionElem);
|
|
|
|
permissionElem = docElement.firstChildElement(QLatin1String("uses-permission"));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
foreach (const QString &permission, permissions ) {
|
|
|
|
permissionElem = doc.createElement(QLatin1String("uses-permission"));
|
|
|
|
permissionElem.setAttribute(QLatin1String("android:name"), permission);
|
|
|
|
docElement.appendChild(permissionElem);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
return saveManifest(target, doc);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::intentName(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return packageName(target) + QLatin1Char('/') + activityName(target);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::activityName(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement activityElem = doc.documentElement().firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity"));
|
|
|
|
return activityElem.attribute(QLatin1String("android:name"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
int AndroidManager::versionCode(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return 0;
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("android:versionCode")).toInt();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setVersionCode(ProjectExplorer::Target *target, int version)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return false;
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
manifestElem.setAttribute(QLatin1String("android:versionCode"), version);
|
|
|
|
return saveManifest(target, doc);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::versionName(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
return manifestElem.attribute(QLatin1String("android:versionName"));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setVersionName(ProjectExplorer::Target *target, const QString &version)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return false;
|
|
|
|
QDomElement manifestElem = doc.documentElement();
|
|
|
|
manifestElem.setAttribute(QLatin1String("android:versionName"), version);
|
|
|
|
return saveManifest(target, doc);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::targetSDK(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!createAndroidTemplatesIfNecessary(target))
|
|
|
|
return AndroidConfigurations::instance().bestMatch(QLatin1String("android-8"));
|
|
|
|
QFile file(defaultPropertiesPath(target).toString());
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return AndroidConfigurations::instance().bestMatch(QLatin1String("android-8"));
|
|
|
|
while (!file.atEnd()) {
|
|
|
|
QByteArray line = file.readLine();
|
|
|
|
if (line.startsWith("target="))
|
|
|
|
return QString::fromLatin1(line.trimmed().mid(7));
|
|
|
|
}
|
|
|
|
return AndroidConfigurations::instance().bestMatch(QLatin1String("android-8"));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setTargetSDK(ProjectExplorer::Target *target, const QString &sdk)
|
|
|
|
{
|
|
|
|
updateTarget(target, sdk, applicationName(target));
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QIcon AndroidManager::highDpiIcon(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
return icon(target, HighDPI);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setHighDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return setIcon(target, HighDPI, iconFilePath);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QIcon AndroidManager::mediumDpiIcon(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return icon(target, MediumDPI);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setMediumDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return setIcon(target, MediumDPI, iconFilePath);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QIcon AndroidManager::lowDpiIcon(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return icon(target, LowDPI);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setLowDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return setIcon(target, LowDPI, iconFilePath);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::dirPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return Utils::FileName::fromString(target->project()->projectDirectory()).appendPath(AndroidDirName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::manifestPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(AndroidManifestName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::libsPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(AndroidLibsFileName);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::stringsPath(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
return dirPath(target).append(AndroidStringsFileName);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::defaultPropertiesPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(AndroidDefaultPropertiesName);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::srcPath(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
return dirPath(target).appendPath(QLatin1String("/src"));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::apkPath(ProjectExplorer::Target *target, BuildType buildType)
|
|
|
|
{
|
|
|
|
return dirPath(target)
|
|
|
|
.appendPath(QLatin1String("bin"))
|
|
|
|
.appendPath(QString::fromLatin1("%1-%2.apk")
|
|
|
|
.arg(applicationName(target))
|
|
|
|
.arg(buildType == DebugBuild
|
|
|
|
? QLatin1String("debug")
|
|
|
|
: (buildType == ReleaseBuildUnsigned)
|
|
|
|
? QLatin1String("release-unsigned")
|
|
|
|
: QLatin1String("signed")));
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::availableTargetApplications(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QStringList apps;
|
|
|
|
Qt4ProjectManager::Qt4Project *qt4Project = qobject_cast<Qt4ProjectManager::Qt4Project *>(target->project());
|
|
|
|
foreach (Qt4ProjectManager::Qt4ProFileNode *proFile, qt4Project->applicationProFiles()) {
|
|
|
|
if (proFile->projectType() == Qt4ProjectManager::ApplicationTemplate) {
|
|
|
|
if (proFile->targetInformation().target.startsWith(QLatin1String("lib"))
|
|
|
|
&& proFile->targetInformation().target.endsWith(QLatin1String(".so")))
|
|
|
|
apps << proFile->targetInformation().target.mid(3, proFile->targetInformation().target.lastIndexOf(QLatin1Char('.')) - 3);
|
|
|
|
else
|
|
|
|
apps << proFile->targetInformation().target;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
apps.sort();
|
|
|
|
return apps;
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::targetApplication(ProjectExplorer::Target *target)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return QString();
|
|
|
|
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity")).firstChildElement(QLatin1String("meta-data"));
|
|
|
|
while (!metadataElem.isNull()) {
|
|
|
|
if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.lib_name"))
|
|
|
|
return metadataElem.attribute(QLatin1String("android:value"));
|
|
|
|
metadataElem = metadataElem.nextSiblingElement(QLatin1String("meta-data"));
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setTargetApplication(ProjectExplorer::Target *target, const QString &name)
|
|
|
|
{
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!openManifest(target, doc))
|
|
|
|
return false;
|
|
|
|
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity")).firstChildElement(QLatin1String("meta-data"));
|
|
|
|
while (!metadataElem.isNull()) {
|
|
|
|
if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.lib_name")) {
|
|
|
|
metadataElem.setAttribute(QLatin1String("android:value"), name);
|
|
|
|
return saveManifest(target, doc);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
metadataElem = metadataElem.nextSiblingElement(QLatin1String("meta-data"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return false;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::targetApplicationPath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QString selectedApp = targetApplication(target);
|
|
|
|
if (selectedApp.isEmpty())
|
|
|
|
return QString();
|
|
|
|
Qt4ProjectManager::Qt4Project *qt4Project = qobject_cast<Qt4ProjectManager::Qt4Project *>(target->project());
|
|
|
|
foreach (Qt4ProjectManager::Qt4ProFileNode *proFile, qt4Project->applicationProFiles()) {
|
|
|
|
if (proFile->projectType() == Qt4ProjectManager::ApplicationTemplate) {
|
|
|
|
if (proFile->targetInformation().target.startsWith(QLatin1String("lib"))
|
|
|
|
&& proFile->targetInformation().target.endsWith(QLatin1String(".so"))) {
|
|
|
|
if (proFile->targetInformation().target.mid(3, proFile->targetInformation().target.lastIndexOf(QLatin1Char('.')) - 3)
|
|
|
|
== selectedApp)
|
2012-07-16 11:04:42 +02:00
|
|
|
return proFile->targetInformation().buildDir + QLatin1Char('/') + proFile->targetInformation().target;
|
2012-04-24 15:49:09 +02:00
|
|
|
} else {
|
|
|
|
if (proFile->targetInformation().target == selectedApp)
|
|
|
|
return proFile->targetInformation().buildDir + QLatin1String("/lib") + proFile->targetInformation().target + QLatin1String(".so");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
|
2012-04-24 15:49:09 +02:00
|
|
|
Qt4ProjectManager::Qt4Project *qt4Project = qobject_cast<Qt4ProjectManager::Qt4Project*>(target->project());
|
|
|
|
if (!qt4Project || !qt4Project->rootProjectNode() || !version)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Utils::FileName javaSrcPath
|
2012-07-06 13:29:45 +02:00
|
|
|
= Utils::FileName::fromString(version->qmakeProperty("QT_INSTALL_PREFIX"))
|
2012-07-03 16:57:44 +03:00
|
|
|
.appendPath(QLatin1String("src/android/java"));
|
2012-04-24 15:49:09 +02:00
|
|
|
QDir projectDir(qt4Project->projectDirectory());
|
|
|
|
Utils::FileName androidPath = dirPath(target);
|
|
|
|
|
|
|
|
QStringList m_ignoreFiles;
|
|
|
|
bool forceUpdate = false;
|
|
|
|
QDomDocument srcVersionDoc;
|
2012-07-03 16:57:44 +03:00
|
|
|
Utils::FileName srcVersionPath = javaSrcPath;
|
|
|
|
srcVersionPath.appendPath(QLatin1String("version.xml"));
|
2012-11-06 16:22:53 +01:00
|
|
|
if (openXmlFile(srcVersionDoc, srcVersionPath)) {
|
2012-04-24 15:49:09 +02:00
|
|
|
QDomDocument dstVersionDoc;
|
2012-07-03 16:57:44 +03:00
|
|
|
Utils::FileName dstVersionPath=androidPath;
|
|
|
|
dstVersionPath.appendPath(QLatin1String("version.xml"));
|
2012-11-06 16:22:53 +01:00
|
|
|
if (openXmlFile(dstVersionDoc, dstVersionPath))
|
2012-04-24 15:49:09 +02:00
|
|
|
forceUpdate = (srcVersionDoc.documentElement().attribute(QLatin1String("value")).toDouble()
|
|
|
|
> dstVersionDoc.documentElement().attribute(QLatin1String("value")).toDouble());
|
|
|
|
else
|
|
|
|
forceUpdate = true;
|
|
|
|
|
|
|
|
if (forceUpdate && androidPath.toFileInfo().exists()) {
|
|
|
|
QDomElement ignoreFile = srcVersionDoc.documentElement().firstChildElement(QLatin1String("ignore")).firstChildElement(QLatin1String("file"));
|
|
|
|
while (!ignoreFile.isNull()) {
|
|
|
|
m_ignoreFiles << ignoreFile.text();
|
|
|
|
ignoreFile = ignoreFile.nextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-23 12:24:44 +03:00
|
|
|
Utils::FileName src = androidPath;
|
2012-07-16 11:04:42 +02:00
|
|
|
src.appendPath(QLatin1String("src"));
|
2012-06-23 12:24:44 +03:00
|
|
|
Utils::FileName res = androidPath;
|
2012-07-16 11:04:42 +02:00
|
|
|
res.appendPath(QLatin1String("res"));
|
2012-06-23 12:24:44 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!forceUpdate && androidPath.toFileInfo().exists()
|
|
|
|
&& manifestPath(target).toFileInfo().exists()
|
2012-06-23 12:24:44 +03:00
|
|
|
&& src.toFileInfo().exists()
|
|
|
|
&& res.toFileInfo().exists())
|
2012-04-24 15:49:09 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
forceUpdate &= androidPath.toFileInfo().exists();
|
|
|
|
|
|
|
|
if (!dirPath(target).toFileInfo().exists() && !projectDir.mkdir(AndroidDirName)) {
|
|
|
|
raiseError(tr("Error creating Android directory '%1'.").arg(AndroidDirName));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList androidFiles;
|
|
|
|
QDirIterator it(javaSrcPath.toString(), QDirIterator::Subdirectories);
|
|
|
|
int pos = it.path().size();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (it.fileInfo().isDir()) {
|
|
|
|
projectDir.mkpath(AndroidDirName + it.filePath().mid(pos));
|
|
|
|
} else {
|
2012-07-03 16:57:44 +03:00
|
|
|
Utils::FileName dstFile = androidPath;
|
|
|
|
dstFile.appendPath(it.filePath().mid(pos));
|
2012-04-24 15:49:09 +02:00
|
|
|
if (m_ignoreFiles.contains(it.fileName())) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (dstFile.toFileInfo().exists())
|
|
|
|
QFile::remove(dstFile.toString());
|
|
|
|
else
|
|
|
|
androidFiles << dstFile.toString();
|
|
|
|
}
|
|
|
|
QFile::copy(it.filePath(), dstFile.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!androidFiles.isEmpty())
|
|
|
|
qt4Project->rootProjectNode()->addFiles(ProjectExplorer::UnknownFileType, androidFiles);
|
|
|
|
|
|
|
|
QStringList sdks = AndroidConfigurations::instance().sdkTargets();
|
|
|
|
if (sdks.isEmpty()) {
|
|
|
|
raiseError(tr("No Qt for Android SDKs were found.\nPlease install at least one SDK."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
updateTarget(target, AndroidConfigurations::instance().sdkTargets().at(0));
|
|
|
|
QStringList apps = availableTargetApplications(target);
|
|
|
|
if (!apps.isEmpty())
|
|
|
|
setTargetApplication(target, apps.at(0));
|
|
|
|
|
|
|
|
QString applicationName = target->project()->displayName();
|
|
|
|
if (!applicationName.isEmpty()) {
|
|
|
|
setPackageName(target, packageName(target) + QLatin1Char('.') + applicationName);
|
|
|
|
applicationName[0] = applicationName[0].toUpper();
|
|
|
|
setApplicationName(target, applicationName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forceUpdate)
|
|
|
|
QMessageBox::warning(0, tr("Warning"), tr("Android files have been updated automatically"));
|
|
|
|
|
|
|
|
return true;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
void AndroidManager::updateTarget(ProjectExplorer::Target *target, const QString &targetSDK, const QString &name)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QString androidDir = dirPath(target).toString();
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
// clean previous build
|
|
|
|
QProcess androidProc;
|
|
|
|
androidProc.setWorkingDirectory(androidDir);
|
2012-04-24 15:49:09 +02:00
|
|
|
androidProc.start(AndroidConfigurations::instance().antToolPath().toString(),
|
|
|
|
QStringList() << QLatin1String("clean"));
|
2012-04-18 20:30:57 +03:00
|
|
|
if (!androidProc.waitForFinished(-1))
|
|
|
|
androidProc.terminate();
|
|
|
|
// clean previous build
|
|
|
|
|
|
|
|
int targetSDKNumber = targetSDK.mid(targetSDK.lastIndexOf(QLatin1Char('-')) + 1).toInt();
|
|
|
|
bool commentLines = false;
|
|
|
|
QDirIterator it(androidDir, QStringList() << QLatin1String("*.java"), QDir::Files, QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
QFile file(it.filePath());
|
|
|
|
if (!file.open(QIODevice::ReadWrite))
|
|
|
|
continue;
|
|
|
|
QList<QByteArray> lines = file.readAll().trimmed().split('\n');
|
|
|
|
|
|
|
|
bool modified = false;
|
|
|
|
bool comment = false;
|
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
|
|
|
if (lines[i].contains("@ANDROID-")) {
|
|
|
|
commentLines = targetSDKNumber < lines[i].mid(lines[i].lastIndexOf('-') + 1).toInt();
|
|
|
|
comment = !comment;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!comment)
|
|
|
|
continue;
|
|
|
|
if (commentLines) {
|
|
|
|
if (!lines[i].trimmed().startsWith("//QtCreator")) {
|
|
|
|
lines[i] = "//QtCreator " + lines[i];
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
} else { if (lines[i].trimmed().startsWith("//QtCreator")) {
|
|
|
|
lines[i] = lines[i].mid(12);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (modified) {
|
|
|
|
file.resize(0);
|
|
|
|
foreach (const QByteArray &line, lines) {
|
|
|
|
file.write(line);
|
|
|
|
file.write("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList params;
|
|
|
|
params << QLatin1String("update") << QLatin1String("project") << QLatin1String("-p") << androidDir;
|
|
|
|
if (!targetSDK.isEmpty())
|
|
|
|
params << QLatin1String("-t") << targetSDK;
|
|
|
|
if (!name.isEmpty())
|
|
|
|
params << QLatin1String("-n") << name;
|
2012-04-24 15:49:09 +02:00
|
|
|
androidProc.start(AndroidConfigurations::instance().androidToolPath().toString(), params);
|
2012-04-18 20:30:57 +03:00
|
|
|
if (!androidProc.waitForFinished(-1))
|
|
|
|
androidProc.terminate();
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
Utils::FileName AndroidManager::localLibsRulesFilePath(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!version)
|
|
|
|
return Utils::FileName();
|
2012-07-06 13:29:45 +02:00
|
|
|
return Utils::FileName::fromString(version->qmakeProperty("QT_INSTALL_LIBS") + QLatin1String("/rules.xml"));
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::loadLocalLibs(ProjectExplorer::Target *target, int apiLevel)
|
|
|
|
{
|
|
|
|
return loadLocal(target, apiLevel, Lib);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::loadLocalJars(ProjectExplorer::Target *target, int apiLevel)
|
|
|
|
{
|
|
|
|
return loadLocal(target, apiLevel, Jar);
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::availableQtLibs(ProjectExplorer::Target *target)
|
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit());
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!target->activeRunConfiguration())
|
|
|
|
return QStringList();
|
|
|
|
|
|
|
|
Utils::FileName readelfPath = AndroidConfigurations::instance().readelfPath(target->activeRunConfiguration()->abi().architecture());
|
|
|
|
QStringList libs;
|
|
|
|
const Qt4ProjectManager::Qt4Project *const qt4Project
|
|
|
|
= qobject_cast<const Qt4ProjectManager::Qt4Project *>(target->project());
|
|
|
|
if (!qt4Project || !version)
|
|
|
|
return libs;
|
2012-07-06 13:29:45 +02:00
|
|
|
QString qtLibsPath = version->qmakeProperty("QT_INSTALL_LIBS");
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!readelfPath.toFileInfo().exists()) {
|
|
|
|
QDirIterator libsIt(qtLibsPath, QStringList() << QLatin1String("libQt*.so"));
|
|
|
|
while (libsIt.hasNext()) {
|
|
|
|
libsIt.next();
|
|
|
|
libs << libsIt.fileName().mid(3, libsIt.fileName().indexOf(QLatin1Char('.')) - 3);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
libs.sort();
|
|
|
|
return libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
LibrariesMap mapLibs;
|
|
|
|
QDir libPath;
|
|
|
|
QDirIterator it(qtLibsPath, QStringList() << QLatin1String("*.so"), QDir::Files, QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
libPath = it.next();
|
|
|
|
const QString library = libPath.absolutePath().mid(libPath.absolutePath().lastIndexOf(QLatin1Char('/')) + 1);
|
|
|
|
mapLibs[library].dependencies = dependencies(readelfPath, libPath.absolutePath());
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
// clean dependencies
|
|
|
|
foreach (const QString &key, mapLibs.keys()) {
|
|
|
|
int it = 0;
|
|
|
|
while (it < mapLibs[key].dependencies.size()) {
|
|
|
|
const QString &dependName = mapLibs[key].dependencies[it];
|
|
|
|
if (!mapLibs.keys().contains(dependName) && dependName.startsWith(QLatin1String("lib")) && dependName.endsWith(QLatin1String(".so"))) {
|
|
|
|
mapLibs[key].dependencies.removeAt(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!mapLibs[key].dependencies.size())
|
|
|
|
mapLibs[key].level = 0;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QVector<Library> qtLibraries;
|
|
|
|
// calculate the level for every library
|
|
|
|
foreach (const QString &key, mapLibs.keys()) {
|
|
|
|
if (mapLibs[key].level < 0)
|
|
|
|
setLibraryLevel(key, mapLibs);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!mapLibs[key].name.length() && key.startsWith(QLatin1String("lib")) && key.endsWith(QLatin1String(".so")))
|
|
|
|
mapLibs[key].name = key.mid(3, key.length() - 6);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
for (int it = 0; it < mapLibs[key].dependencies.size(); it++) {
|
|
|
|
const QString &libName = mapLibs[key].dependencies[it];
|
|
|
|
if (libName.startsWith(QLatin1String("lib")) && libName.endsWith(QLatin1String(".so")))
|
|
|
|
mapLibs[key].dependencies[it] = libName.mid(3, libName.length() - 6);
|
|
|
|
}
|
|
|
|
qtLibraries.push_back(mapLibs[key]);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
qSort(qtLibraries.begin(), qtLibraries.end(), qtLibrariesLessThan);
|
|
|
|
foreach (Library lib, qtLibraries) {
|
|
|
|
libs.push_back(lib.name);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::qtLibs(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return libsXml(target, QLatin1String("qt_libs"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setQtLibs(ProjectExplorer::Target *target, const QStringList &libs)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return setLibsXml(target, libs, QLatin1String("qt_libs"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::availablePrebundledLibs(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList libs;
|
|
|
|
Qt4ProjectManager::Qt4Project *qt4Project = qobject_cast<Qt4ProjectManager::Qt4Project *>(target->project());
|
|
|
|
if (!qt4Project)
|
|
|
|
return libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
foreach (Qt4ProjectManager::Qt4ProFileNode *node, qt4Project->allProFiles())
|
|
|
|
if (node->projectType() == Qt4ProjectManager::LibraryTemplate)
|
|
|
|
libs << QLatin1String("lib") + node->targetInformation().target + QLatin1String(".so");
|
|
|
|
return libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::prebundledLibs(ProjectExplorer::Target *target)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return libsXml(target, QLatin1String("bundled_libs"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setPrebundledLibs(ProjectExplorer::Target *target, const QStringList &libs)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return setLibsXml(target, libs, QLatin1String("bundled_libs"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::openLibsXml(ProjectExplorer::Target *target, QDomDocument &doc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-11-06 16:22:53 +01:00
|
|
|
return openXmlFile(doc, libsPath(target));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::saveLibsXml(ProjectExplorer::Target *target, QDomDocument &doc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return saveXmlFile(target, doc, libsPath(target));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
void AndroidManager::raiseError(const QString &reason)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QMessageBox::critical(0, tr("Error creating Android templates"), reason);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::loadLocal(ProjectExplorer::Target *target, int apiLevel, ItemType item)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QString itemType;
|
|
|
|
if (item == Lib)
|
|
|
|
itemType = QLatin1String("lib");
|
|
|
|
else
|
|
|
|
itemType = QLatin1String("jar");
|
|
|
|
|
|
|
|
QString localLibs;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
QDomDocument doc;
|
2012-11-06 16:22:53 +01:00
|
|
|
if (!openXmlFile(doc, localLibsRulesFilePath(target)))
|
2012-04-24 15:49:09 +02:00
|
|
|
return localLibs;
|
|
|
|
|
|
|
|
QStringList libs;
|
|
|
|
libs << qtLibs(target) << prebundledLibs(target);
|
|
|
|
QDomElement element = doc.documentElement().firstChildElement(QLatin1String("platforms")).firstChildElement(itemType + QLatin1Char('s')).firstChildElement(QLatin1String("version"));
|
|
|
|
while (!element.isNull()) {
|
|
|
|
if (element.attribute(QLatin1String("value")).toInt() == apiLevel) {
|
|
|
|
if (element.hasAttribute(QLatin1String("symlink")))
|
|
|
|
apiLevel = element.attribute(QLatin1String("symlink")).toInt();
|
|
|
|
break;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
element = element.nextSiblingElement(QLatin1String("version"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
element = doc.documentElement().firstChildElement(QLatin1String("dependencies")).firstChildElement(QLatin1String("lib"));
|
|
|
|
while (!element.isNull()) {
|
|
|
|
if (libs.contains(element.attribute(QLatin1String("name")))) {
|
|
|
|
QDomElement libElement = element.firstChildElement(QLatin1String("depends")).firstChildElement(itemType);
|
|
|
|
while (!libElement.isNull()) {
|
|
|
|
localLibs += libElement.attribute(QLatin1String("file")).arg(apiLevel) + QLatin1Char(':');
|
|
|
|
libElement = libElement.nextSiblingElement(itemType);
|
|
|
|
}
|
|
|
|
|
|
|
|
libElement = element.firstChildElement(QLatin1String("replaces")).firstChildElement(itemType);
|
|
|
|
while (!libElement.isNull()) {
|
|
|
|
localLibs.replace(libElement.attribute(QLatin1String("file")).arg(apiLevel) + QLatin1Char(':'), QString());
|
|
|
|
libElement = libElement.nextSiblingElement(itemType);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
element = element.nextSiblingElement(QLatin1String("lib"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return localLibs;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:22:53 +01:00
|
|
|
bool AndroidManager::openXmlFile(QDomDocument &doc, const Utils::FileName &fileName)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QFile f(fileName.toString());
|
|
|
|
if (!f.open(QIODevice::ReadOnly))
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!doc.setContent(f.readAll())) {
|
|
|
|
raiseError(tr("Can't parse '%1'").arg(fileName.toUserOutput()));
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return true;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::saveXmlFile(ProjectExplorer::Target *target, QDomDocument &doc, const Utils::FileName &fileName)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!createAndroidTemplatesIfNecessary(target))
|
|
|
|
return false;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QFile f(fileName.toString());
|
|
|
|
if (!f.open(QIODevice::WriteOnly)) {
|
|
|
|
raiseError(tr("Can't open '%1'").arg(fileName.toUserOutput()));
|
|
|
|
return false;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
return f.write(doc.toByteArray(4)) >= 0;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::openManifest(ProjectExplorer::Target *target, QDomDocument &doc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-11-06 16:22:53 +01:00
|
|
|
return openXmlFile(doc, manifestPath(target));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::saveManifest(ProjectExplorer::Target *target, QDomDocument &doc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return saveXmlFile(target, doc, manifestPath(target));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QString AndroidManager::iconPath(ProjectExplorer::Target *target, AndroidManager::IconType type)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case HighDPI:
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(QLatin1String("res/drawable-hdpi/icon.png")).toString();
|
2012-04-18 20:30:57 +03:00
|
|
|
case MediumDPI:
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(QLatin1String("res/drawable-mdpi/icon.png")).toString();
|
2012-04-18 20:30:57 +03:00
|
|
|
case LowDPI:
|
2012-04-24 15:49:09 +02:00
|
|
|
return dirPath(target).appendPath(QLatin1String("res/drawable-ldpi/icon.png")).toString();
|
|
|
|
default:
|
|
|
|
return QString();
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::libsXml(ProjectExplorer::Target *target, const QString &tag)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
QStringList libs;
|
|
|
|
QDomDocument doc;
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!openLibsXml(target, doc))
|
2012-04-18 20:30:57 +03:00
|
|
|
return libs;
|
|
|
|
QDomElement arrayElem = doc.documentElement().firstChildElement(QLatin1String("array"));
|
|
|
|
while (!arrayElem.isNull()) {
|
|
|
|
if (arrayElem.attribute(QLatin1String("name")) == tag) {
|
|
|
|
arrayElem = arrayElem.firstChildElement(QLatin1String("item"));
|
|
|
|
while (!arrayElem.isNull()) {
|
|
|
|
libs << arrayElem.text();
|
|
|
|
arrayElem = arrayElem.nextSiblingElement(QLatin1String("item"));
|
|
|
|
}
|
|
|
|
return libs;
|
|
|
|
}
|
|
|
|
arrayElem = arrayElem.nextSiblingElement(QLatin1String("array"));
|
|
|
|
}
|
|
|
|
return libs;
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setLibsXml(ProjectExplorer::Target *target, const QStringList &libs, const QString &tag)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
QDomDocument doc;
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!openLibsXml(target, doc))
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
QDomElement arrayElem = doc.documentElement().firstChildElement(QLatin1String("array"));
|
|
|
|
while (!arrayElem.isNull()) {
|
|
|
|
if (arrayElem.attribute(QLatin1String("name")) == tag) {
|
|
|
|
doc.documentElement().removeChild(arrayElem);
|
|
|
|
arrayElem = doc.createElement(QLatin1String("array"));
|
|
|
|
arrayElem.setAttribute(QLatin1String("name"), tag);
|
|
|
|
foreach (const QString &lib, libs) {
|
|
|
|
QDomElement item = doc.createElement(QLatin1String("item"));
|
|
|
|
item.appendChild(doc.createTextNode(lib));
|
|
|
|
arrayElem.appendChild(item);
|
|
|
|
}
|
|
|
|
doc.documentElement().appendChild(arrayElem);
|
2012-04-24 15:49:09 +02:00
|
|
|
return saveLibsXml(target, doc);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
arrayElem = arrayElem.nextSiblingElement(QLatin1String("array"));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QIcon AndroidManager::icon(ProjectExplorer::Target *target, IconType type)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
return QIcon(iconPath(target, type));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::setIcon(ProjectExplorer::Target *target, IconType type, const QString &iconFileName)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!QFileInfo(iconFileName).exists())
|
|
|
|
return false;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
const QString path = iconPath(target, type);
|
|
|
|
QFile::remove(path);
|
|
|
|
return QFile::copy(iconFileName, path);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList AndroidManager::dependencies(const Utils::FileName &readelfPath, const QString &lib)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QProcess readelfProc;
|
|
|
|
readelfProc.start(readelfPath.toString(), QStringList() << QLatin1String("-d") << QLatin1String("-W") << lib);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!readelfProc.waitForFinished(-1)) {
|
2012-12-10 23:43:21 +00:00
|
|
|
readelfProc.kill();
|
2012-04-24 15:49:09 +02:00
|
|
|
return libs;
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QList<QByteArray> lines = readelfProc.readAll().trimmed().split('\n');
|
|
|
|
foreach (const QByteArray &line, lines) {
|
|
|
|
if (line.contains("(NEEDED)") && line.contains("Shared library:") ) {
|
|
|
|
const int pos = line.lastIndexOf('[') + 1;
|
|
|
|
libs << QString::fromLatin1(line.mid(pos, line.lastIndexOf(']') - pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return libs;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
int AndroidManager::setLibraryLevel(const QString &library, LibrariesMap &mapLibs)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
int maxlevel = mapLibs[library].level;
|
|
|
|
if (maxlevel > 0)
|
|
|
|
return maxlevel;
|
|
|
|
foreach (QString lib, mapLibs[library].dependencies) {
|
|
|
|
foreach (const QString &key, mapLibs.keys()) {
|
|
|
|
if (library == key)
|
|
|
|
continue;
|
|
|
|
if (key == lib) {
|
|
|
|
int libLevel = mapLibs[key].level;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (libLevel < 0)
|
|
|
|
libLevel = setLibraryLevel(key, mapLibs);
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
if (libLevel > maxlevel)
|
|
|
|
maxlevel = libLevel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
if (mapLibs[library].level < 0)
|
|
|
|
mapLibs[library].level = maxlevel + 1;
|
|
|
|
return maxlevel + 1;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool AndroidManager::qtLibrariesLessThan(const Library &a, const Library &b)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (a.level == b.level)
|
|
|
|
return a.name < b.name;
|
|
|
|
return a.level < b.level;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Qt4ProjectManager
|