Search code examples
androidandroid-gradle-3.0

Avoid api and always use implementation?


Building a multi module Android app using Gradle plugin 3, instead of declaring a dependency with compile one should use implementation or api. The latter basically works like compile. Using implementation, the dependency is hidden from any module depending on this module.

So, let's say I have three modules A, B and C. B depends on A and C depends on B and A, like this: A <- B <- C (Gradle plugin 2 compile). With Gradle plugin 3 I could do just the same using "api". Would it make any difference if I explicitly declared all dependencies using implementation, like A <- B, A <- C, B <- C?

Asking a bit different: Why would I use api at all instead of explicitly declaring dependencies using implementation? It seems "saver" to avoid api. Is api just for convenience or am I missing any side effects?


Solution

  • In general, implementation recommended to use (it will speed-up project building and protect from dependency leaks)

    But if your module uses some it's dependencies at it's public API those dependencies should be added with api configuration otherwise users of your module should add those dependencies manually.