Amid the COVID-19 outbreak, Folio3 aims to help clinics serve patients with telemedicine effectively.

Android Gradle: When to use what?

Android Gradle: When to use what?



On updating Android Gradle plugin 3.0 in your project, you might have noticed that you are getting warning:

This is because compile keyword has been now deprecated in favour of implementation and api but directly changing compile to implementation gives you dependency errors. You also can’t use api everywhere or you will get dexMerger errors.

In this blog, we will discuss both API and Implementation and when to use what.

Implementation Vs API:

Assume that we have four library modules:

  • LibCarA
  • LibEngineA
  • LibCarB
  • LibEngineB

The dependency tree would somewhat look like this:


(Scenario 1) Using ‘implementation’ Keyword to import library:

Now if we include LibEngineA in LibCarA as implementation project(‘:LibEngineA’) And we add LibCarA in our app module than app module won’t be able to use LibEngineA functionalities directly it can only access LibCarA functions.


(Scenario 2) Using ‘api’ Keyword to import library:

Now let’s import LibEngineB in LibCarB using api keyword as api project(‘:LibEngineB’) And import LibCarB in our AppModule. You will be able to use LibCarB and LibEngineB functionalities as well.


Why use Implementation instead of API ?

Let’s understand the difference on compilation level;s that why using implementation makes build time faster than API.

In the first scenario where we are importing LibEngineA in LibCarA using keyword implementation. Any change in LibEngineA gradle will only recompile LibEngineA and LibCarA. Also using implementation won’t conflict with imported library modules, other dependencies if the same library is imported in both modules thus there won’t be any dexMerger issues. As any other class which does not import LibEngineA directly cannot use any implementation of it.

In the second scenario where we are importing LibEngineB in LibCarB using api. If any change is implemented inside LibEngineB, Gradle needs to recompile LibEngineB, LibCarB and all other modules which import LibCarB as any other module might use implementation of LibEngineB.

So in conclusion its preferred to use implementation and to avoid API keyword until or unless it’s really necessary. It improves build time and when working on projects with lots of modules dependent on each other it will help a lot in resolving dex merger issues to find the perfect api and implementation keyword use.


Please feel free to reach out if you have any questions. In case you need any help with development, installation, integration, up-gradation and customization of your Business Solutions. We have expertise in Enterprise Application Development Solutions. Connect with us for more information. [email protected]


USA408 365 4638


1301 Shoreway Road, Suite 160,

Belmont, CA 94002

Latest From Our Blog

Why the Daily Scrum is NOT a Status Meeting?

February 3, 2020
I am here today to debunk, The Myth “The Daily Scrum is the Status Meeting”. This is a key misconception in the industry and often resu...
Read more

A Complete Guide to Custom Caching in Magento 2...

November 29, 2019
In this blog, I will explain how to create your own cache in Magento 2, and how to read and write data from that custom cache. I hope after reading...
Read more

React Hooks

September 3, 2019
React is a javascript framework for building interactive client side interfaces along with the integration with back-end server. React considers th...
Read more