summaryrefslogtreecommitdiff
path: root/build-logic/android-plugins/src
diff options
context:
space:
mode:
Diffstat (limited to 'build-logic/android-plugins/src')
-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"
+ )
+ }
+ }
+ }
+}