如何摆脱应用程序模块中特定于模块的库存储库?

时间:2018-09-21 08:18:11

标签: android gradle module

我正在模块化我的单模块应用程序,但是我遇到了一个我无法处理的问题。 我有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依赖项的存储库,也不是将这个'存储库'存储在顶级构建文件中。

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

1 个答案:

答案 0 :(得分:1)

当您的应用程序要访问库中使用的第三方时,也应将其依赖项添加到您的应用程序build.gradle中。因为它们之间没有像链之类的关系,所以第三方仅在您的图书馆中可见。因此,您应该在app build.gradle中添加它:

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