As seen in Android Studio 3.0 (canary 3.0), we now add depedencies
by declaring implementation
instead of compile
configuration.
// Before
compile 'com.android.support:appcompat-v7:25.3.1'
// Currently
implementation 'com.android.support:appcompat-v7:25.3.1'
We can still use compile
, but I would like to understand:
implementation
and compile
configuration?implementation
as default?Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.
The compileOnly configuration is used to itemize a dependency that you need to compile your code, same as compile above. The difference is that packages your java code use from a compileOnly dependency will not be listed as Import-Package manifest entries.
Gradle build script defines a process to build projects; each project contains some dependencies and some publications. Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path.
Thanks to the really useful link from @petter, I would like to add a summary as following.
It means that Android Gradle build
starts to use the java-library
plugin instead of its previous java
plugin. This plugin introduces the exposed API
concept with two configuration
to declare dependencies.
should be used to declare dependencies which are exported by the library API
For example, in a case that you are building a Java (or Android) library which is used by other apps. If you use any third-party library and you want to expose its API to your library's consumer also, you should declare like this.
api 'commons-httpclient:commons-httpclient:3.1'
should be used to declare dependencies which are internal to the component.
When developing Android app, our app
module is the end point which does not need to expose any part externally. implementation
should be used.
implementation 'org.apache.commons:commons-lang3:3.5'
The previous compile
configuration works the same as api
. The implementation
, however, brings the following benefits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With