title: Is it valid to publish an Android library with javax.inject as a dependency?
body: <p>I'm writing an Android library that depends on a JVM library that depends on <code>javax.inject</code>. The default Android linter appears to disallow <code>javax.inject</code> as a (transitive) dependency for most Android libraries, but it whitelists it for Dagger and Guice. Can I write an Android library with a <code>javax.inject</code> dependency, and if so, what considerations do I need to know about?</p>
  
  <p>I'm writing both of these libraries: a pure-JVM library, i.e. a JAR, and an Android library, i.e. an AAR, that depend on the JVM library.</p>
  
  <p>I would like my JVM library to support Dagger. The library is simple enough that I don't think providing a <code>@Component</code> or anything is necessary; just the <code>@Inject</code> constructor should do the trick.</p>
  
  <p>So, not wanting to burden non-Dagger consumers with any extra dexing etc., and thinking myself clever, I included just <code>javax.inject</code>, not Dagger itself, in the JVM library's build.gradle file:</p>
  
  <pre><code>implementation "javax.inject:javax.inject:1"
  </code></pre>
  
  <p>Thus Dagger users can just inject the JVM library's object as they see fit, and non-Dagger users never know the difference (because the <code>javax.inject</code> library is just a few annotations). In a test app with Dagger, this seems to work as expected.</p>
  
  <p>But! In the Android library that consumes the JVM library (and provides some Android-related conveniences for it), running <code>lint</code> causes an error: "Error: Invalid package reference in library; not included in Android: javax.inject." Since I knew that Dagger already uses this library I was confused, so I googled the lint error and found that the Android linter <a href="https://android.googlesource.com/platform/tools/base/+/master/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InvalidPackageDetector.java#268" rel="nofollow noreferrer">specifically whitelists Dagger</a>.</p>
  
  <p>Why is <code>javax.inject</code> disallowed by the default linter for all other libraries? Are Dagger and Guice doing something extra-special to make sure <code>javax.inject</code> is available, or can I just ignore the error?</p>