| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2014-01-07 13:27:11 +01:00
										 |  |  | ** Copyright (c) 2014 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"
 | 
					
						
							| 
									
										
										
										
											2013-01-25 16:49:22 +01:00
										 |  |  | #include "androidtoolchain.h"
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  | #include "androiddeployqtstep.h"
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 17:27:06 +02:00
										 |  |  | #include <coreplugin/documentmanager.h>
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  | #include <coreplugin/messagemanager.h>
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | #include <projectexplorer/projectexplorer.h>
 | 
					
						
							|  |  |  | #include <projectexplorer/session.h>
 | 
					
						
							|  |  |  | #include <projectexplorer/target.h>
 | 
					
						
							| 
									
										
										
										
											2013-10-29 16:19:24 +01:00
										 |  |  | #include <qmakeprojectmanager/qmakenodes.h>
 | 
					
						
							|  |  |  | #include <qmakeprojectmanager/qmakeproject.h>
 | 
					
						
							|  |  |  | #include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
 | 
					
						
							|  |  |  | #include <qmakeprojectmanager/qmakebuildconfiguration.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"); | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     const QLatin1String AndroidLibraryPrefix("--Managed_by_Qt_Creator--"); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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('_'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 18:34:49 +02:00
										 |  |  |         static QStringList keywords; | 
					
						
							|  |  |  |         if (keywords.isEmpty()) | 
					
						
							|  |  |  |             keywords << QLatin1String("abstract") << QLatin1String("continue") << QLatin1String("for") | 
					
						
							|  |  |  |                      << QLatin1String("new") << QLatin1String("switch") << QLatin1String("assert") | 
					
						
							|  |  |  |                      << QLatin1String("default") << QLatin1String("if") << QLatin1String("package") | 
					
						
							|  |  |  |                      << QLatin1String("synchronized") << QLatin1String("boolean") << QLatin1String("do") | 
					
						
							|  |  |  |                      << QLatin1String("goto") << QLatin1String("private") << QLatin1String("this") | 
					
						
							|  |  |  |                      << QLatin1String("break") << QLatin1String("double") << QLatin1String("implements") | 
					
						
							|  |  |  |                      << QLatin1String("protected") << QLatin1String("throw") << QLatin1String("byte") | 
					
						
							|  |  |  |                      << QLatin1String("else") << QLatin1String("import") << QLatin1String("public") | 
					
						
							|  |  |  |                      << QLatin1String("throws") << QLatin1String("case") << QLatin1String("enum") | 
					
						
							|  |  |  |                      << QLatin1String("instanceof") << QLatin1String("return") << QLatin1String("transient") | 
					
						
							|  |  |  |                      << QLatin1String("catch") << QLatin1String("extends") << QLatin1String("int") | 
					
						
							|  |  |  |                      << QLatin1String("short") << QLatin1String("try") << QLatin1String("char") | 
					
						
							|  |  |  |                      << QLatin1String("final") << QLatin1String("interface") << QLatin1String("static") | 
					
						
							|  |  |  |                      << QLatin1String("void") << QLatin1String("class") << QLatin1String("finally") | 
					
						
							|  |  |  |                      << QLatin1String("long") << QLatin1String("strictfp") << QLatin1String("volatile") | 
					
						
							|  |  |  |                      << QLatin1String("const") << QLatin1String("float") << QLatin1String("native") | 
					
						
							|  |  |  |                      << QLatin1String("super") << QLatin1String("while"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // No keywords
 | 
					
						
							|  |  |  |         int index = -1; | 
					
						
							|  |  |  |         while (index != packageName.length()) { | 
					
						
							|  |  |  |             int next = packageName.indexOf(QLatin1Char('.'), index + 1); | 
					
						
							|  |  |  |             if (next == -1) | 
					
						
							|  |  |  |                 next = packageName.length(); | 
					
						
							|  |  |  |             QString word = packageName.mid(index + 1, next - index - 1); | 
					
						
							|  |  |  |             if (!word.isEmpty()) { | 
					
						
							|  |  |  |                 QChar c = word[0]; | 
					
						
							|  |  |  |                 if (c >= QChar(QLatin1Char('0')) && c<= QChar(QLatin1Char('9'))) { | 
					
						
							|  |  |  |                     packageName.insert(index + 1, QLatin1Char('_')); | 
					
						
							|  |  |  |                     index = next + 1; | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (keywords.contains(word)) { | 
					
						
							|  |  |  |                 packageName.insert(next, QLatin1String("_")); | 
					
						
							|  |  |  |                 index = next + 1; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 index = next; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-29 14:22:31 +01:00
										 |  |  |     if (!qobject_cast<QmakeProjectManager::QmakeProject *>(target->project())) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         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
										 |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 15:23:04 +02:00
										 |  |  | int AndroidManager::minimumSDK(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDomDocument doc; | 
					
						
							|  |  |  |     if (!openManifest(target, doc)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     QDomElement manifestElem = doc.documentElement(); | 
					
						
							|  |  |  |     QDomElement usesSdk = manifestElem.firstChildElement(QLatin1String("uses-sdk")); | 
					
						
							|  |  |  |     if (usesSdk.isNull()) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     if (usesSdk.hasAttribute(QLatin1String("android:minSdkVersion"))) { | 
					
						
							|  |  |  |         bool ok; | 
					
						
							|  |  |  |         int tmp = usesSdk.attribute(QLatin1String("android:minSdkVersion")).toInt(&ok); | 
					
						
							|  |  |  |         if (ok) | 
					
						
							|  |  |  |             return tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 15:20:54 +02:00
										 |  |  | QString AndroidManager::buildTargetSDK(ProjectExplorer::Target *target) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit()); | 
					
						
							|  |  |  |     if (qt && qt->qtVersion() >= QtSupport::QtVersionNumber(5, 2, 0)) { | 
					
						
							|  |  |  |         if (!target->activeDeployConfiguration()) | 
					
						
							|  |  |  |             return QLatin1String("android-9"); | 
					
						
							|  |  |  |         AndroidDeployQtStep *step = AndroidGlobal::buildStep<AndroidDeployQtStep>(target->activeDeployConfiguration()); | 
					
						
							|  |  |  |         if (step) | 
					
						
							|  |  |  |             return step->buildTargetSdk(); | 
					
						
							|  |  |  |         return QLatin1String("android-9"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 16:27:31 +02:00
										 |  |  |     QVariant v = target->namedSettings(QLatin1String("AndroidManager.TargetSdk")); | 
					
						
							|  |  |  |     if (v.isValid()) | 
					
						
							|  |  |  |         return v.toString(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 16:18:36 +02:00
										 |  |  |     QString fallback = QLatin1String("android-8"); | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     if (qt && qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0)) | 
					
						
							|  |  |  |         fallback = QLatin1String("android-9"); | 
					
						
							| 
									
										
										
										
											2013-04-10 16:18:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     if (!createAndroidTemplatesIfNecessary(target)) | 
					
						
							| 
									
										
										
										
											2013-10-17 13:12:55 +02:00
										 |  |  |         return fallback; | 
					
						
							| 
									
										
										
										
											2013-04-19 16:27:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     QFile file(defaultPropertiesPath(target).toString()); | 
					
						
							|  |  |  |     if (!file.open(QIODevice::ReadOnly)) | 
					
						
							| 
									
										
										
										
											2013-10-17 13:12:55 +02:00
										 |  |  |         return fallback; | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     while (!file.atEnd()) { | 
					
						
							|  |  |  |         QByteArray line = file.readLine(); | 
					
						
							|  |  |  |         if (line.startsWith("target=")) | 
					
						
							|  |  |  |             return QString::fromLatin1(line.trimmed().mid(7)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-10-17 13:12:55 +02:00
										 |  |  |     return fallback; | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 15:20:54 +02:00
										 |  |  | bool AndroidManager::setBuildTargetSDK(ProjectExplorer::Target *target, const QString &sdk) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     updateTarget(target, sdk, applicationName(target)); | 
					
						
							| 
									
										
										
										
											2013-04-19 16:27:31 +02:00
										 |  |  |     target->setNamedSettings(QLatin1String("AndroidManager.TargetSdk"), sdk); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 15:10:21 +02:00
										 |  |  | QString AndroidManager::targetArch(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-29 14:22:31 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *pro = qobject_cast<QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							| 
									
										
										
										
											2013-05-03 15:10:21 +02:00
										 |  |  |     if (!pro) | 
					
						
							|  |  |  |         return QString(); | 
					
						
							| 
									
										
										
										
											2013-10-29 14:22:31 +01:00
										 |  |  |     QmakeProjectManager::QmakeProFileNode *node = pro->rootQmakeProjectNode(); | 
					
						
							| 
									
										
										
										
											2013-05-03 15:10:21 +02:00
										 |  |  |     if (!node) | 
					
						
							|  |  |  |         return QString(); | 
					
						
							| 
									
										
										
										
											2013-10-16 11:02:37 +02:00
										 |  |  |     return node->singleVariableValue(QmakeProjectManager::AndroidArchVar); | 
					
						
							| 
									
										
										
										
											2013-05-03 15:10:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | Utils::FileName AndroidManager::dirPath(ProjectExplorer::Target *target) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target->kit()); | 
					
						
							|  |  |  |     if (qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber(5, 2, 0)) | 
					
						
							| 
									
										
										
										
											2013-11-06 13:06:10 +01:00
										 |  |  |         return target->activeBuildConfiguration()->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY)); | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     QString packageName = QLatin1String("QtApp"); | 
					
						
							|  |  |  |     QString buildTypeName; | 
					
						
							|  |  |  |     if (buildType == DebugBuild) | 
					
						
							|  |  |  |         buildTypeName = QLatin1String("debug"); | 
					
						
							|  |  |  |     else if (buildType == ReleaseBuildUnsigned) | 
					
						
							|  |  |  |         buildTypeName =QLatin1String("release-unsigned"); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         buildTypeName = QLatin1String("release"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit()); | 
					
						
							|  |  |  |     if (!qt || qt->qtVersion() < QtSupport::QtVersionNumber(5, 2, 0)) { | 
					
						
							|  |  |  |         // Qt 5.1 and earlier:
 | 
					
						
							|  |  |  |         packageName = applicationName(target); | 
					
						
							|  |  |  |         if (buildType == ReleaseBuildSigned) | 
					
						
							|  |  |  |             buildTypeName = QLatin1String("signed"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     return dirPath(target) | 
					
						
							|  |  |  |             .appendPath(QLatin1String("bin")) | 
					
						
							|  |  |  |             .appendPath(QString::fromLatin1("%1-%2.apk") | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |                         .arg(packageName) | 
					
						
							|  |  |  |                         .arg(buildTypeName)); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | QStringList AndroidManager::availableTargetApplications(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList apps; | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							|  |  |  |     if (!qmakeProject) | 
					
						
							| 
									
										
										
										
											2013-08-28 16:28:47 +02:00
										 |  |  |         return apps; | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     foreach (QmakeProjectManager::QmakeProFileNode *proFile, qmakeProject->applicationProFiles()) { | 
					
						
							| 
									
										
										
										
											2013-10-16 11:02:37 +02:00
										 |  |  |         if (proFile->projectType() == QmakeProjectManager::ApplicationTemplate) { | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |             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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  | // Note, this could be implemented via a base class and a couple of virtuals
 | 
					
						
							|  |  |  | // but I intend to remove the indirection once we drop support for qt 4.8
 | 
					
						
							|  |  |  | // and qt 5.1.
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | bool AndroidManager::bundleQt(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     AndroidDeployStep *androidDeployStep | 
					
						
							|  |  |  |         = AndroidGlobal::buildStep<AndroidDeployStep>(target->activeDeployConfiguration()); | 
					
						
							| 
									
										
										
										
											2013-11-11 22:20:47 +02:00
										 |  |  |     if (androidDeployStep) | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         return androidDeployStep->deployAction() == AndroidDeployStep::BundleLibraries; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AndroidDeployQtStep *androidDeployQtStep | 
					
						
							|  |  |  |             = AndroidGlobal::buildStep<AndroidDeployQtStep>(target->activeDeployConfiguration()); | 
					
						
							| 
									
										
										
										
											2013-11-11 22:20:47 +02:00
										 |  |  |     if (androidDeployQtStep) | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         return androidDeployQtStep->deployAction() == AndroidDeployQtStep::BundleLibrariesDeployment; | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  | bool AndroidManager::useLocalLibs(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     AndroidDeployStep *androidDeployStep | 
					
						
							|  |  |  |         = AndroidGlobal::buildStep<AndroidDeployStep>(target->activeDeployConfiguration()); | 
					
						
							|  |  |  |     if (androidDeployStep) { | 
					
						
							|  |  |  |         return androidDeployStep->deployAction() == AndroidDeployStep::DeployLocal | 
					
						
							|  |  |  |                 || androidDeployStep->deployAction() == AndroidDeployStep::BundleLibraries; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AndroidDeployQtStep *androidDeployQtStep | 
					
						
							|  |  |  |             = AndroidGlobal::buildStep<AndroidDeployQtStep>(target->activeDeployConfiguration()); | 
					
						
							|  |  |  |     if (androidDeployQtStep) { | 
					
						
							|  |  |  |         return androidDeployQtStep->deployAction() == AndroidDeployQtStep::DebugDeployment | 
					
						
							|  |  |  |                 || androidDeployQtStep->deployAction() == AndroidDeployQtStep::BundleLibrariesDeployment; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString AndroidManager::deviceSerialNumber(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     AndroidDeployStep *androidDeployStep | 
					
						
							|  |  |  |         = AndroidGlobal::buildStep<AndroidDeployStep>(target->activeDeployConfiguration()); | 
					
						
							|  |  |  |     if (androidDeployStep) | 
					
						
							|  |  |  |         return androidDeployStep->deviceSerialNumber(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AndroidDeployQtStep *androidDeployQtStep | 
					
						
							|  |  |  |             = AndroidGlobal::buildStep<AndroidDeployQtStep>(target->activeDeployConfiguration()); | 
					
						
							|  |  |  |     if (androidDeployQtStep) | 
					
						
							|  |  |  |         return androidDeployQtStep->deviceSerialNumber(); | 
					
						
							|  |  |  |     return QString(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | bool AndroidManager::updateDeploymentSettings(ProjectExplorer::Target *target) | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // For Qt 4, the "use local libs" options is handled by passing command line arguments to the
 | 
					
						
							|  |  |  |     // app, so no need to alter the AndroidManifest.xml
 | 
					
						
							|  |  |  |     QtSupport::BaseQtVersion *baseQtVersion = QtSupport::QtKitInformation::qtVersion(target->kit()); | 
					
						
							|  |  |  |     if (baseQtVersion == 0 || baseQtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0)) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     if (baseQtVersion->qtVersion() >= QtSupport::QtVersionNumber(5, 2, 0)) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     ProjectExplorer::RunConfiguration *runConfiguration = target->activeRunConfiguration(); | 
					
						
							|  |  |  |     AndroidRunConfiguration *androidRunConfiguration = qobject_cast<AndroidRunConfiguration *>(runConfiguration); | 
					
						
							|  |  |  |     if (androidRunConfiguration == 0) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     bool useLocalLibs = AndroidManager::useLocalLibs(target); | 
					
						
							|  |  |  |     bool bundleQtLibs = AndroidManager::bundleQt(target); | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  |     QDomDocument doc; | 
					
						
							|  |  |  |     if (!openManifest(target, doc)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity")).firstChildElement(QLatin1String("meta-data")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     // ### Passes -1 for API level, which means it won't work with setups that require
 | 
					
						
							|  |  |  |     // library selection based on API level. Use the old approach (command line argument)
 | 
					
						
							|  |  |  |     // in these cases. Hence the Qt version > 4 condition at the beginning of this function.
 | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  |     QString localLibs; | 
					
						
							|  |  |  |     QString localJars; | 
					
						
							|  |  |  |     QString staticInitClasses; | 
					
						
							|  |  |  |     if (useLocalLibs) { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |         localLibs = loadLocalLibs(target, -1); | 
					
						
							|  |  |  |         localJars = loadLocalJars(target, -1); | 
					
						
							|  |  |  |         staticInitClasses = loadLocalJarsInitClasses(target, -1); | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool changedManifest = false; | 
					
						
							|  |  |  |     while (!metadataElem.isNull()) { | 
					
						
							|  |  |  |         if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.use_local_qt_libs")) { | 
					
						
							| 
									
										
										
										
											2013-03-27 16:22:29 +02:00
										 |  |  |             if (metadataElem.attribute(QLatin1String("android:value")).toInt() != int(useLocalLibs)) { | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  |                 metadataElem.setAttribute(QLatin1String("android:value"), int(useLocalLibs)); | 
					
						
							|  |  |  |                 changedManifest = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.load_local_libs")) { | 
					
						
							|  |  |  |             if (metadataElem.attribute(QLatin1String("android:value")) != localLibs) { | 
					
						
							|  |  |  |                 metadataElem.setAttribute(QLatin1String("android:value"), localLibs); | 
					
						
							|  |  |  |                 changedManifest = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.load_local_jars")) { | 
					
						
							|  |  |  |             if (metadataElem.attribute(QLatin1String("android:value")) != localJars) { | 
					
						
							|  |  |  |                 metadataElem.setAttribute(QLatin1String("android:value"), localJars); | 
					
						
							|  |  |  |                 changedManifest = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.static_init_classes")) { | 
					
						
							|  |  |  |             if (metadataElem.attribute(QLatin1String("android:value")) != staticInitClasses) { | 
					
						
							|  |  |  |                 metadataElem.setAttribute(QLatin1String("android:value"), staticInitClasses); | 
					
						
							|  |  |  |                 changedManifest = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |         } else if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.bundle_local_qt_libs")) { | 
					
						
							| 
									
										
										
										
											2013-05-16 22:07:14 +03:00
										 |  |  |             if (metadataElem.attribute(QLatin1String("android:value")).toInt() != int(bundleQtLibs)) { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |                 metadataElem.setAttribute(QLatin1String("android:value"), int(bundleQtLibs)); | 
					
						
							|  |  |  |                 changedManifest = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-03-07 13:22:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         metadataElem = metadataElem.nextSiblingElement(QLatin1String("meta-data")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (changedManifest) | 
					
						
							|  |  |  |         return saveManifest(target, doc); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							|  |  |  |     foreach (QmakeProjectManager::QmakeProFileNode *proFile, qmakeProject->applicationProFiles()) { | 
					
						
							| 
									
										
										
										
											2013-10-16 11:02:37 +02:00
										 |  |  |         if (proFile->projectType() == QmakeProjectManager::ApplicationTemplate) { | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |             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()); | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject*>(target->project()); | 
					
						
							|  |  |  |     if (!qmakeProject || !qmakeProject->rootProjectNode() || !version) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     // TODO we should create the AndroidManifest.xml file for that version
 | 
					
						
							|  |  |  |     if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 2, 0)) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     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")); | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     QDir projectDir(qmakeProject->projectDirectory()); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     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()) | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |         qmakeProject->rootProjectNode()->addFiles(androidFiles); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 16:18:36 +02:00
										 |  |  |     int minApiLevel = 4; | 
					
						
							|  |  |  |     if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit())) | 
					
						
							|  |  |  |         if (qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0)) | 
					
						
							|  |  |  |             minApiLevel = 9; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList sdks = AndroidConfigurations::instance().sdkTargets(minApiLevel); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     if (sdks.isEmpty()) { | 
					
						
							|  |  |  |         raiseError(tr("No Qt for Android SDKs were found.\nPlease install at least one SDK.")); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-10 16:18:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-17 13:23:08 +02:00
										 |  |  |     updateTarget(target, sdks.first()); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |         QMessageBox::warning(0, tr("Warning"), tr("Android files have been updated automatically.")); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | void AndroidManager::updateTarget(ProjectExplorer::Target *target, const QString &targetSDK, const QString &name) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target->kit()); | 
					
						
							|  |  |  |     if (qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber(5,2,0)) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     QString androidDir = dirPath(target).toString(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 18:18:38 +02:00
										 |  |  |     Utils::Environment env = Utils::Environment::systemEnvironment(); | 
					
						
							|  |  |  |     QString javaHome = AndroidConfigurations::instance().config().openJDKLocation.toString(); | 
					
						
							|  |  |  |     if (!javaHome.isEmpty()) | 
					
						
							|  |  |  |         env.set(QLatin1String("JAVA_HOME"), javaHome); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |     // clean previous build
 | 
					
						
							|  |  |  |     QProcess androidProc; | 
					
						
							|  |  |  |     androidProc.setWorkingDirectory(androidDir); | 
					
						
							| 
									
										
										
										
											2013-06-10 18:18:38 +02:00
										 |  |  |     androidProc.setProcessEnvironment(env.toProcessEnvironment()); | 
					
						
							| 
									
										
										
										
											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++) { | 
					
						
							| 
									
										
										
										
											2013-06-03 19:58:30 +02:00
										 |  |  |             QByteArray trimmed = lines[i].trimmed(); | 
					
						
							|  |  |  |             if (trimmed.contains("@ANDROID-")) { | 
					
						
							|  |  |  |                 commentLines = targetSDKNumber < trimmed.mid(trimmed.lastIndexOf('-') + 1).toInt(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |                 comment = !comment; | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (!comment) | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             if (commentLines) { | 
					
						
							| 
									
										
										
										
											2013-06-03 19:58:30 +02:00
										 |  |  |                 if (!trimmed.startsWith("//QtCreator")) { | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |                     lines[i] = "//QtCreator " + lines[i]; | 
					
						
							|  |  |  |                     modified = true; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-06-03 19:58:30 +02:00
										 |  |  |             } else { if (trimmed.startsWith("//QtCreator")) { | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |                     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; | 
					
						
							| 
									
										
										
										
											2013-11-19 17:25:32 +01:00
										 |  |  |     androidProc.setProcessEnvironment(AndroidConfigurations::instance().androidToolEnvironment().toProcessEnvironment()); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |     return Utils::FileName::fromString(version->qmakeProperty("QT_INSTALL_LIBS")); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | QString AndroidManager::loadLocalBundledFiles(ProjectExplorer::Target *target, int apiLevel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return loadLocal(target, apiLevel, BundledFile); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | QString AndroidManager::loadLocalJars(ProjectExplorer::Target *target, int apiLevel) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     ItemType type = bundleQt(target) ? BundledJar : Jar; | 
					
						
							|  |  |  |     return loadLocal(target, apiLevel, type); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-06 16:23:08 +02:00
										 |  |  | QString AndroidManager::loadLocalJarsInitClasses(ProjectExplorer::Target *target, int apiLevel) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     ItemType type = bundleQt(target) ? BundledJar : Jar; | 
					
						
							|  |  |  |     return loadLocal(target, apiLevel, type, QLatin1String("initClass")); | 
					
						
							| 
									
										
										
										
											2013-01-06 16:23:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-14 13:39:45 +02:00
										 |  |  | QPair<int, int> AndroidManager::apiLevelRange(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // 4 is the minimum version on which qt is supported
 | 
					
						
							|  |  |  |     // 19 and 20 are not yet released, but allow the user
 | 
					
						
							|  |  |  |     // to set them
 | 
					
						
							|  |  |  |     int minApiLevel = 4; | 
					
						
							|  |  |  |     QtSupport::BaseQtVersion *qt; | 
					
						
							|  |  |  |     if (target && (qt = QtSupport::QtKitInformation::qtVersion(target->kit()))) | 
					
						
							|  |  |  |         if (qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0)) | 
					
						
							|  |  |  |             minApiLevel = 9; | 
					
						
							|  |  |  |     return qMakePair(minApiLevel, 20); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString AndroidManager::androidNameForApiLevel(int x) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch (x) { | 
					
						
							|  |  |  |     case 4: | 
					
						
							|  |  |  |         return QLatin1String("Android 1.6"); | 
					
						
							|  |  |  |     case 5: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.0"); | 
					
						
							|  |  |  |     case 6: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.0.1"); | 
					
						
							|  |  |  |     case 7: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.1.x"); | 
					
						
							|  |  |  |     case 8: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.2.x"); | 
					
						
							|  |  |  |     case 9: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.3, 2.3.1, 2.3.2"); | 
					
						
							|  |  |  |     case 10: | 
					
						
							|  |  |  |         return QLatin1String("Android 2.3.3, 2.3.4"); | 
					
						
							|  |  |  |     case 11: | 
					
						
							|  |  |  |         return QLatin1String("Android 3.0.x"); | 
					
						
							|  |  |  |     case 12: | 
					
						
							|  |  |  |         return QLatin1String("Android 3.1.x"); | 
					
						
							|  |  |  |     case 13: | 
					
						
							|  |  |  |         return QLatin1String("Android 3.2"); | 
					
						
							|  |  |  |     case 14: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.0, 4.0.1, 4.0.2"); | 
					
						
							|  |  |  |     case 15: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.0.3, 4.0.4"); | 
					
						
							|  |  |  |     case 16: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.1, 4.1.1"); | 
					
						
							|  |  |  |     case 17: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.2, 4.2.2"); | 
					
						
							|  |  |  |     case 18: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.3"); | 
					
						
							| 
									
										
										
										
											2013-11-12 12:14:33 +01:00
										 |  |  |     case 19: | 
					
						
							|  |  |  |         return QLatin1String("Android 4.4"); | 
					
						
							| 
									
										
										
										
											2013-08-14 13:39:45 +02:00
										 |  |  |     default: | 
					
						
							|  |  |  |         return QLatin1String("Unknown Android version."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  | QVector<AndroidManager::Library> AndroidManager::availableQtLibsWithDependencies(ProjectExplorer::Target *target) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02: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 (!target->activeRunConfiguration()) | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  |         return QVector<AndroidManager::Library>(); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-25 16:49:22 +01:00
										 |  |  |     ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(target->kit()); | 
					
						
							|  |  |  |     if (tc->type() != QLatin1String(Constants::ANDROID_TOOLCHAIN_TYPE)) | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  |         return QVector<AndroidManager::Library>(); | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 14:22:31 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *project = static_cast<QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							|  |  |  |     QString arch = project->rootQmakeProjectNode()->singleVariableValue(QmakeProjectManager::AndroidArchVar); | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-25 16:49:22 +01:00
										 |  |  |     AndroidToolChain *atc = static_cast<AndroidToolChain *>(tc); | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  |     QString libgnustl = libGnuStl(arch, atc->ndkToolChainVersion()); | 
					
						
							| 
									
										
										
										
											2013-01-25 16:49:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Utils::FileName readelfPath = AndroidConfigurations::instance().readelfPath(target->activeRunConfiguration()->abi().architecture(), | 
					
						
							|  |  |  |                                                                                 atc->ndkToolChainVersion()); | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     const QmakeProjectManager::QmakeProject *const qmakeProject | 
					
						
							| 
									
										
										
										
											2013-10-29 14:22:31 +01:00
										 |  |  |             = qobject_cast<const QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     if (!qmakeProject || !version) | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  |         return QVector<AndroidManager::Library>(); | 
					
						
							| 
									
										
										
										
											2012-07-06 13:29:45 +02:00
										 |  |  |     QString qtLibsPath = version->qmakeProperty("QT_INSTALL_LIBS"); | 
					
						
							| 
									
										
										
										
											2013-11-11 22:20:47 +02:00
										 |  |  |     if (!readelfPath.toFileInfo().exists()) | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  |         return QVector<AndroidManager::Library>(); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  |     const QString library = libgnustl.mid(libgnustl.lastIndexOf(QLatin1Char('/')) + 1); | 
					
						
							| 
									
										
										
										
											2013-09-03 18:48:02 +02:00
										 |  |  |     mapLibs[library] = Library(); | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     // clean dependencies
 | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |     const LibrariesMap::Iterator lend = mapLibs.end(); | 
					
						
							|  |  |  |     for (LibrariesMap::Iterator lit = mapLibs.begin(); lit != lend; ++lit) { | 
					
						
							|  |  |  |         Library &library = lit.value(); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         int it = 0; | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |         while (it < library.dependencies.size()) { | 
					
						
							|  |  |  |             const QString &dependName = library.dependencies[it]; | 
					
						
							|  |  |  |             if (!mapLibs.contains(dependName) && dependName.startsWith(QLatin1String("lib")) && dependName.endsWith(QLatin1String(".so"))) | 
					
						
							|  |  |  |                 library.dependencies.removeAt(it); | 
					
						
							| 
									
										
										
											
												Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
  # skip ast (excluding paste, astpath, and canv'ast'imer)
  next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
  s = File.read(file)
  next if s.include?('qlalr')
  orig = s.dup
  s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
    res = $&
    if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
      res
    else
      res.gsub!('} else', 'else')
      res.gsub!(/\n +} *\n/m, "\n")
      res.gsub(/ *{$/, '')
    end
  }
  s.gsub!(/ *$/, '')
  File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
											
										 
											2013-01-08 03:32:53 +02:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |                 ++it; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |         if (library.dependencies.isEmpty()) | 
					
						
							|  |  |  |             library.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
 | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |     for (LibrariesMap::Iterator lit = mapLibs.begin(); lit != lend; ++lit) { | 
					
						
							|  |  |  |         Library &library = lit.value(); | 
					
						
							|  |  |  |         const QString &key = lit.key(); | 
					
						
							|  |  |  |         if (library.level < 0) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |            setLibraryLevel(key, mapLibs); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |         if (library.name.isEmpty() && key.startsWith(QLatin1String("lib")) && key.endsWith(QLatin1String(".so"))) | 
					
						
							|  |  |  |             library.name = key.mid(3, key.length() - 6); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |         for (int it = 0; it < library.dependencies.size(); it++) { | 
					
						
							|  |  |  |             const QString &libName = library.dependencies[it]; | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |             if (libName.startsWith(QLatin1String("lib")) && libName.endsWith(QLatin1String(".so"))) | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |                 library.dependencies[it] = libName.mid(3, libName.length() - 6); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-03-12 14:33:22 +01:00
										 |  |  |         qtLibraries.push_back(library); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     qSort(qtLibraries.begin(), qtLibraries.end(), qtLibrariesLessThan); | 
					
						
							| 
									
										
										
										
											2013-03-05 14:20:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return qtLibraries; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QStringList AndroidManager::availableQtLibs(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList libs; | 
					
						
							|  |  |  |     QVector<Library> qtLibraries = availableQtLibsWithDependencies(target); | 
					
						
							|  |  |  |     foreach (Library lib, qtLibraries) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         libs.push_back(lib.name); | 
					
						
							|  |  |  |     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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | bool AndroidManager::setBundledInAssets(ProjectExplorer::Target *target, const QStringList &fileList) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return setLibsXml(target, fileList, QLatin1String("bundled_in_assets")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidManager::setBundledInLib(ProjectExplorer::Target *target, const QStringList &fileList) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return setLibsXml(target, fileList, QLatin1String("bundled_in_lib")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     QmakeProjectManager::QmakeProject *qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(target->project()); | 
					
						
							|  |  |  |     if (!qmakeProject) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         return libs; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 17:37:39 +01:00
										 |  |  |     foreach (QmakeProjectManager::QmakeProFileNode *node, qmakeProject->allProFiles()) | 
					
						
							| 
									
										
										
										
											2013-10-16 11:02:37 +02:00
										 |  |  |         if (node->projectType() == QmakeProjectManager::LibraryTemplate) | 
					
						
							| 
									
										
										
										
											2013-05-24 13:04:07 +02:00
										 |  |  |             libs << node->targetInformation().target; | 
					
						
							| 
									
										
										
										
											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::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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |     QMessageBox::critical(0, tr("Error creating Android templates."), reason); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-06 16:23:08 +02:00
										 |  |  | QString AndroidManager::loadLocal(ProjectExplorer::Target *target, int apiLevel, ItemType item, const QString &attribute) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     QString itemType; | 
					
						
							|  |  |  |     if (item == Lib) | 
					
						
							|  |  |  |         itemType = QLatin1String("lib"); | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |     else if (item == BundledFile) | 
					
						
							|  |  |  |         itemType = QLatin1String("bundled"); | 
					
						
							|  |  |  |     else // Jar or BundledJar
 | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         itemType = QLatin1String("jar"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString localLibs; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |     QDir rulesFilesDir(localLibsRulesFilePath(target).toString()); | 
					
						
							|  |  |  |     if (!rulesFilesDir.exists()) | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |         return localLibs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList libs; | 
					
						
							|  |  |  |     libs << qtLibs(target) << prebundledLibs(target); | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QFileInfoList rulesFiles = rulesFilesDir.entryInfoList(QStringList() << QLatin1String("*.xml"), | 
					
						
							|  |  |  |                                                            QDir::Files | QDir::Readable); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList dependencyLibs; | 
					
						
							|  |  |  |     QStringList replacedLibs; | 
					
						
							|  |  |  |     foreach (QFileInfo rulesFile, rulesFiles) { | 
					
						
							|  |  |  |         if (rulesFile.baseName() != QLatin1String("rules") | 
					
						
							|  |  |  |                 && !rulesFile.baseName().endsWith(QLatin1String("-android-dependencies"))) { | 
					
						
							|  |  |  |             continue; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |         QDomDocument doc; | 
					
						
							|  |  |  |         if (!openXmlFile(doc, Utils::FileName::fromString(rulesFile.absoluteFilePath()))) | 
					
						
							|  |  |  |             return localLibs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         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-24 15:49:09 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |             element = element.nextSiblingElement(QLatin1String("version")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         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()) { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |                     if (libElement.attribute(QLatin1String("bundling")).toInt() == (item == BundledJar ? 1 : 0)) { | 
					
						
							|  |  |  |                         if (libElement.hasAttribute(attribute)) { | 
					
						
							| 
									
										
										
										
											2013-09-06 15:14:11 +02:00
										 |  |  |                             QString dependencyLib = libElement.attribute(attribute); | 
					
						
							|  |  |  |                             if (dependencyLib.contains(QLatin1String("%1"))) | 
					
						
							|  |  |  |                                 dependencyLib = dependencyLib.arg(apiLevel); | 
					
						
							| 
									
										
										
										
											2013-05-16 03:58:26 +02:00
										 |  |  |                             if (libElement.hasAttribute(QLatin1String("extends"))) { | 
					
						
							|  |  |  |                                 const QString extends = libElement.attribute(QLatin1String("extends")); | 
					
						
							| 
									
										
										
										
											2013-11-11 22:20:47 +02:00
										 |  |  |                                 if (libs.contains(extends)) | 
					
						
							| 
									
										
										
										
											2013-05-16 03:58:26 +02:00
										 |  |  |                                     dependencyLibs << dependencyLib; | 
					
						
							|  |  |  |                             } else if (!dependencyLibs.contains(dependencyLib)) { | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |                                 dependencyLibs << dependencyLib; | 
					
						
							| 
									
										
										
										
											2013-05-16 03:58:26 +02:00
										 |  |  |                             } | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |                         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if (libElement.hasAttribute(QLatin1String("replaces"))) { | 
					
						
							| 
									
										
										
										
											2013-09-06 15:14:11 +02:00
										 |  |  |                             QString replacedLib = libElement.attribute(QLatin1String("replaces")); | 
					
						
							|  |  |  |                             if (replacedLib.contains(QLatin1String("%1"))) | 
					
						
							|  |  |  |                                 replacedLib = replacedLib.arg(apiLevel); | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  |                             if (!replacedLibs.contains(replacedLib)) | 
					
						
							|  |  |  |                                 replacedLibs << replacedLib; | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     libElement = libElement.nextSiblingElement(itemType); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 libElement = element.firstChildElement(QLatin1String("replaces")).firstChildElement(itemType); | 
					
						
							|  |  |  |                 while (!libElement.isNull()) { | 
					
						
							|  |  |  |                     if (libElement.hasAttribute(attribute)) { | 
					
						
							|  |  |  |                         QString replacedLib = libElement.attribute(attribute).arg(apiLevel); | 
					
						
							|  |  |  |                         if (!replacedLibs.contains(replacedLib)) | 
					
						
							|  |  |  |                             replacedLibs << replacedLib; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |                     libElement = libElement.nextSiblingElement(itemType); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |             element = element.nextSiblingElement(QLatin1String("lib")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // The next loop requires all library names to end with a ":" so we append one
 | 
					
						
							|  |  |  |     // to the end after joining.
 | 
					
						
							| 
									
										
										
										
											2013-02-18 16:20:28 +01:00
										 |  |  |     localLibs = dependencyLibs.join(QLatin1String(":")) + QLatin1Char(':'); | 
					
						
							| 
									
										
										
										
											2013-02-15 16:07:54 +01:00
										 |  |  |     foreach (QString replacedLib, replacedLibs) | 
					
						
							|  |  |  |         localLibs.remove(replacedLib + QLatin1Char(':')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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())) { | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |         raiseError(tr("Cannot 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)) { | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |         raiseError(tr("Cannot open '%1'.").arg(fileName.toUserOutput())); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-16 17:27:06 +02:00
										 |  |  |     Core::FileChangeBlocker blocker(manifestPath(target).toString()); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 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
										 |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-26 15:53:33 +01:00
										 |  |  | QString AndroidManager::libGnuStl(const QString &arch, const QString &ndkToolChainVersion) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return AndroidConfigurations::instance().config().ndkLocation.toString() | 
					
						
							|  |  |  |             + QLatin1String("/sources/cxx-stl/gnu-libstdc++/") | 
					
						
							|  |  |  |             + ndkToolChainVersion + QLatin1String("/libs/") | 
					
						
							|  |  |  |             + arch | 
					
						
							|  |  |  |             + QLatin1String("/libgnustl_shared.so"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 12:27:58 +02:00
										 |  |  | QString AndroidManager::libraryPrefix() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return AndroidLibraryPrefix; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AndroidManager::cleanLibsOnDevice(ProjectExplorer::Target *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QString targetArch = AndroidManager::targetArch(target); | 
					
						
							| 
									
										
										
										
											2013-10-09 16:24:25 +02:00
										 |  |  |     if (targetArch.isEmpty()) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     int deviceAPILevel = AndroidManager::minimumSDK(target); | 
					
						
							|  |  |  |     AndroidDeviceInfo info = AndroidConfigurations::instance().showDeviceDialog(target->project(), deviceAPILevel, targetArch); | 
					
						
							|  |  |  |     if (info.serialNumber.isEmpty()) // aborted
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deviceAPILevel = info.sdk; | 
					
						
							|  |  |  |     QString deviceSerialNumber = info.serialNumber; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (info.type == AndroidDeviceInfo::Emulator) { | 
					
						
							|  |  |  |         deviceSerialNumber = AndroidConfigurations::instance().startAVD(deviceSerialNumber, deviceAPILevel, targetArch); | 
					
						
							|  |  |  |         if (deviceSerialNumber.isEmpty()) | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |             Core::MessageManager::write(tr("Starting Android virtual device failed.")); | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QProcess *process = new QProcess(); | 
					
						
							|  |  |  |     QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber); | 
					
						
							|  |  |  |     arguments << QLatin1String("shell") << QLatin1String("rm") << QLatin1String("-r") << QLatin1String("/data/local/tmp/qt"); | 
					
						
							|  |  |  |     process->connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); | 
					
						
							|  |  |  |     const QString adb = AndroidConfigurations::instance().adbToolPath().toString(); | 
					
						
							|  |  |  |     Core::MessageManager::write(adb + QLatin1Char(' ') + arguments.join(QLatin1String(" "))); | 
					
						
							|  |  |  |     process->start(adb, arguments); | 
					
						
							|  |  |  |     if (!process->waitForStarted(500)) | 
					
						
							|  |  |  |         delete process; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AndroidManager::installQASIPackage(ProjectExplorer::Target *target, const QString &packagePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QString targetArch = AndroidManager::targetArch(target); | 
					
						
							| 
									
										
										
										
											2013-10-09 16:24:25 +02:00
										 |  |  |     if (targetArch.isEmpty()) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     int deviceAPILevel = AndroidManager::minimumSDK(target); | 
					
						
							|  |  |  |     AndroidDeviceInfo info = AndroidConfigurations::instance().showDeviceDialog(target->project(), deviceAPILevel, targetArch); | 
					
						
							|  |  |  |     if (info.serialNumber.isEmpty()) // aborted
 | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deviceAPILevel = info.sdk; | 
					
						
							|  |  |  |     QString deviceSerialNumber = info.serialNumber; | 
					
						
							|  |  |  |     if (info.type == AndroidDeviceInfo::Emulator) { | 
					
						
							|  |  |  |         deviceSerialNumber = AndroidConfigurations::instance().startAVD(deviceSerialNumber, deviceAPILevel, targetArch); | 
					
						
							|  |  |  |         if (deviceSerialNumber.isEmpty()) | 
					
						
							| 
									
										
										
										
											2013-10-09 16:37:42 +02:00
										 |  |  |             Core::MessageManager::write(tr("Starting Android virtual device failed.")); | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QProcess *process = new QProcess(); | 
					
						
							|  |  |  |     QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber); | 
					
						
							|  |  |  |     arguments << QLatin1String("install") << QLatin1String("-r ") << packagePath; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     process->connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); | 
					
						
							|  |  |  |     const QString adb = AndroidConfigurations::instance().adbToolPath().toString(); | 
					
						
							|  |  |  |     Core::MessageManager::write(adb + QLatin1Char(' ') + arguments.join(QLatin1String(" "))); | 
					
						
							|  |  |  |     process->start(adb, arguments); | 
					
						
							|  |  |  |     if (!process->waitForFinished(500)) | 
					
						
							|  |  |  |         delete process; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidManager::checkKeystorePassword(const QString &keystorePath, const QString &keystorePasswd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (keystorePasswd.isEmpty()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     QStringList arguments; | 
					
						
							|  |  |  |     arguments << QLatin1String("-list") | 
					
						
							|  |  |  |               << QLatin1String("-keystore") | 
					
						
							|  |  |  |               << keystorePath | 
					
						
							|  |  |  |               << QLatin1String("--storepass") | 
					
						
							|  |  |  |               << keystorePasswd; | 
					
						
							|  |  |  |     QProcess proc; | 
					
						
							|  |  |  |     proc.start(AndroidConfigurations::instance().keytoolPath().toString(), arguments); | 
					
						
							| 
									
										
										
										
											2013-12-10 12:58:10 +01:00
										 |  |  |     if (!proc.waitForStarted(4000)) | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2013-12-10 12:58:10 +01:00
										 |  |  |     if (!proc.waitForFinished(4000)) { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         proc.kill(); | 
					
						
							|  |  |  |         proc.waitForFinished(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return proc.exitCode() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const QString &keystorePasswd, const QString &alias, const QString &certificatePasswd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // assumes that the keystore password is correct
 | 
					
						
							|  |  |  |     QStringList arguments; | 
					
						
							|  |  |  |     arguments << QLatin1String("-certreq") | 
					
						
							|  |  |  |               << QLatin1String("-keystore") | 
					
						
							|  |  |  |               << keystorePath | 
					
						
							|  |  |  |               << QLatin1String("--storepass") | 
					
						
							|  |  |  |               << keystorePasswd | 
					
						
							|  |  |  |               << QLatin1String("-alias") | 
					
						
							|  |  |  |               << alias | 
					
						
							|  |  |  |               << QLatin1String("-keypass"); | 
					
						
							|  |  |  |     if (certificatePasswd.isEmpty()) | 
					
						
							|  |  |  |         arguments << keystorePasswd; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         arguments << certificatePasswd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QProcess proc; | 
					
						
							|  |  |  |     proc.start(AndroidConfigurations::instance().keytoolPath().toString(), arguments); | 
					
						
							| 
									
										
										
										
											2013-12-10 12:58:10 +01:00
										 |  |  |     if (!proc.waitForStarted(4000)) | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2013-12-10 12:58:10 +01:00
										 |  |  |     if (!proc.waitForFinished(4000)) { | 
					
						
							| 
									
										
										
										
											2013-09-17 18:24:57 +02:00
										 |  |  |         proc.kill(); | 
					
						
							|  |  |  |         proc.waitForFinished(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return proc.exitCode() == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidManager::checkForQt51Files(const QString &projectDirectory) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Utils::FileName fileName = Utils::FileName::fromString(projectDirectory); | 
					
						
							|  |  |  |     fileName.appendPath(QLatin1String("android")).appendPath(QLatin1String("version.xml")); | 
					
						
							|  |  |  |     if (!fileName.toFileInfo().exists()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     QDomDocument dstVersionDoc; | 
					
						
							|  |  |  |     if (!AndroidManager::openXmlFile(dstVersionDoc, fileName)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     return dstVersionDoc.documentElement().attribute(QLatin1String("value")).toDouble() < 5.2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } // namespace Internal
 | 
					
						
							| 
									
										
										
										
											2013-10-16 11:02:37 +02:00
										 |  |  | } // namespace Android
 |