Make Sentry completely optional

This commit fully disables Sentry if the DSN option is left empty both in stoatbuild.properties and in the RVX_SENTRY_DSN environment variable.

Not only does it prevent Sentry from being Init'd at runtime, but it also disables the Sentry Gradle plugin, since otherwise the plugin throws errors during Gradle syncs.

Sentry is only really necessary if you're shipping an app, not just developing locally. Making Sentry optional should reduce the barrier for entry to new devs.

Signed-off-by: Misofist <misofist@heavendivided.net>
This commit is contained in:
Misofist 2026-02-15 03:55:29 +11:00
parent 75bb23982b
commit fc2bce4541
2 changed files with 23 additions and 12 deletions

View File

@ -1,5 +1,7 @@
import com.mikepenz.aboutlibraries.plugin.StrictMode
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel
import io.sentry.android.gradle.SentryPlugin
import io.sentry.android.gradle.extensions.SentryPluginExtension
import java.io.FileInputStream
import java.util.Properties
@ -11,13 +13,18 @@ plugins {
alias(libs.plugins.aboutlibraries)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
alias(libs.plugins.sentry.android)
alias(libs.plugins.sentry.android) apply false
alias(libs.plugins.sqldelight)
alias(libs.plugins.google.services)
id("kotlin-kapt")
id("kotlin-parcelize")
}
val sentryEnabled = buildproperty("sentry.dsn", "RVX_SENTRY_DSN") != "";
if(sentryEnabled) {
apply<SentryPlugin>();
}
fun property(fileName: String, propertyName: String, fallbackEnv: String? = null): String? {
val propsFile = rootProject.file(fileName)
if (propsFile.exists()) {
@ -156,16 +163,18 @@ android {
}
}
sentry {
autoUploadProguardMapping =
buildproperty("sentry.upload_mappings", "RVX_SENTRY_UPLOAD_MAPPINGS") == "true"
if(sentryEnabled) {
configure<SentryPluginExtension> {
autoUploadProguardMapping =
buildproperty("sentry.upload_mappings", "RVX_SENTRY_UPLOAD_MAPPINGS") == "true"
tracingInstrumentation {
enabled = true
logcat {
tracingInstrumentation {
enabled = true
minLevel = LogcatLevel.WARNING
logcat {
enabled = true
minLevel = LogcatLevel.WARNING
}
}
}
}

View File

@ -349,9 +349,11 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
SentryAndroid.init(this) { options ->
options.dsn = BuildConfig.SENTRY_DSN
options.release = BuildConfig.VERSION_NAME
if(BuildConfig.SENTRY_DSN != "") {
SentryAndroid.init(this) { options ->
options.dsn = BuildConfig.SENTRY_DSN
options.release = BuildConfig.VERSION_NAME
}
}
@Suppress("DEPRECATION") // We are fixing a bug in the splash screen