google / volley

https://google.github.io/volley
Apache License 2.0
3.37k stars 751 forks source link

Compiler warning in apps that don't use androidx.annotation:annotation #424

Open jpd236 opened 3 years ago

jpd236 commented 3 years ago

(Forking from #402)

When an app depends on Volley (1.2.0+, possibly older as well), and doesn't also depend on androidx.annotation:annotation, the resulting build will have compiler warnings:

> Task :app:compileReleaseJavaWithJavac
warning: unknown enum constant Scope.LIBRARY_GROUP
  reason: class file for androidx.annotation.RestrictTo$Scope not found

These are non-fatal by default, but become fatal if -Werror is enabled.

This doesn't seem to have bothered anyone through now, but it'd be nice to fix. The problem is that neither option seems great. @RestrictTo needs to be retained at class-time, not source-time, so it's technically not safe to depend on as compileOnly. However, androidx.annotation:annotation isn't available on Maven Central, so we'd be requiring a dependency on something that can't actually be obtained there, though in practice this may be perfectly reasonable since you can't build a Google app without artifacts from the Google repository anyway. Removing the annotation wouldn't be ideal since it'd provide no protection (however light) against applications depending on methods meant for internal use in Volley.

jpd236 commented 3 years ago

For 1.2.2, I think we should go ahead and add the dependency. It's the correct thing to do as the dependency is needed at compile-time, including for applications that depend on Volley. Given that Volley has a hard dependency on Android (e.g. can't be used directly from the JVM), and that Android's build system depends on the Google repository in large part, it shouldn't be a problem for any application use cases that I can think of. And there is precedent for popular Android-specific Maven Central artifacts declaring compile-time dependencies on androidx.annotation:annotation, e.g.: