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