dependencies

dependencies的类型可以分为以下几种

  • compile
    • testCompile
    • androidTestcompile
    • debugCompile
    • releaseCompile

从依赖上讲,用compile修饰的配置会传递依赖,而大多数的依赖冲突都是由compile产生的

从编译上讲,使用compile配置的依赖项,会跟随打包流程将源码打包到apk中

testcompile和androidTestcompile不会参与源码打包,只会参与测试包的打包,并且只有在测试模式下启动才会生效,debug和release包不生效

debugCompile只在buildType为debug的时候参与打包,release不参与打包,releaseCompile和debugCompile完全相反,只在release模式下参与打包

  • implementation
    • testImplementation
    • androidTestImplementation
    • debugImplementation
    • releaseImplementation

implementation和compile不同,该依赖方式不会产生传递依赖。很大程度减少重复依赖的问题。在开源 lib 的时候尽量采用implementation的方式依赖一些v4、v7包

  • provided

只参与编译,不参与打包。例如说有libB依赖了libA,moduleC又同时依赖了libA和libB,那么libB就可以使用provided来依赖libA。

  • api

api是Gradle4.1(Android studio3.0)新增的依赖方式,其作用于compile基本一致。

 

猜你喜欢

转载自blog.csdn.net/zhanyahuiv5/article/details/82108173
今日推荐