gradle 中implementation ,compile ,api的区别

首先在AndroidStudio3.x中compile已经过时

由implementation和api来代替

 

 

其次compile与api完全等同 3.x中可以完全将compile换成api

mplementation与api的区别

implementation编译的依赖只作用于当前的module。即app module依赖了other module,

other module中使用implementation编译的三方库(如glide)只对other module起作用,

app module中无法使用该三方库(glide);

如果other module 使用implementation依赖了base module,则APP module中无法使用base module。

举个示例:

我们把其它module中的对com.alibaba.fastjson:1.2.6引用改成implementation

 

 

 那么我们在app module里面是无法使用的 因为implementation 只对当前module生效

便会提示:错误: 程序包com.alibaba.fastjson不存在

 

 

 

总体介绍

compile(api)
这种是我们最常用的方式,使用该方式依赖的库将会参与编译和打包。

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

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

testCompile(testImplementation)
testCompile 只在单元测试代码的编译以及最终打包测试apk时有效。

debugCompile(debugImplementation)
debugCompile 只在debug模式的编译和最终的debug apk打包时有效。

releaseCompile(releaseImplementation)
releaseCompile 仅仅针对Release模式的编译和最终的Release apk打包。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值