Adding Dependencies in Gradle Project which generates .aar file

自闭症网瘾萝莉.ら 提交于 2019-12-06 15:06:23

问题


I have a gradle project which generates .aar file which i used to import in another project to run app. Both projects have build.gradle file and i have to add dependencies in both projects gradle file to make application work.

Is there any way we can remove dependency from one build.gradle so that the other project is not affected?


回答1:


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.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

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.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

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:

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

In app/build.gradle:

dependencies {
    compile project(':myExternalLib')
}

Pay attention to myExternalLib.
You have to use the path of the library inside the other project, not the root of the project.



来源:https://stackoverflow.com/questions/34649901/adding-dependencies-in-gradle-project-which-generates-aar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!