gpt4 book ai didi

android - Gradle依赖配置: implementation vs api vs runtimeonly vs compileonly

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:41 24 4
gpt4 key购买 nike

无法理解 Android Studio 3.0 中引入的最新 gradle 依赖配置,即实现、api、compileonly 和 runtimeonly。

最佳答案

请引用链接:Android Studio 3.0 New Gradle Configuration可在 android 开发者官方网站上获得。

根据上面链接中提到的描述:

  • implementation: When your module configures an implementation dependency, it's letting Gradle know that the module does not want toleak the dependency to other modules at compile time. That is, thedependency is available to other modules only at runtime. Using thisdependency configuration instead of api or compile can result insignificant build time improvements because it reduces the amount ofprojects that the build system needs to recompile. For example, if animplementation dependency changes its API, Gradle recompiles only thatdependency and the modules that directly depend on it. Most app andtest modules should use this configuration.
  • api: When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export thatdependency to other modules, so that it's available to them at bothruntime and compile time. This configuration behaves just like compile(which is now deprecated), and you should typically use this only inlibrary modules. That's because, if an api dependency changes itsexternal API, Gradle recompiles all modules that have access to thatdependency at compile time. So, having a large number of apidependencies can significantly increase build times. Unless you wantto expose a dependency's API to a separate test module, app modulesshould instead use implementation dependencies.
  • compileOnly: Gradle adds the dependency to the compilation classpath only (it is not added to the build output). This is usefulwhen you're creating an Android library module and you need thedependency during compilation, but it's optional to have present atruntime. That is, if you use this configuration, then your librarymodule must include a runtime condition to check whether thedependency is available, and then gracefully change its behavior so itcan still function if it's not provided. This helps reduce the size ofthe final APK by not adding transient dependencies that aren'tcritical. This configuration behaves just like provided (which is nowdeprecated).
  • runtimeonly: Gradle adds the dependency to the build output only, for use during runtime. That is, it is not added to the compileclasspath. This configuration behaves just like apk (which is nowdeprecated).

关于android - Gradle依赖配置: implementation vs api vs runtimeonly vs compileonly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47365119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com