Transitive dependencies for local aar library(本地 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 文件不包含嵌套的(或 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 库的传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:本地 aar 库的传递依赖
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
