有時候你需要在你的各個lib module中,配置各種依賴版本、編譯版本贮聂、最大最小版本支持表窘,這時候各種版本的升級、管理會顯示格外重復(fù)拿撩,或者你可以選擇一個文件,來實(shí)現(xiàn)方(tou)便(lan)管理與維護(hù)。
首先定義一個依賴管理gradle:dependence.gradle猪叙,將庫和版本都存放其中。
在項(xiàng)目根gradle中導(dǎo)入:apply from: 'dependencies.gradle'隙咸。
在其他項(xiàng)目中統(tǒng)一引用沐悦,這樣各個項(xiàng)目中的版本也能夠統(tǒng)一管理啦。
dependence.gradle
ext {
androidBuildToolsVersion = "23.0.2"
androidMinSdkVersion = 16
androidTargetSdkVersion = 23
androidCompileSdkVersion = 23
supportLibraryVersion = '23.0.2'
version = '1.5'
android = [
recyclerView: "com.android.support:recyclerview-v7:${supportLibraryVersion}",
appcompat_v7: "com.android.support:appcompat-v7:${supportLibraryVersion}",
support_v4 : "com.android.support:support-v4:${supportLibraryVersion}",
]
view = [
aaaaaa: "com.xxxxxx:aaaaaa:${version}",
]
}
app/lib 的build.gradle
android {
def globalConfiguration = rootProject.extensions.getByName("ext")
compileSdkVersion globalConfiguration.androidCompileSdkVersion
buildToolsVersion globalConfiguration.androidBuildToolsVersion
defaultConfig {
applicationId "com.xxx.xxxx"
minSdkVersion globalConfiguration.androidMinSdkVersion
targetSdkVersion globalConfiguration.androidTargetSdkVersion
versionCode 1
versionName "1.0.0"
ndk {
//設(shè)置支持的SO庫架構(gòu)
abiFilters 'armeabi', 'armeabi-v7a', 'x86'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
def view = rootProject.ext.view
def android = rootProject.ext.android
compile android.appcompat_v7
compile view.aaaaaa
}