编译,提供APK - Android的依赖范围范围、APK、Android

2023-09-05 03:16:23 作者:迩何曾让涐懂

而在添加新的依赖于Android项目特别是在 Android的工作室依赖有三种作用域选项编译/提供/ APK。

While adding new dependencies to android project especially in Android Studio in Dependencies there are three scope options Compile/Provided/APK.

什么是选择每个人的影响,我们什么时候使用它们呢?再说什么名字说。

What are the effects of choosing each one, when should we use them ? Besides what the name says.

编辑:

妥善处理规定和包范围做他们应该做的。 '提供'和'包'不能与Android库使用,将产生一个错误。这是从http://tools.android.com/tech-docs/new-build-system

"Properly handle 'provided' and 'package' scopes to do what they should be doing. 'provided' and 'package' cannot be used with Android Libraries, and will generate an error" .. this is from http://tools.android.com/tech-docs/new-build-system

推荐答案

提供 - 编译时只能依赖 - 包时只依赖 编译 - 编译时和包时依赖

provided - compile-time only dependency package - package-time only dependency compile - compile-time and package-time dependency

提供通常用于注释处理基础库。通常这些库分居两神器 - 说文解字注和编译器。 编译是提供的依赖,因为你并不需要使用它的应用程序,只为汇编;和注释是编译相关性 - 它是用在应用code,因此编译。或者产生code可能需要额外的依赖,而你的应用程序可能不会。例如。匕首依赖配置:

provided is commonly used for annotation processing based libraries. Usually these libraries are separated in two artifacts - "annotation" and "compiler". "compiler" is provided dependency because you do not need to use it in application, only for compilation; and "annotation" is compile dependency - it is used in application code and therefore compiles. Or generated code may require additional dependencies while your application may not. E.g. dagger dependencies configuration:

compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'