Android Gradle常用配置
2020-04-30 本文已影响0人
Sky_Blue
一、统一配置config.gradle
ext {
app = [
compileSdkVersion: 29,
buildToolsVersion: "29.0.3",
applicationId : "com.lven.immooc",
minSdkVersion : 16,
targetSdkVersion : 29,
versionCode : 1,
versionName : "1.0",
libVersionCode : 1, // 依赖版本,不用经常改
libVersionName : "1.0"// 依赖版本,不用经常改
]
depenLibs = [
appcompat : 'androidx.appcompat:appcompat:1.1.0',
constraintlayout: 'androidx.constraintlayout:constraintlayout:1.1.3'
]
}
// 文件和根目录build.gradle文件一致,根目录build.gradle导入配置文件
apply from: 'config.gradle'
二、项目使用、调试、清单配置
apply plugin: 'com.android.application'
android {
compileSdkVersion this.app.compileSdkVersion
buildToolsVersion this.app.buildToolsVersion
defaultConfig {
applicationId this.app.applicationId
minSdkVersion this.app.minSdkVersion
targetSdkVersion this.app.targetSdkVersion
versionCode this.app.versionCode
versionName this.app.versionName
}
buildTypes {
// 公共常量配置,在BuildConfig类
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// 清单里面用:${VERSION_NAME}
manifestPlaceholders = [
VERSION_NAME: this.app.versionName,
IS_DEBUG : "false"
]
// BuildConfig类下面的常量配置
buildConfigField("boolean", "IS_DEBUG", "false")
buildConfigField("String", "LOG_TAG", "\"Lven\"")
}
debug {
// 清单里面用:${VERSION_NAME}
manifestPlaceholders = [
VERSION_NAME: this.app.versionName,
IS_DEBUG : "false"
]
// BuildConfig类下面的常量配置
buildConfigField("boolean", "IS_DEBUG", "true")
buildConfigField("String", "LOG_TAG", "\"Lven\"")
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation this.depenLibs.appcompat
implementation this.depenLibs.constraintlayout
}
<!--清单引用配置测试-->
<meta-data
android:name="BUGLY_ENABLE_DEBUG"
android:value="${IS_DEBUG}" />
<meta-data
android:name="BUGLY_APP_VERSION"
android:value="${VERSION_NAME}" />