Android Studio build.gradle 里 dependencies compile 和 implementation 的区别

https://blog.csdn.net/Wang_WY/article/details/79625702
Gralde 4.0  Kotlin   
 

compile fileTree(dir: 'libs', include: ['*.jar'])

implementation fileTree(dir: 'libs', include: ['*.jar'])
api fileTree(dir: 'libs', include: ['*.jar'])

compile 指令被标注为过时方法,而新增了两个依赖指令,一个是implementation和api,这两个都可以进行依赖添加


api

完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。

implementation

这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,
也就是将该依赖隐藏在内部,而不对外部公开。

下面是2.x版本依赖的说明,括号里对应的是3.0版本的依赖方式。

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打包。

猜你喜欢

转载自blog.csdn.net/kongbaidepao/article/details/86487948