还不熟悉 2.x 版本依赖的可以看看下面的说明,括号里对应的是 3.0 版本的依赖方式。
compile(api)
这种是我们最常用的方式,使用该方式依赖的库将会参与编译和打包。
当我们依赖一些第三方的库时,可能会遇到com.android.support
冲突的问题,就是因为开发者使用的compile
依赖的com.android.support
包,而他所依赖的包与我们本地所依赖的com.android.support
包版本不一样,所以就会报All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes
这个错误。
provided(compileOnly)
只在编译时有效,不会参与打包
可以在自己的module
中使用该方式依赖一些比如com.android.support
,gson
这些使用者常用的库,避免冲突。
apk(runtimeOnly)
只在生成apk
的时候参与打包,编译时不会参与,很少用。
testCompile(testImplementation)
testCompile
只在单元测试代码的编译以及最终打包测试apk时有效。
debugCompile(debugImplementation)
debugCompile
只在 debug 模式的编译和最终的 debug apk 打包时有效
releaseCompile(releaseImplementation)
Release compile
仅仅针对 Release 模式的编译和最终的 Release apk 打包。