implementation、api、compileOnly区别

4,814 阅读1分钟

compile依赖关系已被弃用,被implementation和api替代;

provided被compile only替代;

apk被runtime only替代;

api:跟2.x版本的 compile完全相同。

implementation和api区别:

implementation:只能在内部使用此模块,比如我在一个libiary中使用implementation依赖了gson库,然后我的主项目依赖了libiary,那么,我的主项目就无法访问gson库中的方法。这样的好处是编译速度会加快,推荐使用implementation的方式去依赖,如果你需要提供给外部访问,那么就使用api依赖即可

provided(compileOnly)作用:

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

apk(runtimeOnly)作用:

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

testCompile(testImplementation)作用:

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

debugCompile(debugImplementation)作用:

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

releaseCompile(releaseImplementation)作用:

Release compile 仅仅针对Release 模式的编译和最终的Release apk打包。

blog.csdn.net/yuzhiqiang_…