Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
check for androidx availability on runtime (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Apr 15, 2020
1 parent 2a3cb67 commit 720f249
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
options.isEnableSessionTracking());

if (options.isEnableSessionTracking()) {
watcher = new LifecycleWatcher(hub, options.getSessionTrackingIntervalMillis());
ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher);

options.getLogger().log(SentryLevel.DEBUG, "SessionTrackingIntegration installed.");
try {
Class.forName("androidx.lifecycle.DefaultLifecycleObserver");
Class.forName("androidx.lifecycle.ProcessLifecycleOwner");
watcher = new LifecycleWatcher(hub, options.getSessionTrackingIntervalMillis());
ProcessLifecycleOwner.get().getLifecycle().addObserver(watcher);

options.getLogger().log(SentryLevel.DEBUG, "SessionTrackingIntegration installed.");
} catch (ClassNotFoundException e) {
options
.getLogger()
.log(
SentryLevel.INFO,
"androidx.lifecycle is not available, SessionTrackingIntegration won't be installed",
e);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions sentry-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ dependencies {

implementation(project(":sentry-android"))

// how to exclude androidx if release health feature is disabled
// implementation(project(":sentry-android")) {
// exclude(group = "androidx.lifecycle", module = "lifecycle-process")
// exclude(group = "androidx.lifecycle", module = "lifecycle-common-java8")
// }

implementation(Config.Libs.appCompat)

// debugging purpose
Expand Down

0 comments on commit 720f249

Please sign in to comment.