When to use api over implementation.

When to use api over implementation.

Recently on my android adventures, I decided to split up a project at work into modules and make my life simpler😃.

One of my modules is a themes module that cuts across all modules providing the necessary themes, styles and colours to other components, but creating the module and implementing it in other modules as shown didn't serve me as I had expected.

dependencies{
  implementation project(':themes')
}

crop-ttScreenshot from 2019-09-24 14-10-07.png

This was because my themes module was using the material design library which was not implemented in the other modules.

themes module build.gradle

So the next logical option might have been to go onto each module and implement the material design library above over and over again but this seemed extremely redundant.

Where api comes in...

From the Gradle documentation:

The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

Therefore in my case, I need to make the material design library accessible across my modules by just adding the themes module, and this is done simply by changing the implementation keyword to api as shown below and voila..its done🥳

crop-tttScreenshot from 2019-09-24 14-16-36.png

Resources

Gradle Docs