android - 如何在Android gradle中使用嵌套依赖?

标签 android android-studio gradle

我在使用 gradle 时遇到问题:

我有一个库项目,它有两个库模块(称为libA,libB), libA 是我推送到本地 Maven 的项目,libB 是 libA 的依赖项之一,如下所示:

  compile project (':libB')

上传到maven后,我在应用程序中使用libA作为依赖项

  compile 'com.luis.lib:libA:1.0'

由于某种原因,我也在应用程序中使用libB的API,所以当我编译时,发生错误,它找不到libB。错误代码:

错误:配置项目“:app”时出现问题。

Could not resolve all dependencies for configuration ':app:_coohuaOnlineTestReleaseCompile'. Could not find CoohuaFramework:qrscanner:unspecified. Searched in the following locations: repo1.maven.org/maven2/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom repo1.maven.org/maven2/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar maven.coohua.com:8002/nexus/content/repositories/releases/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom maven.coohua.com:8002/nexus/content/repositories/releases/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar jcenter.bintray.com/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom https://jcenter.bintray.com/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar file:/Users/douhua/.m2/repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom file:/Users/douhua/.m2/repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar file:/Users/douhua/Library/Android/sdk/extras/android/m2repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom file:/Users/douhua/Library/Android/sdk/extras/android/m2repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar file:/Users/douhua/Library/Android/sdk/extras/google/m2repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.pom file:/Users/douhua/Library/Android/sdk/extras/google/m2repository/CoohuaFramework/qrscanner/unspecified/qrscanner-unspecified.jar Required by: CooHuaClient:app:unspecified > com.coohua.framework:CoohuaFramework:1.6.5

不知道为什么,我也尝试了'transitive=true',但没有帮助。

但是:当我将 libB 的所有代码移动到 libA 作为其一部分时。一切正常,我可以在应用程序中使用 libB 的代码。

谁能告诉我为什么会发生这种情况以及如何解决它?

最佳答案

您已将 libA 推送到 Maven 存储库中。

既然你的 LibA 已经

compile project (':libB')

在pom文件中,libA与libB有依赖关系。

您必须将 libB 推送到 Maven 存储库

这将解决您的问题,因为当您的项目使用时:

 compile 'com.luis.lib:libA:1.0'

Gradle 将解析读取 pom 文件的嵌套依赖项。

I don't know why, I also tried 'transitive=true' but it didn't help.

transitive=true 表示您要下载嵌套依赖项。我认为传递= false 不会解决问题,因为您的 pom 文件中的问题具有未知的依赖项。

BUT: when I moved all the code of libB to libA as part of it. everything works, I can use libB's code in the app.

它可以解决,因为通过这种方式,您不添加依赖项,而是将代码嵌入到 libA 中。

关于android - 如何在Android gradle中使用嵌套依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33605004/

相关文章:

android - PreferenceFragment 中的上下文

Android:将图像转换为字节数组

android - 分配跟踪器已禁用

java - 动态设置一个ContentProvider的权限

使用 Tesseract 的 Android OCR

java - 如何将现有的java项目导入android studio?

build - Gradle 的术语评估和执行之间的区别

spring-boot - Spring Boot 中带有 Gradle 的 Mapstruct + Lombok(未找到 Bean)

maven-2 - 为 gradle 生成的 Maven pom 设置编译器级别

Android Studio : How to disable updates for just core platform version?