From 7f6a29726e34c46bee1ef8ad242bd462896a66e5 Mon Sep 17 00:00:00 2001 From: johan12345 Date: Tue, 7 Jul 2020 17:04:25 +0200 Subject: [PATCH] load Sentry DSN from sentry.properties --- opacclient/opacapp/build.gradle | 11 +++++++++++ .../java/de/geeksfactory/opacclient/OpacClient.java | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/opacclient/opacapp/build.gradle b/opacclient/opacapp/build.gradle index d8ad54929..947fbc70c 100644 --- a/opacclient/opacapp/build.gradle +++ b/opacclient/opacapp/build.gradle @@ -26,16 +26,27 @@ android { } } + // load Sentry configuration from sentry.properties file, if it exists + def sentryProps = new Properties() + def sentryPropsFile = project.rootProject.file("sentry.properties") + String dsn = null; + if (sentryPropsFile.exists()) { + sentryProps.load(sentryPropsFile.newDataInputStream()) + dsn = sentryProps.getProperty("dsn") + } + buildTypes { release { minifyEnabled true signingConfig signingConfigs.release proguardFiles 'proguard-rules.txt' + buildConfigField("String", "SENTRY_DSN", dsn != null ? "\"$dsn\"" : "null") } debug { debuggable true applicationIdSuffix ".debug" versionNameSuffix "-debug" + buildConfigField("String", "SENTRY_DSN", "null") } } diff --git a/opacclient/opacapp/src/main/java/de/geeksfactory/opacclient/OpacClient.java b/opacclient/opacapp/src/main/java/de/geeksfactory/opacclient/OpacClient.java index ea42b2ce6..fa1b0a6c5 100644 --- a/opacclient/opacapp/src/main/java/de/geeksfactory/opacclient/OpacClient.java +++ b/opacclient/opacapp/src/main/java/de/geeksfactory/opacclient/OpacClient.java @@ -29,7 +29,6 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.Bundle; -import androidx.preference.PreferenceManager; import android.util.Log; import org.joda.time.DateTime; @@ -53,6 +52,7 @@ import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; import androidx.multidex.MultiDex; +import androidx.preference.PreferenceManager; import de.geeksfactory.opacclient.apis.OpacApi; import de.geeksfactory.opacclient.frontend.AccountListActivity; import de.geeksfactory.opacclient.frontend.LibraryListActivity; @@ -373,8 +373,10 @@ public void onCreate() { sp = PreferenceManager.getDefaultSharedPreferences(this); - if (!BuildConfig.DEBUG) { - SentryAndroid.init(this); + if (BuildConfig.SENTRY_DSN != null) { + SentryAndroid.init(this, options -> { + options.setDsn(BuildConfig.SENTRY_DSN); + }); if (getLibrary() != null) { Sentry.setTag(SENTRY_LIBRARY, getLibrary().getIdent()); }