Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle Implementation vs CompileOnly Performance

People also ask

What is the difference between compileOnly and implementation in Gradle?

Gradle introduced compileOnly quite some time ago. One use case of using compileOnly (according to their blog) is: Dependencies whose API is required at compile time but whose implementation is to be provided by a consuming library, application or runtime environment.

Is compileOnly deprecated?

compileOnly is the replacement — the equivalent configuration that is being deprecated is provided .

What is the difference between api and implementation scopes Gradle?

If you are working on an interface or module that provides support to other modules by exposing the members of the stated dependency you should be using 'api'. If you are making an application or module that is going to implement or use the stated dependency internally, use 'implementation'.

What is testImplementation in build Gradle?

For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.


The api configuration should be used for dependencies that are exported to external modules (transitive dependency). Vice-Versa implementation configuration should be used for dependencies that are internal to the component (not transitive dependency).

implementation vs compileOnly:

There is no similarity in their job, compileOnly is

  • a configuration inherited from java-plugin
  • required at compile time
  • also not included in the runtime classpath or exposed to dependent projects.

So compileOnly doesn't replace the implementation configuration job e.g:

implementation 'com.android.support:appcompat-v7:25.1.0' // can't use compileOnly here
testCompile 'junit:junit:4.12'

compile "com.google.dagger:dagger:2.8" // can't use here also
annotationProcessor "com.google.dagger:dagger-compiler:2.8" // can't use here also
compileOnly 'javax.annotation:jsr250-api:1.0' // we can use compileOnly here because it's required on run time only.

Since your case is a "multi-module", you have to use the api configuration, until you reach the final module it's better to use implementation.

Following graph describe those configurations:

enter image description here

Performance?

I think api requires more memory because gradle will snapshot every class in that transitive module, vice versa implementation is a preferred configuration because (as mentioned above) it's used for its own internal implementations.