【问题标题】:How can I get rid of module specific libraries repositories in application module?如何摆脱应用程序模块中的模块特定库存储库?
【发布时间】:2018-09-21 16:30:03
【问题描述】:

我正在模块化我的单模块应用程序,但我遇到了一个我无法处理的问题。 我有 2 个模块,我们称它们为 :app (com.android.application 模块) 和 :library (com.android.library)。

:library 模块依赖于另一个 android 库(播放器的 brightcove sdk),它的 build.gradle 看起来像:

repositories {
   maven { url 'http://repo.brightcove.com/releases' }
}
dependencies {
   ...
   implementation "com.brightcove.player:exoplayer2:6.3.1"
}

我的 :app 模块只依赖于 :library 模块

dependencies {
   implementation (':library')
}

但问题是在同步期间 IDE 向我抱怨

Error:Unable to resolve dependency for ':app@debug/compileClasspath': 
Could not resolve com.brightcove.player:exoplayer2:6.3.1.

只有在将相同的存储库添加到 :app 模块后才能解决它。 但我真的不想从 ':app' 中的 ':library' 复制所有 aar 依赖项的存储库,也不想将这个 'repositories' 存储在顶级构建文件中。

在多模块 android 应用程序中处理此类情况的正确方法是什么?

【问题讨论】:

  • 只需在库模块中将implementation 更改为api。并且这个依赖会传播到app 模块。

标签: android gradle module


【解决方案1】:

当您的应用想要访问库中使用的第三方时,您也应该将其依赖项添加到您的应用 build.gradle。因为它们之间没有像链一样的关系,第三方仅在您的库中可见。所以,你应该在 app build.gradle 中添加这个:

dependencies {
     implementation "com.brightcove.player:exoplayer2:6.3.1"
}

【讨论】:

  • 感谢您的回答。实际上不需要将此依赖项添加到 :app 模块。即使我只包含存储库 { maven { url 'repo.brightcove.com/releases' } } w/o 在依赖项中添加库,它也可以正常工作。但这对我来说似乎有点奇怪。
猜你喜欢
  • 1970-01-01
  • 2019-12-21
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-23
相关资源
最近更新 更多