简体   繁体   English

在app模块中使用库模块的依赖关系

[英]Use dependency from library module in app module

Maybe it's a silly question, but want to collect an app's dependencies to library.(so I can easily manage all dependency's version) 也许这是一个愚蠢的问题,但是想要收集应用程序对库的依赖。(所以我可以轻松管理所有依赖项的版本)

app/build.gradle 应用程序/的build.gradle

api project(path: ':library')

library/build.gradle 库/的build.gradle

dependencies {
    implementation 'com.google.code.gson:gson:2.8.2' <- gson is just example, it can be anything.
}



In the above situation Can I use Gson from MainActivity.class? 在上面的情况下我可以使用MainActivity.class中的Gson吗? It seems to not be working.. 它似乎不起作用..

If not, is there a way to achieve this? 如果没有,有没有办法实现这一目标?

I don't want to add the same dependency to both the app and library. 我不想为应用程序和库添加相同的依赖项。 If Gson is updated, I have to modify two positions, I hate it! 如果Gson更新,我必须修改两个位置,我讨厌它! :( :(

Just do the reverse. 反过来说。

In your case, use implementation in app and api in library modules. 在您的情况下,在库模块中的app和api中使用implementation

implementation uses the dependency only for current module and api shares the dependency with other modules which use it. implementation仅对当前模块使用依赖关系, api与使用它的其他模块共享依赖关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM