Android DSL简介
2016-12-29 本文已影响71人
王小宝wy
Android DSL
Configuration Blocks
下面列出来的是可以在android{}范围内定义的Block:
-
defaultConfig{}默认的配置选项,会被所有Product Flavors继承 -
aaptOptions{}appt配置选项 -
adbOptions{}adb配置选项 -
buildTypes{}Build Types配置选项 -
compileOptions{}Compile的配置选项 -
dataBinding{}Data Binding的配置选项 -
dexOptions{}dex的配置选项 -
jacoco{}JaCoCo的配置选项 -
lintOptions{}lint配置选项 -
packageingOptions{}packaging配置选项 -
profuctFlavors{}Product Flavors的配置选项 -
signingConfigs{}Signing的配置选项 -
sourceSets{}配置Source Set -
splits{}配置Apk splits -
testOptions {}配置test options
defautlConfig
在这个Block中可以定义的属性有:
-
applicationId--> 应用的application ID, 应用的包名是用来在代码内部使用R以及确定各个类的位置,applicationId是用来在设备以及Googl Play上区分app的 -
consumerProguardFiles--> 将ProGuard文件包含在发布的AAR中 -
dimension--> 指定ProductFlavor的分组名称,以","隔开 -
jackOptions--> 编译jack的选项 -
manifestPlaceholders--> 同Manifest Merge相关 -
multiDexEnabled--> 是否开启Multi-Dex -
proguardFiles--> 指明要使用的proguard files,使用getDefaultProguardFile会返回文件的完整路径 -
signingConfig--> 签名选项 -
testApplicationId--> Test application ID -
testFunctionalTest-->instrument相关 -
testHandleProfiling-->instrument相关 -
testInstrumentationRunner--> Test instrumentation class name -
testInstrumentationRunnerArguments--> Test instrumentation runner custom arguments. e.g. [key: "value"] will give adb shell am instrument -w -e key value com.example...". -
vectorDrawable--> Options to configure the build-time support for vector drawables -
versionCode--> 版本号 -
versionName--> 版本名称
在这个Block中可以使用的Method有:
-
buildConfigField(type, name, value)--> 添加一个新的属性到BuildConfig -
consumerProguardFile(proguradFile)--> 添加一个progurad file到AAR中 -
consumerProguardFiles(proguradFiles)--> 添加多个proguard file到AAR中 -
maxSdkVersion(targetSdkVersion)--> 设置最大的SDK版本 -
minSdkVersion(targetSdkVersion)--> 设置最小的SDK版本 -
proguardFile(proguardFile)--> 添加一个新的Proguard file -
proguradFiles(proguradFiles)--> 添加多个新的Proguard file -
resConfig(config)--> 添加一个resource configuration filter -
resConfigs(config)--> 添加多个resource configuration filter -
resValue(type, name, value)--> 添加一个新的resource -
setConsumerProguardFiles(proguardFileIterable)--> 指定一个proguard file并添加到AAR中 -
setProguardFiles(proguardFileIterable)--> 设置proguard file -
setTestProguardFiles(files)--> 指定执行test code时的proguard file -
targetSdkVersion(targetSdkVersion)--> 设置target SDK version -
testInstrumentationRunnerArgument(key, value)--> Adds a custom argument to the test instrumentation runner -
testInstrumentationRunnerArguments(key, value)--> Adds custom arguments to the test instrumentation runner -
testProguardFile(proguardFile)--> 添加一个执行test code时的proguard file -
testProguardFiles(proguardFiles)--> 添加多个执行test code时的proguard file
BuildType
在这个Block中可以定义的属性有:
-
applicationIdSuffix--> 给applicationId添加后缀 -
consumerProguardFiles--> 包含在AAR中的Proguard rule files -
debuggable--> 指明当前build type是否产生debuggable apk -
embedMicroApp--> Whether a linked Android Wear app should be embedded in variant using this build type -
jniDebuggable--> 指明产生的APK是否包含可调试的native code -
manifestPlaceholders--> The Manifest placegolders -
minifyEnabled--> 指明Minify是否开启 -
multiDexEnabled--> 指明Multi-Dex是否开启 -
proguardFiles--> 指明要使用的Proguard rule files -
pseudoLocalesEnabled--> 指明是否在APK中产生pseudo locale -
renderscriptOptmLevel--> 指明使用renderscript compiler时的Optimization level -
shrinkResources--> 指明是否shrink不用的资源,默认是false -
signingConfig--> 签名选项 -
testCoverageEnabled--> 指明test coverage是否开启 -
versionNameSuffix--> 指明给版本号添加的后缀 -
zipAlignEnabled--> 指明zipalign是否开启
可以使用的方法有:
buildConfigField(type, name, value)consumerProguardFile(proguardFile)consumerProguardFiles(proguardFiles)proguardFile(proguardFile)proguardFiles(proguardFiles)resValue(type, name, value)setProguardFiles-
shrinkResources(flag)--> 指明是否shrink不用的资源,默认为false