编译、提供、APK - Android 依赖范围 [英] Compile, Provided, APK - Android dependency scope

查看:36
本文介绍了编译、提供、APK - Android 依赖范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当向 android 项目添加新的依赖项时,尤其是在 Android Studio 中的 Dependencies 中有三个范围选项编译/提供/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.

"正确处理'provided' 和'package' 作用域以做他们应该做的事情.'provided' 和 'package' 不能与 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 - 仅编译时依赖
  • package - 仅包时依赖
  • compile - 编译时和包时依赖
    • provided - compile-time only dependency
    • package - package-time only dependency
    • compile - compile-time and package-time dependency
    • provided 通常用于基于注释处理的库.通常这些库被分成两个工件——注释"和编译器".compiler"是提供的依赖,因为你不需要在应用程序中使用它,只用于编译;并且注释"是 compile 依赖项 - 它在应用程序代码中使用并因此编译.或者生成的代码可能需要额外的依赖项,而您的应用程序可能不需要.例如.dagger 依赖配置:

      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'
      

      这篇关于编译、提供、APK - Android 依赖范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆