android tutorial - Centralizing dependencies in Android | Developer android - android app development - android studio - android app developement
Centralizing dependencies via "dependencies.gradle" file
- When working with multi-module projects, it is helpful to centralize dependencies in a single location rather than having them spread across many build files, especially for common libraries such as the Android support libraries and the Firebase libraries.
One recommended way is to separate the Gradle build files, with one build.gradle per module, as well as one in the project root and another one for the dependencies, for example:
- Then, all of your dependencies can be located in gradleScript/dependencies.gradle:
- Which can then be applied from that file in the top level file build.gradle like so:
and in the module1/build.gradle like so:
Another approach
- A less verbose approach for centralizing library dependencies versions can be achieved by declaring the version number as a variable once, and using it everywhere.
In the workspace root build.gradle add this:
- And in every module that uses the same library add the needed libraries