From a113f9522a12bb9dc30f6f61887b490781288680 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Fri, 6 Nov 2026 13:04:03 +0100 Subject: [PATCH] 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. 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 --- sentry-android-core/build.gradle.kts | 14 ++++++++++---- .../sentry-uitest-android/build.gradle.kts | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sentry-android-core/build.gradle.kts b/sentry-android-core/build.gradle.kts index d111a71ecc3..17c181d7361 100644 --- a/sentry-android-core/build.gradle.kts +++ b/sentry-android-core/build.gradle.kts @@ -71,10 +71,16 @@ android { } } -tasks.withType().configureEach { - options.errorprone { - check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) - option("NullAway:AnnotatedPackages", "io.sentry") +// net.ltgt.errorprone only configures Gradle's JVM source sets, not Android variants, so put Error +// Prone on each variant's processor path and enable it ourselves. +androidComponents.onVariants { variant -> + variant.annotationProcessorConfiguration.extendsFrom(configurations.errorprone.get()) + variant.configureJavaCompileTask { task -> + task.options.errorprone { + enabled = true + check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) + option("NullAway:AnnotatedPackages", "io.sentry") + } } } diff --git a/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts b/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts index 8f479470cac..82429ddbde9 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts +++ b/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts @@ -125,11 +125,19 @@ dependencies { androidTestImplementation(libs.okhttp.mockwebserver) } -tasks.withType().configureEach { - options.errorprone { - check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) - option("NullAway:AnnotatedPackages", "io.sentry") - option("NullAway:UnannotatedSubPackages", "io.sentry.uitest.android.databinding") +// net.ltgt.errorprone only configures Gradle's JVM source sets, not Android variants, so put Error +// Prone on each variant's processor path and enable it ourselves. +androidComponents.onVariants { variant -> + variant.annotationProcessorConfiguration.extendsFrom(configurations.errorprone.get()) + variant.configureJavaCompileTask { task -> + task.options.errorprone { + enabled = true + check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) + option("NullAway:AnnotatedPackages", "io.sentry") + option("NullAway:UnannotatedSubPackages", "io.sentry.uitest.android.databinding") + // AGP generates the view binding classes, so their findings can't be fixed here. + excludedPaths.set(".*/build/generated/.*") + } } }