在AndroidStudio中构建项目的时候,可以通过build.gradle来配置一些常量,用于全局使用,比如说APP的版本号、作者名、公司名等等。那么怎么实现这些配置呢?
首先我们打开android项目app目录下的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.xing.app.xxx"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
//省略部分代码
}
如果没有意外的话,打开应该