Skip to content

Commit f7af851

Browse files
runningcodeclaude
andcommitted
build(samples): Move the Android sample to its own composite build
The Android sample was a subproject of the SDK build, so every root Gradle invocation configured AGP, Compose, KSP, SQLDelight, Room and CameraX, and the sample consumed the SDK through project accessors rather than as a real consumer would. It is now a standalone build that includes the SDK build, depending on plain io.sentry:* coordinates that Gradle substitutes with the SDK's projects. Run it with ./gradlew -p sentry-samples/sentry-samples-android <task>. The macrobenchmark module moves along with it, because AGP requires a benchmark's target app to live in the same build. The AGP version moves to the version catalog so both builds share one source of truth, still overridable via VERSION_AGP. The SDK build includes the sample build back, so a single ./gradlew spotlessApply still formats the whole repository and CI needs no sample-specific step. Root check does not reach the sample, so preMerge gains a checkSampleAndroid target. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a5555ea commit f7af851

17 files changed

Lines changed: 195 additions & 44 deletions

File tree

‎.github/workflows/integration-tests-macrobenchmark.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Integration Tests - Macrobenchmark'
2-
# Runs the sentry-uitest-android-macrobenchmark cold-start benchmark on a Sauce Labs real
2+
# Runs the sentry-samples-android macrobenchmark cold-start benchmark on a Sauce Labs real
33
# device and recovers timeToInitialDisplay from the device log.
44
#
55
on:
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Assemble target app and Macrobenchmark apk
3535
if: env.SAUCE_USERNAME != null
36-
run: ./gradlew :sentry-samples:sentry-samples-android:assembleRelease :sentry-android-integration-tests:sentry-uitest-android-macrobenchmark:assembleBenchmark
36+
run: ./gradlew -p sentry-samples/sentry-samples-android assembleRelease :macrobenchmark:assembleBenchmark
3737

3838
- name: Run Macrobenchmark in SauceLab
3939
uses: saucelabs/saucectl-run-action@283660aa934c02723c497efa151d582a3acc5801 # pin@v3

‎.sauce/sentry-uitest-android-macrobenchmark.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defaults:
1515

1616
espresso:
1717
app: ./sentry-samples/sentry-samples-android/build/outputs/apk/release/sentry-samples-android-release.apk
18-
testApp: ./sentry-android-integration-tests/sentry-uitest-android-macrobenchmark/build/outputs/apk/benchmark/sentry-uitest-android-macrobenchmark-benchmark.apk
18+
testApp: ./sentry-samples/sentry-samples-android/macrobenchmark/build/outputs/apk/benchmark/macrobenchmark-benchmark.apk
1919

2020
suites:
2121

‎AGENTS.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ resolves the per-module test task and the unit-test vs system-test split for you
6262
# Assemble Android test APKs
6363
./gradlew :sentry-android-integration-tests:sentry-uitest-android:assembleRelease :sentry-android-integration-tests:sentry-uitest-android:assembleAndroidTest
6464

65+
# Build the Android sample app, which is a separate Gradle build that includes this one
66+
./gradlew -p sentry-samples/sentry-samples-android assembleDebug
67+
6568
# Run critical UI tests
6669
./scripts/test-ui-critical.sh
6770
```
@@ -111,7 +114,7 @@ The repository is organized into multiple modules:
111114
### Utility Modules
112115
- **`sentry-test-support`** - Shared test utilities
113116
- **`sentry-system-test-support`** - System testing infrastructure
114-
- **`sentry-samples`** - Example applications
117+
- **`sentry-samples`** - Example applications. `sentry-samples-android` is a separate Gradle build that includes this one, so root tasks other than `spotlessApply` do not reach it
115118
- **`sentry-bom`** - Bill of Materials for dependency management
116119

117120
### Key Architectural Patterns

‎Makefile‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.PHONY: all clean compile javadocs dryRelease update checkFormat api assembleUiTestRelease assembleUiTestCriticalRelease runUiTestCritical setupPython systemTest systemTestInteractive check preMerge publish
1+
.PHONY: all clean compile javadocs dryRelease update checkFormat api assembleUiTestRelease assembleUiTestCriticalRelease runUiTestCritical setupPython systemTest systemTestInteractive check checkSampleAndroid preMerge publish
22

33
all: stop clean javadocs compile
44
assembleUiTests: assembleUiTestRelease
5-
preMerge: check
5+
preMerge: check checkSampleAndroid
66
publish: clean dryRelease
77

88
# deep clean
@@ -63,3 +63,7 @@ systemTestInteractive: setupPython
6363
# Run tests and lint
6464
check:
6565
./gradlew check
66+
67+
# The Android sample is a separate build, so the root `check` does not reach it
68+
checkSampleAndroid:
69+
./gradlew -p sentry-samples/sentry-samples-android assembleDebug lintDebug

‎build.gradle.kts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ plugins {
2727
alias(libs.plugins.spring.dependency.management) apply false
2828
id("io.sentry.javadoc.aggregate")
2929
alias(libs.plugins.sentry) apply false
30+
alias(libs.plugins.android.application) apply false
3031
}
3132

3233
buildscript {
3334
repositories {
3435
google()
3536
}
3637
dependencies {
37-
classpath(Config.BuildPlugins.androidGradle)
38-
3938
// add classpath of sentry android gradle plugin
4039
// classpath("io.sentry:sentry-android-gradle-plugin:{version}")
4140

@@ -51,7 +50,6 @@ apiValidation {
5150
)
5251
ignoredProjects.addAll(
5352
listOf(
54-
"sentry-samples-android",
5553
"sentry-samples-console",
5654
"sentry-samples-console-opentelemetry-noagent",
5755
"sentry-samples-jul",
@@ -107,6 +105,12 @@ allprojects {
107105
}
108106
}
109107

108+
// `subprojects` below cannot reach the Android sample, which is a separate build, so delegate to it
109+
// and keep a single `./gradlew spotlessApply` formatting the whole repository.
110+
tasks.register("spotlessApply") {
111+
dependsOn(gradle.includedBuild("sentry-samples-android").task(":spotlessApply"))
112+
}
113+
110114
subprojects {
111115
apply { plugin("io.sentry.spotless") }
112116

‎buildSrc/src/main/java/Config.kt‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11

22
object Config {
3-
val AGP = System.getenv("VERSION_AGP") ?: "9.2.1"
43
val kotlinStdLib = "stdlib-jdk8"
54
val kotlinStdLibVersionAndroid = "1.9.24"
65
val kotlinTestJunit = "test-junit"
76

8-
object BuildPlugins {
9-
val androidGradle = "com.android.tools.build:gradle:$AGP"
10-
}
11-
127
object Android {
138
val abiFilters = listOf("x86", "armeabi-v7a", "x86_64", "arm64-v8a")
149

‎gradle/libs.versions.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[versions]
2+
# Also honoured via the VERSION_AGP env var, set by the AGP compatibility matrix job.
3+
agp = "9.2.1"
24
animalsniffer = "2.0.1"
35
apollo = "2.5.9"
46
androidxLifecycle = "2.2.0"
@@ -52,6 +54,7 @@ compileSdk = "37"
5254
minSdk = "21"
5355

5456
[plugins]
57+
android-application = { id = "com.android.application", version.ref = "agp" }
5558
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
5659
kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
5760
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/build
2+
/local.properties

‎sentry-samples/sentry-samples-android/README.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@
33
Sample application demonstrating how to use the Sentry Android SDK, including core functionality (error reporting, tracing, session replay,
44
profiling) and integrations (Compose, OkHttp, SQLite, etc.).
55

6+
This directory is its own Gradle build. It includes the SDK build (`includeBuild("../..")`), so it
7+
depends on plain `io.sentry:*` coordinates exactly like a real app would, and Gradle substitutes
8+
them with the SDK's projects — nothing needs to be published first. Every command below therefore
9+
runs against this build, not the repository root's.
10+
611
## How to run it?
712

813
Install the app on your device or emulator:
914

1015
```
11-
./gradlew :sentry-samples:sentry-samples-android:installDebug
16+
./gradlew -p sentry-samples/sentry-samples-android installDebug
1217
```
1318

14-
or simply open the project in Android Studio and run the `sentry-samples-android` configuration.
19+
or open `sentry-samples/sentry-samples-android` in Android Studio (not the repository root) and run
20+
the `sentry-samples-android` configuration. The SDK sources come along through the included build.
1521

1622
You can also apply the [Sentry Android Gradle Plugin](https://github.com/getsentry/sentry-android-gradle-plugin) (SAGP) when building (not applied by default):
1723

1824
```
19-
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp
25+
./gradlew -p sentry-samples/sentry-samples-android installDebug -PuseSagp
2026
```
2127

2228
In Android Studio, add `useSagp=` (empty value) to `gradle.properties`, or pass `-PuseSagp` as a Gradle project property.
@@ -52,7 +58,7 @@ Re-run `publishToMavenLocal` after each SAGP change.
5258
Then build from sentry-java:
5359

5460
```
55-
./gradlew :sentry-samples:sentry-samples-android:installDebug -PuseSagp
61+
./gradlew -p sentry-samples/sentry-samples-android installDebug -PuseSagp
5662
```
5763

5864
## Viewing SDK output

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

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,32 @@ import org.apache.tools.ant.taskdefs.condition.Os
77
import org.gradle.internal.extensions.stdlib.capitalized
88

99
plugins {
10-
id("com.android.application")
10+
alias(libs.plugins.android.application)
11+
id("io.sentry.spotless")
1112
alias(libs.plugins.kotlin.android)
1213
alias(libs.plugins.kotlin.compose)
1314
alias(libs.plugins.ksp)
1415
alias(libs.plugins.sentry) apply false
1516
alias(libs.plugins.sqldelight)
1617
}
1718

19+
// The SDK version lives in the SDK build's gradle.properties, which this build cannot read as a
20+
// Gradle property. It doubles as the sample's versionName, so an APK says which SDK it was built
21+
// against.
22+
val sentryVersion: String =
23+
providers
24+
.fileContents(layout.projectDirectory.dir("../..").file("gradle.properties"))
25+
.asText
26+
.map { properties ->
27+
val match = Regex("""^versionName=(.+)$""", RegexOption.MULTILINE).find(properties)
28+
checkNotNull(match) { "versionName is missing from the SDK build's gradle.properties" }
29+
.groupValues[1]
30+
.trim()
31+
}
32+
.get()
33+
34+
version = sentryVersion
35+
1836
if (providers.gradleProperty("useSagp").isPresent) {
1937
apply(plugin = "io.sentry.android.gradle")
2038
}
@@ -63,7 +81,7 @@ android {
6381
}
6482
}
6583

66-
ndk { abiFilters.addAll(Config.Android.abiFilters) }
84+
ndk { abiFilters.addAll(listOf("x86", "armeabi-v7a", "x86_64", "arm64-v8a")) }
6785
}
6886

6987
lint {
@@ -102,7 +120,7 @@ android {
102120

103121
signingConfigs {
104122
getByName("debug") {
105-
storeFile = rootProject.file("debug.keystore")
123+
storeFile = rootProject.file("../../debug.keystore")
106124
storePassword = "android"
107125
keyAlias = "androiddebugkey"
108126
keyPassword = "android"
@@ -152,7 +170,7 @@ android {
152170
val toggleNativeLoggingTask =
153171
project.tasks.register<ToggleNativeLoggingTask>(taskName) {
154172
mergedManifest.set(variant.artifacts.get(SingleArtifact.MERGED_MANIFEST))
155-
rootDir.set(project.rootDir.absolutePath)
173+
repoDir.set(project.rootDir.resolve("../..").canonicalPath)
156174
}
157175
project.afterEvaluate {
158176
(variant as? VariantImpl<*>)?.taskContainer?.assembleTask?.configure {
@@ -167,6 +185,10 @@ android {
167185
@Suppress("UnstableApiUsage") packagingOptions { jniLibs { useLegacyPackaging = true } }
168186
}
169187

188+
// The SDK build drives formatting repository-wide and references one task per included build, so
189+
// this build's root spotlessApply has to cover its subprojects too.
190+
tasks.named("spotlessApply") { dependsOn(subprojects.map { "${it.path}:spotlessApply" }) }
191+
170192
sqldelight {
171193
databases {
172194
create("SampleSQLDelightDatabase") {
@@ -179,22 +201,20 @@ sqldelight {
179201
}
180202

181203
dependencies {
182-
implementation(
183-
kotlin(Config.kotlinStdLib, org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION)
184-
)
185-
186-
implementation(projects.sentryAndroid)
187-
implementation(projects.sentryAndroidFragment)
188-
implementation(projects.sentryAndroidNavigation)
189-
implementation(projects.sentryAndroidSqlite)
190-
implementation(projects.sentryAndroidTimber)
191-
implementation(projects.sentryCompose)
192-
implementation(projects.sentryKotlinExtensions)
193-
implementation(projects.sentryOkhttp)
194-
implementation(projects.sentrySpotlight)
204+
implementation(kotlin("stdlib-jdk8"))
205+
206+
implementation("io.sentry:sentry-android:$sentryVersion")
207+
implementation("io.sentry:sentry-android-fragment:$sentryVersion")
208+
implementation("io.sentry:sentry-android-navigation:$sentryVersion")
209+
implementation("io.sentry:sentry-android-sqlite:$sentryVersion")
210+
implementation("io.sentry:sentry-android-timber:$sentryVersion")
211+
implementation("io.sentry:sentry-compose:$sentryVersion")
212+
implementation("io.sentry:sentry-kotlin-extensions:$sentryVersion")
213+
implementation("io.sentry:sentry-okhttp:$sentryVersion")
214+
implementation("io.sentry:sentry-spotlight:$sentryVersion")
195215

196216
// how to exclude androidx if release health feature is disabled
197-
// implementation(projects.sentryAndroid) {
217+
// implementation("io.sentry:sentry-android:$sentryVersion") {
198218
// exclude(group = "androidx.lifecycle", module = "lifecycle-process")
199219
// exclude(group = "androidx.lifecycle", module = "lifecycle-common-java8")
200220
// exclude(group = "androidx.core", module = "core")
@@ -232,12 +252,12 @@ dependencies {
232252
ksp(libs.androidx.room.compiler)
233253
ksp(libs.androidx.room3.compiler)
234254

235-
debugImplementation(projects.sentryAndroidDistribution)
255+
debugImplementation("io.sentry:sentry-android-distribution:$sentryVersion")
236256
debugImplementation(libs.leakcanary)
237257
}
238258

239259
abstract class ToggleNativeLoggingTask : Exec() {
240-
@get:Input abstract val rootDir: Property<String>
260+
@get:Input abstract val repoDir: Property<String>
241261

242262
@get:InputFile abstract val mergedManifest: RegularFileProperty
243263

@@ -255,7 +275,7 @@ abstract class ToggleNativeLoggingTask : Exec() {
255275
args.add(0, "cmd")
256276
args.add(1, "/c")
257277
}
258-
args.add("${rootDir.get()}/scripts/toggle-codec-logs.sh")
278+
args.add("${repoDir.get()}/scripts/toggle-codec-logs.sh")
259279
args.add(if (value) "enable" else "disable")
260280
commandLine(args)
261281
super.exec()

0 commit comments

Comments
 (0)