Skip to content

Commit e80ff51

Browse files
runningcodeclaude
andcommitted
build(android): Run Error Prone and NullAway on the Android modules
net.ltgt.errorprone dropped Android support in 3.0.0, which we have used since 6.7. Since then it only enables Error Prone and adds it to the processor path for Gradle's JVM source sets. On sentry-android-core and sentry-uitest-android the errorprone dependencies and the NullAway ERROR setting had no effect, and the Java compile tasks ran plain javac. Use the AGP variant API to add the errorprone configuration to each variant's annotation processor configuration and enable Error Prone on its JavaCompile task. Both APIs exist in AGP 9.0.0, the oldest version in the AGP matrix. Pass -XDandroidCompatible=true so Error Prone treats these modules as Android code: it skips checks that don't apply there, such as DefaultCharset, and runs its Android checks. sentry-uitest-android has no hand-written Java, so exclude the view binding classes AGP generates, which trip LabelledBreakTarget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 94f84ca commit e80ff51

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,19 @@ android {
7474
}
7575
}
7676

77-
tasks.withType<JavaCompile>().configureEach {
78-
options.errorprone {
79-
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
80-
option("NullAway:AnnotatedPackages", "io.sentry")
77+
// net.ltgt.errorprone only configures Gradle's JVM source sets, not Android variants, so put Error
78+
// Prone on each variant's processor path and enable it ourselves.
79+
androidComponents.onVariants { variant ->
80+
variant.annotationProcessorConfiguration.extendsFrom(configurations.errorprone.get())
81+
variant.configureJavaCompileTask { task ->
82+
// Tells Error Prone this is Android code, so it skips checks that don't apply there, such as
83+
// DefaultCharset (Android's default charset is always UTF-8), and runs its Android checks.
84+
task.options.compilerArgs.add("-XDandroidCompatible=true")
85+
task.options.errorprone {
86+
enabled = true
87+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
88+
option("NullAway:AnnotatedPackages", "io.sentry")
89+
}
8190
}
8291
}
8392

‎sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,22 @@ dependencies {
135135
androidTestImplementation(libs.okhttp.mockwebserver4)
136136
}
137137

138-
tasks.withType<JavaCompile>().configureEach {
139-
options.errorprone {
140-
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
141-
option("NullAway:AnnotatedPackages", "io.sentry")
142-
option("NullAway:UnannotatedSubPackages", "io.sentry.uitest.android.databinding")
138+
// net.ltgt.errorprone only configures Gradle's JVM source sets, not Android variants, so put Error
139+
// Prone on each variant's processor path and enable it ourselves.
140+
androidComponents.onVariants { variant ->
141+
variant.annotationProcessorConfiguration.extendsFrom(configurations.errorprone.get())
142+
variant.configureJavaCompileTask { task ->
143+
// Tells Error Prone this is Android code, so it skips checks that don't apply there, such as
144+
// DefaultCharset (Android's default charset is always UTF-8), and runs its Android checks.
145+
task.options.compilerArgs.add("-XDandroidCompatible=true")
146+
task.options.errorprone {
147+
enabled = true
148+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
149+
option("NullAway:AnnotatedPackages", "io.sentry")
150+
option("NullAway:UnannotatedSubPackages", "io.sentry.uitest.android.databinding")
151+
// AGP generates the view binding classes, so their findings can't be fixed here.
152+
excludedPaths.set(".*/build/generated/.*")
153+
}
143154
}
144155
}
145156

0 commit comments

Comments
 (0)