BuildConfig成员变量:
生成后都是public static final 类型;在gradle脚本中定义方式为:
defaultConfig {
...
buildConfigField "String", "APP_KEY", '"3b495847766em3f74f6e07d0"'
buildConfigField "Integer", "DEFAULT_PORT", '5000'
}
生成文件为对应包下的BuildConfig.java
Manifest常量,在AndroidManifest.xml
中使用例如${XIAOMI_APPKEY}
manifestPlaceholders = [
PKGNAME : applicationId,
CHANNEL : "developer-default",
XIAOMI_APPKEY : "MI-549754564161",
HUAWEI_APPID : "10374276",
MAP_APPKEY : "b10033ef0204e72768c8082677475283"]
gradle.properities
定义全局键值对
COMPILE_SDK_VERSION=28
BUILD_TOOLS_VERSION=28.0.0
TARGET_SDK_VERSION=28
MIN_SDK_VERSION=21
VERSION_NAME=1.0.0
VERSION_CODE=1
使用规则: 在model的build.gradle
中,字符串可以直接引用,整形需在后加 as int
defaultConfig {
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME as String
}
全局build.gradle
中定义常量
ext{
frescoVersion = '1.13.0'
eventbusVersion = '3.1.1'
picassoVersion = '2.5.2'
retrofitVersion = '2.5.0'
okhttploggingVersion = '3.4.1'
okhttpVersion = '3.4.1'
}
使用方法,在model的build.gradle
中引用示例:
dependencies {
//Fresco
api "com.facebook.fresco:fresco:$rootProject.frescoVersion"
api "com.facebook.fresco:imagepipeline-okhttp3:$rootProject.frescoVersion"
//eventbus
api "org.greenrobot:eventbus:$rootProject.eventbusVersion"
//picasso
api "com.squareup.picasso:picasso:$rootProject.picassoVersion"
// Retrofit
api "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
api "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
api "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
//okhttp
api "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttploggingVersion"
api "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
}
buildConfigField
编译进BuildConfig.java
manifestPlaceholders
gradle.properities
中定义为全局键值对;建议在这里定义整个项目的编译版本、版本号等build.gradle
定义常量;建议在这里管理所有第三方库的版本联系客服