简体   繁体   English

在生成.aar文件的Gradle Project中添加依赖项

[英]Adding Dependencies in Gradle Project which generates .aar file

I have a gradle project which generates .aar file which i used to import in another project to run app. 我有一个gradle项目,它生成.aar文件,我曾将其导入另一个项目中以运行应用程序。 Both projects have build.gradle file and i have to add dependencies in both projects gradle file to make application work. 两个项目都有build.gradle文件,我必须在两个项目gradle文件中添加依赖项才能使应用程序正常工作。

Is there any way we can remove dependency from one build.gradle so that the other project is not affected? 有什么办法可以从一个build.gradle中删除依赖项,从而使另一个项目不受影响?

The aar file doesn't contain the nested (or transitive ) dependencies and doesn't have a pom file which describes the dependencies used by the library. aar文件不包含嵌套的(或可传递的 )依赖项 ,也没有描述该库使用的依赖项的pom文件。

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project. 这意味着,如果要使用flatDir库导入aar文件,则还必须在项目中指定依赖项。

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue. 您应该使用Maven存储库 (您必须在私有或公共Maven存储库中发布库),不会遇到相同的问题。
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list. 在这种情况下,gradle使用pom文件下载依赖项,该文件将包含依赖项列表。

An alternative is to add the module as "external module". 另一种选择是将模块添加为“外部模块”。
Inside a project you can refer an external module . 在项目内部,您可以引用外部模块

Just use: 只需使用:

Project
|__build.gradle
|__settings.gradle
|__app (application module)
   |__build.gradle

In settings.gradle : settings.gradle

include ':app' 
include ':myExternalLib'
project(':myExternalLib').projectDir=new   File('pathLibrary')

In app/build.gradle : app/build.gradle

dependencies {
    compile project(':myExternalLib')
}

Pay attention to myExternalLib . 注意myExternalLib
You have to use the path of the library inside the other project, not the root of the project. 您必须使用其他项目中库的路径, 而不是项目的根目录

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

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