Android Gradle实现与CompileOnly性能

Eli*_*zer 26 android gradle android-gradle-plugin android-gradle-3.0

文档提到implementation了相对于compile/ 提供了显着的构建时间改进api.怎么样compileOnly

我的用例是一个多模块(抱歉,我不喜欢Gradle的多项目术语)项目,我有一个Android应用程序,以及应用程序所依赖的多个库(implementation).一些图书馆也相互依赖.我应该使用implementationcompileOnly在库模块中声明依赖项时?我的app模块将implementation用于依赖这些工件,因此我不需要它们通过库模块传递.

小智 21

api配置应用于该出口到外部依赖modules (传递依赖).副Versa implementation配置应该用于组件内部的依赖(不是传递依赖).

implementation vs compileOnly:

有一个在他们的工作没有任何相似性,compileOnly

  • 从java-plugin继承的配置
  • 在编译时需要
  • 也不包含在运行时类路径中或暴露给依赖项目.

因此compileOnly不会替换implementation配置作业,例如:

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.
Run Code Online (Sandbox Code Playgroud)

由于您的案例是"多模块",您必须使用api配置,直到您到达最终模块,最好使用implementation.

下图描述了这些配置:

在此输入图像描述

性能?

我认为api需要更多内存,因为gradle会对该传递 模块中的每个类进行快照,反之亦然implementation是一种首选配置,因为(如上所述)它用于自己的内部实现.