Skip to content

Commit

Permalink
fix: AbstractMethodError when getting Lifecycle (#2228)
Browse files Browse the repository at this point in the history
* wrapped getLifeCycle in a try-catch

* removed newline

* Format code

* Updated CHANGELOG.md

* wrapping L92 and added comment

* Format code

Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
  • Loading branch information
2 people authored and vaind committed Sep 7, 2022
1 parent b598e3e commit 8c31d09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8c31d09

Please sign in to comment.