图书馆与图书馆的区别图书馆计划外部图书馆 [英] Difference Between Library & Library Project & External Libraries

查看:35
本文介绍了图书馆与图书馆的区别图书馆计划外部图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android Studio IDE 中,您可以添加 .jar 文件.您还可以添加库项目"的整个项目.还有 Android 库(来自 Gradle)作为外部库添加.

In the Android Studio IDE you can add a .jar file. You can also add entire projects that are 'Library Projects'. And there are also the Android libraries (from Gradle) added as External Libraries.

.jar

图书馆项目

外部图书馆

我知道 .jars 就是这样.但是为什么其他库(库项目)需要添加它们自己的完整构建文件(如 gradle、res、src 等).让我的理解更加复杂的是,Gradle 下载的那些被添加为外部库",并且那些具有 .jar 文件和 res 文件夹.

I get that .jars are just that. But then how come other libraries (Library Projects) need to get added that have entire build files of their own (like gradle, res, src etc). And further complicating my understanding, the Gradle downloaded ones are added as 'External Libraries' and those have .jar files and a res folder.

您能解释一下为什么可以将库添加为 .jar、整个项目或外部库吗?

Could you explain why libraries can be added as .jar, entire projects, or as external libraries?

推荐答案

您能解释一下为什么可以将库添加为 .jar、整个项目或外部库吗?

Could you explain why libraries can be added as .jar, entire projects, or as external libraries?

你有不同的可能性,因为你可以有不同的情况.库通常是由其他团队构建的,您无法决定它的分发方式.

You have different possibilities, because you can have different cases. Often the library is built by other team and you can't decide how it is distributed.

  • 您可以在本地拥有一个自己的库或一个分支.在这种情况下您有代码,并且可以将此库添加为模块
  • You can have a own library or a fork locally. In this case you have the code and you can add this library as a module

在这种情况下,只需在 module/build.gradle 中添加:

In this case just add in the module/build.gradle:

apply plugin: 'com.android.library'

并在主项目中添加依赖项,如:

and add the dependency in the main project like:

dependencies{
  compile project(':module')
}

  • 您可以使用 ma​​ven 依赖项.在这种情况下,有人将库上传到了 Maven 存储库中.
    目前,我认为这是最好的解决方案.
    • You can use a maven dependency. In this case someone uploaded the library in a maven repository.
      Currently it is the best solution in my opinion.
    • 在这种情况下,只需在您的项目中添加一个依赖项

      In this case just add a dependency in your project

      dependencies{
        compile 'group:name:version'
      }
      

      此依赖项可以是 aar 文件,也可以是 jar 文件.
      您也可以在公共或私有 Maven 中发布您自己的库.

      This dependency can be a aar file, but also a jar file.
      Also you can publish in a public or private maven your own libraries.

      • 您可以在项目中添加aar 文件

      在这种情况下定义您的平面存储库:

      In this case define your flat repository:

      repositories {
          flatDir {
              dirs 'libs'
          }
      }
      

      并添加依赖项:

      dependencies {
         compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
       }
      

      • 您可以在项目中添加jar 文件
      • 在这种情况下,通常您可以将所有 jar 文件放在 libs 文件夹中并添加依赖项:

        In this case usually you can put all jars in the libs folder and add the dependency:

        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
        }
        

        这篇关于图书馆与图书馆的区别图书馆计划外部图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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