Jay Taylor's notes
back to listing indexHow to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)
[web search]Centralize the support libraries dependencies in gradle
Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.
A very good way is to separate gradle build files, defining something like:
root
--gradleScript
----dependencies.gradle
--module1
----build.gradle
--build.gradle
In gradleScript/dependecies.gradle
:
ext {
//Version
supportLibrary = '22.2.1'
//Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}",
cardView : "com.android.support:cardview-v7:${supportLibrary}",
appCompat : "com.android.support:appcompat-v7:${supportLibrary}",
supportAnnotation: "com.android.support:support-annotations:${supportLibrary}",
]
}
In the top level file build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
In the module1/build.gradle
:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
jfabrix101 commented on Sep 13, 2015
Very useful tip |
IlyaEremin commented on Feb 11, 2016
Also, you can union all supportDependencies in following way: |