Android: Compile app profiles before starting debugging

At https://source.android.com/docs/core/runtime/configure/art-service we
learn that:

"Starting with Android 14, on-device AOT compilation for apps (a.k.a.
dexopt) is handled by ART Service. ART Service is a part of the ART
module, and you can customize it through system properties and APIs."

This commit makes sure to have the app profiles created before the
application was started. Otherwise the service will do it in the
background and could trigger exceptions that would land in disassembly.

Fixes: QTCREATORBUG-29928
Change-Id: I5d30fa03535f03b15d5470789323c0af0246d0dd
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Cristian Adam
2024-08-22 17:45:13 +02:00
parent 604dfa57ef
commit 6ea2ab3ab7
2 changed files with 8 additions and 0 deletions

View File

@@ -288,6 +288,12 @@ bool AndroidRunnerWorker::packageFileExists(const QString &filePath)
return success && !output.trimmed().isEmpty(); return success && !output.trimmed().isEmpty();
} }
void AndroidRunnerWorker::compileAppProfiles()
{
runAdb({"shell", "pm", "art", "clear-app-profiles", m_packageName});
runAdb({"shell", "pm", "compile", "-m", "verify", "-f", m_packageName});
}
QStringList AndroidRunnerWorker::selector() const QStringList AndroidRunnerWorker::selector() const
{ {
return AndroidDeviceInfo::adbSelector(m_deviceSerialNumber); return AndroidDeviceInfo::adbSelector(m_deviceSerialNumber);
@@ -808,6 +814,7 @@ void AndroidRunnerWorker::onProcessIdChanged(const PidUserPair &pidUser)
for (const QString &entry: std::as_const(m_afterFinishAdbCommands)) for (const QString &entry: std::as_const(m_afterFinishAdbCommands))
runAdb(entry.split(' ', Qt::SkipEmptyParts)); runAdb(entry.split(' ', Qt::SkipEmptyParts));
} else { } else {
compileAppProfiles();
if (m_useCppDebugger) if (m_useCppDebugger)
startNativeDebugging(); startNativeDebugging();
// In debugging cases this will be funneled to the engine to actually start // In debugging cases this will be funneled to the engine to actually start

View File

@@ -66,6 +66,7 @@ private:
bool startDebuggerServer(const QString &packageDir, const QString &debugServerFile, QString *errorStr = nullptr); bool startDebuggerServer(const QString &packageDir, const QString &debugServerFile, QString *errorStr = nullptr);
bool deviceFileExists(const QString &filePath); bool deviceFileExists(const QString &filePath);
bool packageFileExists(const QString& filePath); bool packageFileExists(const QString& filePath);
void compileAppProfiles();
bool uploadDebugServer(const QString &debugServerFileName); bool uploadDebugServer(const QString &debugServerFileName);
void asyncStartLogcat(); void asyncStartLogcat();