From 720f2492214e165b2c94a9bdb95dd31e48623a36 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:40:51 +0200 Subject: [PATCH] check for androidx availability on runtime (#356) --- .../core/SessionTrackingIntegration.java | 19 +++++++++++++++---- sentry-sample/build.gradle.kts | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SessionTrackingIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/SessionTrackingIntegration.java index 33cb2c267..5a30df8c8 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SessionTrackingIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SessionTrackingIntegration.java @@ -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); + } } } diff --git a/sentry-sample/build.gradle.kts b/sentry-sample/build.gradle.kts index 3b969469a..5815970bd 100644 --- a/sentry-sample/build.gradle.kts +++ b/sentry-sample/build.gradle.kts @@ -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