问题描述
我们正在制作一些库,主要是为了我们的 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 文件不包含嵌套的(或 transitive) 依赖项 并且没有描述所使用的依赖项的 pom 文件图书馆.
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 库的传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!