Android Gradle实现与CompileOnly性能 [英] Android Gradle Implementation vs CompileOnly Performance
问题描述
文档提及实现
比编译
/ api
。关于 compileOnly
?
我的用例是一个多模块(对不起,我不喜欢Gradle的多模块)项目术语)项目,我有一个Android应用程序,以及该应用程序依赖的多个库( implementation )。一些图书馆也相互依赖。在库模块中声明依赖关系时,我应该使用
implementation
还是 compileOnly
?我的应用程序模块将使用 implementation
来依赖这些工件,所以我不需要它们通过库模块传递。
<对于导出到外部
模块的依赖关系,应该使用 api
配置 (传递依赖)。副元素实现
配置应该用于组件内部的依赖关系(不是传递依赖关系)。
实施与 compileOnly :
他们的工作没有相似之处, compileOnly
是
- 编译时需要的一个从java-plugin继承的配置
-
- 也未包含在运行时classpath或暴露于相关的
项目中。
所以 compileOnly
doesn替换实现
配置作业,例如:
implementation'com。 android.support:appcompat-v7:25.1.0'//不能在这里使用compileOnly
testCompile'junit:junit:4.12'
compilecom.google.dagger:dagger: 2.8//在这里也不能使用
annotationPr ocessorcom.google.dagger:dagger-compiler:2.8//在这里也不能使用
compileOnly'javax.annotation:jsr250-api:1.0'//我们可以在这里使用compileOnly,因为它在运行时是必需的只有时间。
由于您的情况是多模块,您必须使用 api
配置,直到您到达最终模块为止,最好使用 implementation
。
以下图表描述了这些配置:
< img src =https://i.stack.imgur.com/MibMR.pngalt =在这里输入图片描述>
性能?
我认为 api
需要更多内存,因为 gradle 将快照传递 模块中的每个类,反之亦然实现是首选配置,因为(如上所述)用于其自己的内部实现。
The docs mention that implementation
provides significant build time improvements over compile
/api
. What about compileOnly
?
My use case is a multi-module (sorry I don't like Gradle's multi-project terminology) project, where I have an Android app, and multiple libraries that the app depends on (implementation
). Some of the libraries also depend on one another. Should I use implementation
or compileOnly
when declaring dependencies in the library modules? My app module will be using implementation
to depend on those artifacts, so I don't need them to be transitive through the library modules.
解决方案 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:
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.
这篇关于Android Gradle实现与CompileOnly性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文