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! :(
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.
Dependency is a much more broader term than plain libraries. It can mean data, software installed, whatever. Maybe they meant to say “may depend on libraries and other dependencies”. A library is not the only thing software can depend on: configuration files, device drivers, databases, etc.
Click on “Import Existing Project“. Step 2: Select the desired library and the desired module. Then click finish. Android Studio will import the library into your project and will sync Gradle files.
Module dependencies are classes, archives, libraries and resources that your module files references. While a library is a set of class files stored in an archive or directory. Export check means if checked then this library will be implicitly added to the other module that references this one.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With