首先在根目录下新建一个config.gradle文件,然后只需要在根目录的build.gradle下添加一行代码:
apply from: 'config.gradle'
config.gradle中一般这么写,根据自己项目进行配置
ext {
//support
compileSdkVersion = 26
minSdkVersion = 21
targetSdkVersion = 26
buildToolsVersion = '26.0.2'
supportLibVersion = "26.0.1"
androidSupport = "com.android.support"
dependencies = [
// support
supportAppCompat : "$androidSupport:appcompat-v7:$supportLibVersion",
supportDesign : "$androidSupport:design:$supportLibVersion",
supportRecyclerview : "$androidSupport:recyclerview-v7:$supportLibVersion",
supportCardView : "$androidSupport:cardview-v7:$supportLibVersion",
supportMultidex : "$androidSupport:multidex:1.0.1",
//下面可以配置三方依赖
//组件通信
eventbus : "org.greenrobot:eventbus:3.1.1",
]
}
module使用
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.XXXX"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
dependencies{
compile rootProject.ext.dependencies["supportDesign"]
compile rootProject.ext.dependencies["supportAppCompat"]
compile rootProject.ext.dependencies["supportRecyclerview"]
compile rootProject.ext.dependencies["eventbus"]
}
}