Junior — Middle
What is the difference between API and implementation in the Gradle build system?
sobes.tech AI
Answer from AI
In Gradle, especially when working with Android, api and implementation configurations are used to manage dependencies and their visibility.
-
implementation— the dependency is available only within the current module. Other modules that depend on this module will not see this dependency. This improves build times because changes in such dependencies do not require rebuilding dependent modules. -
api— the dependency becomes part of the module's public API. This means modules that depend on this module can also use this dependency directly.
Example:
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.0' // used only within the module
api 'com.google.guava:guava:30.1.1-jre' // available to dependent modules
}
Use implementation when you want to hide implementation details, and api when you want the dependency to be accessible to consumers of your module.