diff options
author | Manu Sridharan <msridhar@gmail.com> | 2024-01-25 10:07:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-25 18:07:22 +0000 |
commit | 115d6837bd96de023d4f3407df8a442ea17c947c (patch) | |
tree | d12bb2f869d9e05ea963be98b4b4ad790b1a92c7 | |
parent | 091ac38fb8b410c6483022c03ffbee2bb169bee3 (diff) | |
download | nullaway-115d6837bd96de023d4f3407df8a442ea17c947c.tar.gz |
Update instructions for Android and our sample app (#900)
Fixes #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.
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | sample-app/build.gradle | 33 |
2 files changed, 20 insertions, 23 deletions
@@ -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 diff --git a/sample-app/build.gradle b/sample-app/build.gradle index 6c4deb2..0ab1e6f 100644 --- a/sample-app/build.gradle +++ b/sample-app/build.gradle @@ -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") |