每個模塊使用
compile 'com.android.support:appcompat-v7:23.1.1'
並不意味着添加了兩遍或更多次。
Gradle處理它只爲您添加一次庫。
使用多模塊項目,可以將支持庫依賴關係集中在gradle中。
一個很好的方法是分離gradle這個構建文件,定義是這樣的:
root
--gradleScript
----dependencies.gradle
--module1
----build.gradle
--module2
----build.gradle
--build.gradle
在gradleScript/dependecies.gradle
:
ext {
//Version
supportLibrary = '23.2.0'
//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}",
]
}
在頂層文件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.5.0'
}
}
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
在module1/build.gradle
:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
如何在排除組中添加依賴關係? –