简体   繁体   English

Android:libs中的.jar文件与gradle中的依赖项url

[英]Android: .jar file in libs vs dependency url in gradle

I have come across two ways when I am adding jar dependency in an android project in Android Studio. 在Android Studio的android项目中添加jar依赖项时,遇到了两种方法。

  1. Adding *.jar file in libs folder. 在libs文件夹中添加* .jar文件。
  2. Adding dependency url in gradle.build. 在gradle.build中添加依赖项URL。

Which one is better and why? 哪一个更好,为什么?

I particularly prefer the dependency URL. 我特别喜欢依赖项URL。 A static library file in the project directory is seldom a better choice. 在项目目录中的静态库文件很少是更好的选择。

If a dependency is updated, you just have to update the build.gradle . 如果依赖项已更新,则只需更新build.gradle No need of downloading and replacing files, which adds size to the project (kilo or megabytes in the file system). 无需下载和替换文件,这会增加项目的大小(文件系统中的千字节或兆字节)。 Also, manually updating these files is an error-prone action. 另外,手动更新这些文件是容易出错的操作。

If the project is in a version control system (eg Git), commiting the jars to the repository is arguably a bad practice, whereas a modification in build.gradle is perfectly acceptable. 如果项目在版本控制系统(例如Git)中,则将jar提交到存储库无疑是一种不好的做法,而build.gradle的修改是完全可以接受的。

Another advantage of dependency declaration is smart dependency management. 依赖声明的另一个优点是智能的依赖管理。 If an artifact in use depends on another one, the dependency management is done automatically by eg Gradle or Maven. 如果使用中的工件依赖于另一个工件,则依赖项管理将由Gradle或Maven自动完成。 If a statically added jar has a dependency, it has to be manually added to the project, which is a laborious, tedious, and error-prone task. 如果静态添加的jar具有依赖项,则必须将其手动添加到项目中,这是一项费力,繁琐且容易出错的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM