debugCompile、xxxCompile、debugImplementation、releaseImplementation、testImplementation
众所周知,android stuido 在gradle中的依赖方式有好多个关键字,如
implementation、provided、api、apk、compileOnly、runtimeOnly 等等
但gradle中还会出现
debugImplementation这种,并没有在官网中定义的关键字
所以不禁要问 这是啥?啥规则,怎么写?
进入官网
搜索 implementation
出来的第一个 结果 点进去
https://developer.android.com/studio/build/dependencies
现在居然是中文了,感动T.T
以上配置会将依赖项应用于所有构建变体。如果您只想为特定的构建变体源代码集或测试源代码集声明依赖项,则必须将配置名称的首字母大写,并在其前面加上构建变体或测试源代码集的名称作为前缀。
例如,如需只向“free”产品变种添加 implementation 依赖项(使用远程二进制文件依赖项),请使用如下所示的代码:
所以回到咱们的问题,这是啥?啥规则,怎么写?
这是 :只想为特定的构建变体源代码集或测试源代码集声明依赖项
规则: 必须将配置名称的首字母大写,并在其前面加上构建变体或测试源代码集的名称作为前缀
怎么写:
第一步:
android {
buildTypes {
debug {}
release {}
freeddddffdfsdsfs{
matchingFallbacks = ['debug', 'qa', 'release']
}
}
}
第二步
debugImplementation(debugCompile)
debugImplementation 只在debug模式的编译和最终的debug apk打包时有效。
releaseImplementation(releaseCompile)
releaseImplementation 仅仅针对release 模式的编译和最终的release apk打包。
androidTestImplementation(androidTestCompile)
androidTestImplementation 只在单元测试代码的编译以及最终打包测试apk时有效。
freeddddffdfsdsfsImplementation(freeddddffdfsdsfsCompile)
freeddddffdfsdsfsImplementation 只有freeddddffdfsdsfs 模式下才有效