本地AAR库的传递依存关系 [英] Transitive dependencies for local aar library

查看:95
本文介绍了本地AAR库的传递依存关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为API创建一些库,基本上是为了使外部开发人员的工作更轻松.

We're making some library, basicly for our API, that we would make life easier for our external developers.

因此,我们创建了新的库项目,并将Retrofit和其他一些库作为依赖项.

So we created new library project and put Retrofit and some other libraries as dependencies.

dependencies {
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.1'
    compile 'com.squareup.retrofit2:converter-gson:2.0.1'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
}

现在,当我们构建它时,它会生成aar文件.

Now when we build it, it produces aar file.

但是现在,当我们将aar文件放置到libs目录并将其设置为依赖项时,我们仍然必须将相同的依赖项放入用户的build.gradle文件中,这很糟糕.应该从图书馆取走,对吧?

But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile(name: 'ourlibrary', ext: 'aar') {
        transitive = true;
    }
}

如何使transitive = true工作?

推荐答案

aar 文件不包含嵌套的(或

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.

这意味着,如果要使用flatDir存储库导入aar文件,则还必须在项目中指定依赖项.

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

对于您来说,添加transitive=true不能解决您的问题,原因如上所述.

In your case adding transitive=true doesn't resolve your issue for the reason described above.

您应该使用 Maven存储库(您必须在私有或公共Maven存储库中发布库),您不会遇到相同的问题.
在这种情况下,gradle使用pom文件下载依赖项,该文件将包含依赖项列表.

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.

这篇关于本地AAR库的传递依存关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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