aboutsummaryrefslogtreecommitdiff
path: root/build-logic/android-plugins/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-02-20 18:58:35 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-02-20 19:01:19 +0530
commit3d0006d610c89f601fef7fa64e1794cd76b47006 (patch)
tree5860930c753dce064abfe71f78efa33029b89fb7 /build-logic/android-plugins/src/main
parentf6dd7e338f9e9a58fd7ae641f0aa95f976ed2b6e (diff)
Introduce Sentry for error reporting (#1737)
Diffstat (limited to 'build-logic/android-plugins/src/main')
-rw-r--r--build-logic/android-plugins/src/main/kotlin/com.github.android-password-store.sentry.gradle.kts29
1 files changed, 29 insertions, 0 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/com.github.android-password-store.sentry.gradle.kts b/build-logic/android-plugins/src/main/kotlin/com.github.android-password-store.sentry.gradle.kts
new file mode 100644
index 00000000..3648ccf0
--- /dev/null
+++ b/build-logic/android-plugins/src/main/kotlin/com.github.android-password-store.sentry.gradle.kts
@@ -0,0 +1,29 @@
+@file:Suppress("PropertyName")
+
+import flavors.FlavorDimensions
+import flavors.ProductFlavors
+
+plugins { id("com.android.application") }
+
+val SENTRY_DSN_PROPERTY = "SENTRY_DSN"
+val INVOKED_FROM_IDE_PROPERTY = "android.injected.invoked.from.ide"
+
+android {
+ androidComponents {
+ onVariants(selector().withFlavor(FlavorDimensions.FREE to ProductFlavors.NON_FREE)) { variant ->
+ val sentryDsn =
+ project
+ .providers
+ .environmentVariable(SENTRY_DSN_PROPERTY)
+ .orElse("https://public_key@example.com/project_id")
+ if (sentryDsn.isPresent) {
+ variant.manifestPlaceholders.put("sentryDsn", sentryDsn.get())
+ } else if (project.providers.gradleProperty(INVOKED_FROM_IDE_PROPERTY).orNull != "true") {
+ // Checking for 'INVOKED_FROM_IDE_PROPERTY' prevents failures during Gradle sync by the IDE
+ throw GradleException(
+ "The '${SENTRY_DSN_PROPERTY}' environment variable must be set when building the ${ProductFlavors.NON_FREE} flavor"
+ )
+ }
+ }
+ }
+}