gradle依赖implementation,api,compileOnly

Android studio 版本更新至3.0时,连带着com.android.tools.build:gradle 插件工具也升级到了3.0.0,在插件3.0.0中使用了最新的Gralde 4.0 里程碑版本作为gradle 的编译版本,该版本gradle编译速度有所加速,更加欣喜的是,完全支持Java8。当然,对于Kotlin的支持,在这个版本也有所体现,Kotlin插件默认是安装的。依赖关键字也有所改变:

gradle依赖implementation,api,compileOnly

implementation

对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。使用implementation来进行依赖,这会大大改善工程的构建时间;只有你明确要向外部暴露所依赖lib的接口时,才需要使用api依赖,整体来说,会减少很多重新编译;也就是依赖不传递;

api(compile)

这种是我们最常用的方式,使用该方式依赖的库将会参与编译和打包;例如:A moudle依赖了B moudle,B moudle中使用api依赖了C库,则A也可以使用C库中的接口。依赖传递;

compileOnly(provided)

只在编译时有效,不会参与打包,可以在自己的moudle中使用该方式依赖;比如com.android.support,gson这些使用者常用的库,避免冲突;

runtimeOnly(apk)

只在生成apk的时候参与打包,编译时不会参与,很少用;

androidTestImplementation (androidtestCompile)

androidTestImplementation 只在单元测试代码的编译以及最终打包测试apk时有效;

debugImplementation (debugCompile)

debugImplementation 只在debug模式的编译和最终的debug apk打包时有效;

releaseImplementation (releaseCompile)

releaseImplementation 仅仅针对Release模式的编译和最终的Release apk打包;
————————————————

原文链接:https://blog.csdn.net/ezconn/article/details/112851615

上一篇:一个C#开发搭建Android框架的心路历程


下一篇:AAPT: error: resource android:attr/lStar not found解决办法