浅谈浅谈Gradle 常用配置总结常用配置总结
这里分享下我在日常开发中对 Gradle 的常用配置规则
一、版本号配置一、版本号配置
当项目逐渐演进的过程中,主工程依赖的 Module 可能会越来越多,此时就需要统一配置各个 Module 的编译参数了
在工程的根目录下新建一个 gradle 文件,命名为 config.gradle ,在此文件中统一声明工程的编译属性和依赖库的版本号
ext {
compileSdkVersion = 28
minSdkVersion = 15
targetSdkVersion = 28
versionCode = 1
versionName = '1.0'
dependencies = [
appcompatV7 : 'com.android.support:appcompat-v7:28.0.0-rc02',
constraintLayout: 'com.android.support.constraint:constraint-layout:1.1.3',
junit : 'junit:junit:4.12',
testRunner : 'com.android.support.test:runner:1.0.2',
espressoCore : 'com.android.support.test.espresso:espresso-core:3.0.2'
]
}
默认情况下, App Module 的 build.gradle 文件的默认配置如下所示
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "leavesc.hello.gradlesamples"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}