Soo Chun Jung
Soo Chun Jung

Reputation: 595

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

api project(path: ':library')

library/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? 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! :(

Upvotes: 8

Views: 2690

Answers (1)

Nabin Bhandari
Nabin Bhandari

Reputation: 16419

Just do the reverse.

In your case, use implementation in app and api in library modules.

implementation uses the dependency only for current module and api shares the dependency with other modules which use it.

Upvotes: 19

Related Questions