本地 aar 库的传递依赖

Transitive dependencies for local aar library(本地 aar 库的传递依赖)
本文介绍了本地 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.

您应该使用 ma​​ven 存储库(您必须在私有或公共 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 库的传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)