From 6ea2ab3ab761f846d8ad03a2a6c51226c41b284d Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 22 Aug 2024 17:45:13 +0200 Subject: [PATCH] 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 Reviewed-by: Assam Boudjelthia Reviewed-by: Jarek Kobus --- src/plugins/android/androidrunnerworker.cpp | 7 +++++++ src/plugins/android/androidrunnerworker.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index a764167f365..335103f3ba7 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -288,6 +288,12 @@ bool AndroidRunnerWorker::packageFileExists(const QString &filePath) 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 { return AndroidDeviceInfo::adbSelector(m_deviceSerialNumber); @@ -808,6 +814,7 @@ void AndroidRunnerWorker::onProcessIdChanged(const PidUserPair &pidUser) for (const QString &entry: std::as_const(m_afterFinishAdbCommands)) runAdb(entry.split(' ', Qt::SkipEmptyParts)); } else { + compileAppProfiles(); if (m_useCppDebugger) startNativeDebugging(); // In debugging cases this will be funneled to the engine to actually start diff --git a/src/plugins/android/androidrunnerworker.h b/src/plugins/android/androidrunnerworker.h index bba8d351041..6b9ae2dae6a 100644 --- a/src/plugins/android/androidrunnerworker.h +++ b/src/plugins/android/androidrunnerworker.h @@ -66,6 +66,7 @@ private: bool startDebuggerServer(const QString &packageDir, const QString &debugServerFile, QString *errorStr = nullptr); bool deviceFileExists(const QString &filePath); bool packageFileExists(const QString& filePath); + void compileAppProfiles(); bool uploadDebugServer(const QString &debugServerFileName); void asyncStartLogcat();