Skip to content

Commit

Permalink
Update instructions for Android and our sample app (uber#900)
Browse files Browse the repository at this point in the history
Fixes uber#891. It's hard to add a regression test for this, but I manually
tested that with the new configuration, NullAway errors are detected in
the sample app. After this lands, I'd like to update the readme further
to refer to this particular commit, so users can see the changes we
needed to make.
  • Loading branch information
msridhar committed Jan 25, 2024
1 parent 091ac38 commit 115d683
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,9 @@ Snapshots of the development version are available in [Sonatype's snapshots repo

#### Android

The configuration for an Android project is very similar to the Java case, with one key difference: The `com.google.code.findbugs:jsr305:3.0.2` dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library.
Versions 3.0.0 and later of the Gradle Error Prone Plugin [no longer support Android](https://github.com/tbroyer/gradle-errorprone-plugin/releases/tag/v3.0.0). So if you're using a recent version of this plugin, you'll need to add some further configuration to run Error Prone and NullAway. Our [sample app `build.gradle` file](https://github.com/uber/NullAway/blob/master/sample-app/build.gradle) shows one way to do this, but your Android project may require tweaks. Alternately, 2.x versions of the Gradle Error Prone Plugin still support Android and may still work with your project.

```gradle
dependencies {
errorprone "com.uber.nullaway:nullaway:<NullAway version>"
errorprone "com.google.errorprone:error_prone_core:<Error Prone version>"
}
```
For a more complete example see our [sample app](https://github.com/uber/NullAway/blob/master/sample-app/). (The sample app's [`build.gradle`](https://github.com/uber/NullAway/blob/master/sample-app/) is not suitable for direct copy-pasting, as some configuration is inherited from the top-level `build.gradle`.)
Beyond that, compared to the Java configuration, the `com.google.code.findbugs:jsr305:3.0.2` dependency can be removed; you can use the `android.support.annotation.Nullable` annotation from the Android Support library instead.

#### Annotation Processors / Generated Code

Expand Down
33 changes: 18 additions & 15 deletions sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,30 @@ android {
variants.addAll(getUnitTestVariants())
variants.configureEach { variant ->
variant.getJavaCompileProvider().configure {
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "com.uber")
}
options.compilerArgs += [
"-XDcompilePolicy=simple",
"-Xplugin:ErrorProne -XepOpt:NullAway:AnnotatedPackages=com.uber",
]
options.fork = true
options.forkOptions.jvmArgs = [
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"
]
}
}

// If you want to disable NullAway in just tests, you can do the below
// DomainObjectSet<BaseVariant> testVariants = getTestVariants()
// testVariants.addAll(getUnitTestVariants())
// testVariants.configureEach { variant ->
// variant.getJavaCompileProvider().configure {
// options.errorprone {
// check("NullAway", CheckSeverity.OFF)
// }
// }
// }
}

dependencies {
implementation deps.support.appcompat
annotationProcessor deps.build.errorProneCore
annotationProcessor project(":nullaway")
annotationProcessor project(path: ":sample-library-model")

Expand Down

0 comments on commit 115d683

Please sign in to comment.