Skip to content

Commit 77e5b0a

Browse files
authored
chore(samples-android): Add optional SAGP build mode (#5538)
Adds an optional useSagp flag to Android sample app builds that, when true, applies the Sentry Android Gradle Plugin. (Defaults to false, which matches existing build behavior.) ``` ./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp=true ``` See the Android sample app README for more details.
1 parent 26ddd89 commit 77e5b0a

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Sentry Sample Android App
2+
3+
Sample application demonstrating how to use the Sentry Android SDK, including core functionality (error reporting, tracing, session replay,
4+
profiling) and integrations (Compose, OkHttp, etc.).
5+
6+
## How to run it?
7+
8+
Install the app on your device or emulator:
9+
10+
```
11+
./gradlew :sentry-samples:sentry-samples-android:installDebug
12+
```
13+
14+
or simply open the project in Android Studio and run the `sentry-samples-android` configuration.
15+
16+
You can also apply the [Sentry Android Gradle Plugin](https://github.com/getsentry/sentry-android-gradle-plugin) (SAGP) when building (not applied by default):
17+
18+
```
19+
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp=true
20+
```
21+
22+
In Android Studio, add `useSagp=true` to `gradle.properties` or pass it as a Gradle project property.
23+
24+
## Build modes
25+
26+
### With or without SAGP
27+
28+
The sample app can be built with or without the SAGP.
29+
30+
| Gradle Property | Required | Purpose |
31+
|-----------------|--------------------------|----------------------------------------------------------------------------------------------------------------|
32+
| `useSagp` | No (defaults to `false`) | When `true`, apply SAGP when building the sample app. When false or absent, build the sample app without SAGP. |
33+
34+
You can configure SAGP properties via the lambda passed to `extensions.configure<SentryPluginExtension>("sentry")` in the sample app's
35+
`build.gradle.kts` file.
36+
37+
### Builds against your local sentry-java branch
38+
39+
Regardless of `useSagp`, the sample always depends on sentry-java modules from this monorepo (e.g., `projects.sentryAndroid`). SAGP's SDK
40+
auto-installation is disabled, so the sample never pulls a separate SDK version from Maven. Local SDK changes in your branch are picked up
41+
directly.
42+
43+
## Viewing SDK output
44+
45+
### Locally
46+
47+
Debug builds enable SDK debug logging, so captured envelopes are printed to logcat (tag `Sentry`):
48+
49+
```
50+
adb logcat -s Sentry
51+
```
52+
53+
### On Sentry UI
54+
55+
By default, SDK output produced by the sample app appears under the [sentry-sdk test project](https://sentry-sdks.sentry.io/issues/?project=5428559).
56+
To redirect them to your own project, replace the test DSN (i.e., the `io.sentry.dsn` `meta-data` value in `src/main/AndroidManifest.xml`
57+
with your own.

‎sentry-samples/sentry-samples-android/build.gradle.kts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
import com.android.build.api.artifact.SingleArtifact
22
import com.android.build.api.variant.impl.VariantImpl
3+
import io.sentry.android.gradle.extensions.InstrumentationFeature
4+
import io.sentry.android.gradle.extensions.SentryPluginExtension
35
import org.apache.tools.ant.taskdefs.condition.Os
46
import org.gradle.internal.extensions.stdlib.capitalized
57

68
plugins {
79
id("com.android.application")
810
alias(libs.plugins.kotlin.android)
911
alias(libs.plugins.kotlin.compose)
12+
alias(libs.plugins.sentry) apply false
13+
}
14+
15+
val useSagp =
16+
providers.gradleProperty("useSagp").map { it.equals("true", ignoreCase = true) }.orElse(false)
17+
18+
if (useSagp.get()) {
19+
apply(plugin = "io.sentry.android.gradle")
20+
}
21+
22+
plugins.withId("io.sentry.android.gradle") {
23+
// Extension configs match non-SAGP builds. Update locally to test your feature.
24+
extensions.configure<SentryPluginExtension>("sentry") {
25+
autoInstallation.enabled.set(false)
26+
includeProguardMapping.set(false)
27+
includeDependenciesReport.set(false)
28+
telemetry.set(false)
29+
tracingInstrumentation {
30+
features.set(
31+
setOf(
32+
InstrumentationFeature.COMPOSE,
33+
InstrumentationFeature.DATABASE,
34+
InstrumentationFeature.FILE_IO,
35+
InstrumentationFeature.OKHTTP,
36+
)
37+
)
38+
logcat.enabled.set(false)
39+
appStart.enabled.set(false)
40+
}
41+
}
1042
}
1143

1244
android {

0 commit comments

Comments
 (0)