From 3e1d6df892b50db7af0f7d4bf99e416a518ba0a2 Mon Sep 17 00:00:00 2001 From: Brett Chabot Date: Wed, 26 Jun 2024 11:39:17 -0700 Subject: [PATCH] Catch and log exceptions when enabling tracing. Due to an android gradle bug calls to forceEnableAppTracing() may fail with NoSuchMethodError at runtime. Instead of crashing, just catch and log this exception. --- runner/monitor/CHANGELOG.md | 2 ++ .../java/androidx/test/platform/tracing/AndroidXTracer.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/runner/monitor/CHANGELOG.md b/runner/monitor/CHANGELOG.md index 81697fb4a..29ace4aa3 100644 --- a/runner/monitor/CHANGELOG.md +++ b/runner/monitor/CHANGELOG.md @@ -6,6 +6,8 @@ **Bug Fixes** +* Catch and log NoSuchMethodError on forceEnableAppTracing calls + **New Features** **Breaking Changes** diff --git a/runner/monitor/java/androidx/test/platform/tracing/AndroidXTracer.java b/runner/monitor/java/androidx/test/platform/tracing/AndroidXTracer.java index 1abdd4b66..261d4dafd 100644 --- a/runner/monitor/java/androidx/test/platform/tracing/AndroidXTracer.java +++ b/runner/monitor/java/androidx/test/platform/tracing/AndroidXTracer.java @@ -59,6 +59,12 @@ public AndroidXTracer enableTracing() { // The AndroidX call can fail if reflection is not allowed. // We want to log the error yet we should not break any test in this case. Log.e(TAG, "enableTracing failed", e); + } catch (NoSuchMethodError e) { + // This can occur if an androidx.tracing < 1.1.0 is put on classpath instead. + // See http://issuetracker.google.com/349628366). + // We want to log the error yet we should not break any test in this case. + Log.e(TAG, "enableTracing failed. " + + "You may need to upgrade your androidx.tracing:tracing version", e); } return this; }