gpt4 book ai didi

java - Android 在内部与外部导入库的好处

转载 作者:IT老高 更新时间:2023-10-28 23:13:00 26 4
gpt4 key购买 nike

在 ADT 17 之后,非 Android 库需要包含在项目的“libs”文件夹中,或者通过构建路径中的“Order and Export”选项卡导出。 外部导入库有什么区别(如果有):

External1

External2

以及内部:

Internal2

Internal1

以将库包含在“Android 依赖项”组中的方式导入库是否有优势?

最佳答案

如何将外部 jar 依赖项添加到 Android 项目的构建路径(内部或外部)对实际构建过程没有影响(更具体地说是在 compile 和 dex 步骤),它所做的只是告诉构建过程在哪里寻找用于编译和 dex 步骤所需的 jar。

Java Build Path - Libraries 窗口中显示的 Android Dependencies 元素只是 ADT 插件用于管理/分组 jar 依赖项的另一个抽象层。您的外部 jar 文件(在您的情况下为 android-support-v4.jar)出现在该窗口中(在 Android 依赖项 内部或外部)的位置没有区别。

从r17开始,依赖管理有了很大的改进,推荐使用libs/目录存储所有jar依赖(引用你内部的方式),这被认为是一种自动化的方式(现在ADT插件变得更智能了) ,见 Revisions for ADT 17.0.0 :

New build features

  • Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)

但是,如果您愿意,您仍然可以使用旧方法(请参阅外部方法),这被认为是手动方法(因为 ADT 插件以前很愚蠢),请参阅 Recent Changes‎ for r17 Release :

Important: If you are still referencing jar libraries manually instead of putting them under libs/ be aware of the following:

  • If the project is a Library project, these jar libraries will not be automatically visible to application projects. You should really move these to libs/

  • If the project is an application, this can work but you must make sure to mark the jar files as exported.

以将库包含在“Android 依赖项”组中的方式导入库是否有优势?

从依赖管理的角度来看,自动化与手动相比,在计算机科学领域,自动化总是被认为比手动更无错误。

关于java - Android 在内部与外部导入库的好处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10478018/

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