diff --git a/CHANGELOG.md b/CHANGELOG.md index 60a5111073..be73191013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Fixed AbstractMethodError when getting Lifecycle ([#2228](https://github.com/getsentry/sentry-java/pull/2228)) - Avoid sending empty profiles ([#2232](https://github.com/getsentry/sentry-java/pull/2232)) ## 6.4.1 diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/AppLifecycleIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/AppLifecycleIntegration.java index 092cbe5b85..fc9b48377f 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/AppLifecycleIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/AppLifecycleIntegration.java @@ -83,14 +83,29 @@ private void addObserver(final @NotNull IHub hub) { if (this.options == null) { return; } + watcher = new LifecycleWatcher( hub, this.options.getSessionTrackingIntervalMillis(), this.options.isEnableAutoSessionTracking(), this.options.isEnableAppLifecycleBreadcrumbs()); - ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher); - options.getLogger().log(SentryLevel.DEBUG, "AppLifecycleIntegration installed."); + + try { + ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher); + options.getLogger().log(SentryLevel.DEBUG, "AppLifecycleIntegration installed."); + } catch (Throwable e) { + // This is to handle a potential 'AbstractMethodError' gracefully. The error is triggered in + // connection with conflicting dependencies of the androidx.lifecycle. + // //See the issue here: https://github.com/getsentry/sentry-java/pull/2228 + watcher = null; + options + .getLogger() + .log( + SentryLevel.ERROR, + "AppLifecycleIntegration failed to get Lifecycle and could not be installed.", + e); + } } private void removeObserver() {