forked from qt-creator/qt-creator
Android: Enable setting environment variables for android apps
Change-Id: Id4625f081d6997dcabad9b01fb09d6c9c6ef7477 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
@@ -55,7 +55,8 @@ HEADERS += \
|
|||||||
androidsdkmanagerwidget.h \
|
androidsdkmanagerwidget.h \
|
||||||
androidpackageinstallationstep.h \
|
androidpackageinstallationstep.h \
|
||||||
androidextralibrarylistmodel.h \
|
androidextralibrarylistmodel.h \
|
||||||
createandroidmanifestwizard.h
|
createandroidmanifestwizard.h \
|
||||||
|
androidrunenvironmentaspect.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
androidconfigurations.cpp \
|
androidconfigurations.cpp \
|
||||||
@@ -103,7 +104,8 @@ SOURCES += \
|
|||||||
androidsdkmanagerwidget.cpp \
|
androidsdkmanagerwidget.cpp \
|
||||||
androidpackageinstallationstep.cpp \
|
androidpackageinstallationstep.cpp \
|
||||||
androidextralibrarylistmodel.cpp \
|
androidextralibrarylistmodel.cpp \
|
||||||
createandroidmanifestwizard.cpp
|
createandroidmanifestwizard.cpp \
|
||||||
|
androidrunenvironmentaspect.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
androidsettingswidget.ui \
|
androidsettingswidget.ui \
|
||||||
|
@@ -85,6 +85,8 @@ Project {
|
|||||||
"androidqtversionfactory.h",
|
"androidqtversionfactory.h",
|
||||||
"androidrunconfiguration.cpp",
|
"androidrunconfiguration.cpp",
|
||||||
"androidrunconfiguration.h",
|
"androidrunconfiguration.h",
|
||||||
|
"androidrunenvironmentaspect.h",
|
||||||
|
"androidrunenvironmentaspect.cpp",
|
||||||
"androidruncontrol.cpp",
|
"androidruncontrol.cpp",
|
||||||
"androidruncontrol.h",
|
"androidruncontrol.h",
|
||||||
"androidrunner.cpp",
|
"androidrunner.cpp",
|
||||||
|
@@ -99,12 +99,11 @@ static QString toNdkArch(const QString &arch)
|
|||||||
return QLatin1String("arch-") + arch;
|
return QLatin1String("arch-") + arch;
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl, const QString &intentName,
|
AndroidDebugSupport::AndroidDebugSupport(RunControl *runControl, const QString &intentName)
|
||||||
const Utils::Environment &extraEnvVars)
|
|
||||||
: Debugger::DebuggerRunTool(runControl)
|
: Debugger::DebuggerRunTool(runControl)
|
||||||
{
|
{
|
||||||
setDisplayName("AndroidDebugger");
|
setDisplayName("AndroidDebugger");
|
||||||
m_runner = new AndroidRunner(runControl, intentName, extraEnvVars);
|
m_runner = new AndroidRunner(runControl, intentName);
|
||||||
addStartDependency(m_runner);
|
addStartDependency(m_runner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,8 +37,7 @@ class AndroidDebugSupport : public Debugger::DebuggerRunTool
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
AndroidDebugSupport(ProjectExplorer::RunControl *runControl,
|
AndroidDebugSupport(ProjectExplorer::RunControl *runControl,
|
||||||
const QString &intentName = QString(),
|
const QString &intentName = QString());
|
||||||
const Utils::Environment &extraEnvVars = Utils::Environment());
|
|
||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
|
@@ -32,13 +32,12 @@ namespace Android {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
AndroidQmlToolingSupport::AndroidQmlToolingSupport(RunControl *runControl,
|
AndroidQmlToolingSupport::AndroidQmlToolingSupport(RunControl *runControl,
|
||||||
const QString &intentName,
|
const QString &intentName)
|
||||||
const Utils::Environment &extraEnvVars)
|
|
||||||
: RunWorker(runControl)
|
: RunWorker(runControl)
|
||||||
{
|
{
|
||||||
setDisplayName("AndroidQmlToolingSupport");
|
setDisplayName("AndroidQmlToolingSupport");
|
||||||
|
|
||||||
auto runner = new AndroidRunner(runControl, intentName, extraEnvVars);
|
auto runner = new AndroidRunner(runControl, intentName);
|
||||||
addStartDependency(runner);
|
addStartDependency(runner);
|
||||||
|
|
||||||
auto profiler = runControl->createWorker(runControl->runMode());
|
auto profiler = runControl->createWorker(runControl->runMode());
|
||||||
|
@@ -36,9 +36,8 @@ class AndroidQmlToolingSupport : public ProjectExplorer::RunWorker
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AndroidQmlToolingSupport(
|
explicit AndroidQmlToolingSupport(ProjectExplorer::RunControl *runControl,
|
||||||
ProjectExplorer::RunControl *runControl, const QString &intentName = QString(),
|
const QString &intentName = QString());
|
||||||
const Utils::Environment &extraEnvVars = Utils::Environment());
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void start() override;
|
void start() override;
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "androidtoolchain.h"
|
#include "androidtoolchain.h"
|
||||||
#include "androidmanager.h"
|
#include "androidmanager.h"
|
||||||
#include "adbcommandswidget.h"
|
#include "adbcommandswidget.h"
|
||||||
|
#include "androidrunenvironmentaspect.h"
|
||||||
|
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
@@ -110,6 +111,7 @@ void BaseStringListAspect::setLabel(const QString &label)
|
|||||||
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
|
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
|
||||||
: RunConfiguration(target, id)
|
: RunConfiguration(target, id)
|
||||||
{
|
{
|
||||||
|
addExtraAspect(new AndroidRunEnvironmentAspect(this));
|
||||||
addExtraAspect(new ArgumentsAspect(this));
|
addExtraAspect(new ArgumentsAspect(this));
|
||||||
|
|
||||||
auto amStartArgsAspect = new BaseStringAspect(this);
|
auto amStartArgsAspect = new BaseStringAspect(this);
|
||||||
@@ -154,6 +156,7 @@ QWidget *AndroidRunConfiguration::createConfigurationWidget()
|
|||||||
|
|
||||||
extraAspect(Constants::ANDROID_PRESTARTSHELLCMDLIST)->addToConfigurationLayout(layout);
|
extraAspect(Constants::ANDROID_PRESTARTSHELLCMDLIST)->addToConfigurationLayout(layout);
|
||||||
extraAspect(Constants::ANDROID_POSTFINISHSHELLCMDLIST)->addToConfigurationLayout(layout);
|
extraAspect(Constants::ANDROID_POSTFINISHSHELLCMDLIST)->addToConfigurationLayout(layout);
|
||||||
|
extraAspect<AndroidRunEnvironmentAspect>()->addToConfigurationLayout(layout);
|
||||||
|
|
||||||
auto wrapped = wrapWidget(widget);
|
auto wrapped = wrapWidget(widget);
|
||||||
auto detailsWidget = qobject_cast<DetailsWidget *>(wrapped);
|
auto detailsWidget = qobject_cast<DetailsWidget *>(wrapped);
|
||||||
|
@@ -38,9 +38,8 @@ using namespace ProjectExplorer;
|
|||||||
namespace Android {
|
namespace Android {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
AndroidRunSupport::AndroidRunSupport(RunControl *runControl, const QString &intentName,
|
AndroidRunSupport::AndroidRunSupport(RunControl *runControl, const QString &intentName)
|
||||||
const Utils::Environment &extraEnvVars)
|
: AndroidRunner(runControl, intentName)
|
||||||
: AndroidRunner(runControl, intentName, extraEnvVars)
|
|
||||||
{
|
{
|
||||||
runControl->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR);
|
runControl->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR);
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,7 @@ class AndroidRunSupport : public AndroidRunner
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AndroidRunSupport(ProjectExplorer::RunControl *runControl,
|
explicit AndroidRunSupport(ProjectExplorer::RunControl *runControl,
|
||||||
const QString &intentName = QString(),
|
const QString &intentName = QString());
|
||||||
const Utils::Environment &extraEnvVars = Utils::Environment());
|
|
||||||
~AndroidRunSupport() override;
|
~AndroidRunSupport() override;
|
||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
|
48
src/plugins/android/androidrunenvironmentaspect.cpp
Normal file
48
src/plugins/android/androidrunenvironmentaspect.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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 The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
#include "androidrunenvironmentaspect.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
enum BaseEnvironmentBase {
|
||||||
|
CleanEnvironmentBase
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
|
||||||
|
AndroidRunEnvironmentAspect::AndroidRunEnvironmentAspect(ProjectExplorer::RunConfiguration *rc) :
|
||||||
|
ProjectExplorer::EnvironmentAspect (rc)
|
||||||
|
{
|
||||||
|
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::Environment AndroidRunEnvironmentAspect::baseEnvironment() const
|
||||||
|
{
|
||||||
|
// Clean Environment
|
||||||
|
return Utils::Environment();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Android
|
||||||
|
|
42
src/plugins/android/androidrunenvironmentaspect.h
Normal file
42
src/plugins/android/androidrunenvironmentaspect.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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 The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <projectexplorer/environmentaspect.h>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
|
||||||
|
class AndroidRunEnvironmentAspect : public ProjectExplorer::EnvironmentAspect
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AndroidRunEnvironmentAspect(ProjectExplorer::RunConfiguration *rc);
|
||||||
|
|
||||||
|
Utils::Environment baseEnvironment() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Android
|
||||||
|
|
@@ -118,9 +118,7 @@ using namespace Utils;
|
|||||||
namespace Android {
|
namespace Android {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
AndroidRunner::AndroidRunner(RunControl *runControl,
|
AndroidRunner::AndroidRunner(RunControl *runControl, const QString &intentName)
|
||||||
const QString &intentName,
|
|
||||||
const Utils::Environment &extraEnvVars)
|
|
||||||
: RunWorker(runControl), m_target(runControl->runConfiguration()->target())
|
: RunWorker(runControl), m_target(runControl->runConfiguration()->target())
|
||||||
{
|
{
|
||||||
setDisplayName("AndroidRunner");
|
setDisplayName("AndroidRunner");
|
||||||
@@ -144,7 +142,6 @@ AndroidRunner::AndroidRunner(RunControl *runControl,
|
|||||||
m_worker.reset(new AndroidRunnerWorker(this, m_packageName));
|
m_worker.reset(new AndroidRunnerWorker(this, m_packageName));
|
||||||
m_worker->setIntentName(intent);
|
m_worker->setIntentName(intent);
|
||||||
m_worker->setIsPreNougat(apiLevel <= 23);
|
m_worker->setIsPreNougat(apiLevel <= 23);
|
||||||
m_worker->setExtraEnvVars(extraEnvVars);
|
|
||||||
|
|
||||||
m_worker->moveToThread(&m_thread);
|
m_worker->moveToThread(&m_thread);
|
||||||
|
|
||||||
|
@@ -50,8 +50,7 @@ class AndroidRunner : public ProjectExplorer::RunWorker
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AndroidRunner(ProjectExplorer::RunControl *runControl,
|
explicit AndroidRunner(ProjectExplorer::RunControl *runControl,
|
||||||
const QString &intentName = QString(),
|
const QString &intentName = QString());
|
||||||
const Utils::Environment &extraEnvVars = Utils::Environment());
|
|
||||||
~AndroidRunner() override;
|
~AndroidRunner() override;
|
||||||
|
|
||||||
Utils::Port gdbServerPort() const { return m_gdbServerPort; }
|
Utils::Port gdbServerPort() const { return m_gdbServerPort; }
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "androidrunconfiguration.h"
|
#include "androidrunconfiguration.h"
|
||||||
|
|
||||||
#include <debugger/debuggerrunconfigurationaspect.h>
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
||||||
|
#include <projectexplorer/environmentaspect.h>
|
||||||
#include <projectexplorer/runconfigurationaspects.h>
|
#include <projectexplorer/runconfigurationaspects.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <qtsupport/baseqtversion.h>
|
#include <qtsupport/baseqtversion.h>
|
||||||
@@ -193,6 +194,10 @@ AndroidRunnerWorker::AndroidRunnerWorker(RunWorker *runner, const QString &packa
|
|||||||
m_deviceSerialNumber = AndroidManager::deviceSerialNumber(target);
|
m_deviceSerialNumber = AndroidManager::deviceSerialNumber(target);
|
||||||
m_apiLevel = AndroidManager::deviceApiLevel(target);
|
m_apiLevel = AndroidManager::deviceApiLevel(target);
|
||||||
|
|
||||||
|
m_extraEnvVars = runConfig->extraAspect<EnvironmentAspect>()->environment();
|
||||||
|
qCDebug(androidRunWorkerLog) << "Environment variables for the app"
|
||||||
|
<< m_extraEnvVars.toStringList();
|
||||||
|
|
||||||
m_extraAppParams = runConfig->runnable().commandLineArguments;
|
m_extraAppParams = runConfig->runnable().commandLineArguments;
|
||||||
|
|
||||||
if (auto aspect = runConfig->extraAspect(Constants::ANDROID_AMSTARTARGS))
|
if (auto aspect = runConfig->extraAspect(Constants::ANDROID_AMSTARTARGS))
|
||||||
@@ -607,12 +612,5 @@ void AndroidRunnerWorker::onProcessIdChanged(qint64 pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidRunnerWorker::setExtraEnvVars(const Utils::Environment &extraEnvVars)
|
|
||||||
{
|
|
||||||
m_extraEnvVars = extraEnvVars;
|
|
||||||
qCDebug(androidRunWorkerLog) << "Settings extra env:"
|
|
||||||
<< extraEnvVars.toStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Android
|
} // namespace Android
|
||||||
|
@@ -55,7 +55,6 @@ public:
|
|||||||
void logcatReadStandardOutput();
|
void logcatReadStandardOutput();
|
||||||
void logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError);
|
void logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError);
|
||||||
void setAndroidDeviceInfo(const AndroidDeviceInfo &info);
|
void setAndroidDeviceInfo(const AndroidDeviceInfo &info);
|
||||||
void setExtraEnvVars(const Utils::Environment &extraEnvVars);
|
|
||||||
void setIsPreNougat(bool isPreNougat) { m_isPreNougat = isPreNougat; }
|
void setIsPreNougat(bool isPreNougat) { m_isPreNougat = isPreNougat; }
|
||||||
void setIntentName(const QString &intentName) { m_intentName = intentName; }
|
void setIntentName(const QString &intentName) { m_intentName = intentName; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user