android gradle配置詳解

點擊打開鏈接

AppExtension類及其屬性

可能大部分人看到AppExtension類會感覺到非常的陌生,其實我們在app中的build.gradle中填寫配置信息的時候,經常看到它,它是什麼呢?

如果你按ctrl+鼠標左鍵對着Android{},點擊進去就知道了,其實android{…}表示的就是AppExtension這個類。

如圖:

image

我們再來看看AppExtension繼承關係:

image

除了AppExtension之外還有2個類與之相似,LibraryExtension和TestExtension

如果是module項目作爲lib使用,那麼lib下的build.gradle中的android對應的是LibraryExtension


AppExtension的屬性

  • aaptOptions:aapt是一個可以將資源文件編譯成二進制文件的工具。aaptOptions表示aapt工具設置的可選項參數。
  • adbExecutable:adb從編譯sdk時執行
  • adbOptions:adb的可選項參數
  • applicationVariants:應用變體列表
  • ==buildToolsVersion==:構建工具版本(必要的)
  • buildTypes:構建類型(一般是release和debug,還可以自定義)
  • compileOptions:編譯可選項參數
  • ==compileSdkVersion==:編譯sdk版本(必要的)
  • dataBinding:Data Binding可選項參數(關於DataBinding的使用)
  • defualtConfig:默認配置,對於所有的打包項目
  • defualtPublishConfig:默認是release。使用參考
  • dexOptions:Dex可選項參數。
  • externalNativeBuild:native編譯支持。參考
  • flavorDimensionList:
  • generatePureSplits:是否拆成多個APK
  • jacoco:JaCoCo可選項參數
  • lintOptions:Lint工具可選項參數
  • ndkDirectory:ndk目錄(一般在local.properties中)
  • packagingOptions:packaging的可選參數
  • productFlavors:項目所有flavor
  • publishNonDefualt:不僅僅使用默認的publish artifacts。可參考defualtPublishConfig。
  • resourcePrefix:創建新資源時使用的前綴。
  • sdkDirectory:sdk目錄(一般在local.properties中)
  • signingConfigs:簽名文件的可選項參數
  • sourceSets:資源文件目錄指定(Android中有自己的AndroidSourceSets,這個一般用於assets,jin等目錄)
  • splits:splits類型。
  • testBuildType:測試構建類型
  • testOptions:測試可選項參數
  • testVariants:測試變體
  • unitTestVariants:單元測試變體
  • variantFilter:變體過濾器

加粗的表示DSL語言的閉包

如:

buildTypes { }
  • 1
  • 1

AppExtension的方法: 
- flavorDimensions(dimension):指定flavor名稱 
- useLibraray(name):請求使用一個lib庫 
- useLibrary(name,required):與上面解釋一樣。


AppExtension的配置閉包(Configration blocks)

與app中build.gradle中android{}一樣,代碼中由AppExtension類表示。其他的配置閉包也一樣。

  • aaptOptions{}
aaptOptions{}代碼由AaptOptions類表示。

AaptOptions的屬性:
1.additionalParameters:額外參數,List類型。
2.cruncherEnabled:如果PNG圖片是否可以大量快速的處理,boolean類型。 true表示可以。
3.cruncherProcesses:快速處理,可能需要更多的內存和CPU。int類型。默認0,值越大處理越快,需要的內存和CPU也越大。
4.failOnMissingConfigEntry:如果沒有找到一個配置,就返回一個錯誤。Boolean值,默認false5.ignoreAssetsPattern:忽略Assets模塊。
6.moCompress:拓展文件不會打包進apk中。


用法(詳細用法可能需要去看看文檔了):

aaptOptions{
    cruncherEnabled true//快速處理PNG圖片
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

AaptOptions官方文檔


  • adbOption{}
adbOptions{}對應的是AdbOptions

AdbOptions的屬性:
1.installOptionsapk安裝的可選參數。
2.timeOutInMs:使用adb的超時時間。

不常用
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

  • buildTypes{}
buildTypes{}對應的是BuildType類

buildTypes的屬性:

1.applicationIdSuffix:應用id後綴(給Applica)
2.consumerProguardFiles:混淆文件包含在arr包中。
3.debuggable:是否生成一個debug的apk
4.embedMicroApp:可穿戴設備app是否可以使用這個編譯類型
5.javaCompileOption:Java編譯配置參數
6.jniDebuggable:這個編譯類型的配置是否可以與debuggable的native代碼生成一個apk
7.manifestPlaceholders:清單佔位符
8.minifyEnabled:是否縮小
9.multiDexEnabled:是否拆成多個Dex
10.multiDexKeepFile:指定文本文件編譯進主Dex文件中
11.multiDexKeepProguard:指定混淆文件編譯進主Dex文件中
12.name:build type的名字
13.proguardFiles:混淆文件
14.pseudoLocalesEnabled:是否生成僞現場apk(如果沒有提供混淆規則文件,則設置默認的混淆規則文件(SDK/tools/proguard/proguard-android.txt))
15.renderscriptDebuggable:使用RenderScript編譯器的優化級別。
16.shrinkResources:是否去除未利用的資源,默認false,表示不去除。
17.signingConfig:簽名配置
18.testCoverageEnabled:測試覆蓋率是否被激活。
19.useJack:過時
20.versionNameSuffix:版本名稱後綴
21.zipAlignEnable:是否使用zipalign工具壓縮。

------------------------------------------------------

buildType的方法:

1.buildConfigField(type,name,value):添加一個變量生成BuildConfig類。
2.consumeProguardFile(proguardFile):添加一個混淆文件進arr包。
3.consumeProguardFile(proguardFiles):添加混淆文件進arr包。
4.externalNativeBuild(action):配置本地的build選項。
5.initWith:複製這個build類型的所有屬性。
6.proguardFile(proguardFile):添加一個新的混淆配置文件。
7.proguradFiles(files):添加新的混淆文件
8.resValue(type,name,value):添加一個新的生成資源
9.setProguardFiles(proguardFileIterable):設置一個混淆配置文件。


------------------------------------------------------------


buildType用法:

  buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            shrinkResources true
            zipAlignEnabled true
            debuggable false
            //...
        }

        debug{
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            shrinkResources true
            zipAlignEnabled true
            debuggable true
            //...
        }
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67

BuildType官方文檔


  • compileOptions{}
compileOptions{}對應的是CompileOptions


CompileOptions的屬性:
1.encoding:Java源文件的編碼格式
2.incremental:是否應該使用Java編寫的Gradle新的增量模型
3.sourceCompatibility:指定編譯編譯.java文件的jdk版本
4.targetCompatibility:確保class文件與targetCompatibility指定版本,或者更新的java虛擬機兼容


不太常用
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

  • dataBinding{}
dataBinding{}對應的是DataBindingOptions


DataBindingOptions的屬性:

1.addDefualtAdapters:是否添加一個默認的data binding適配器。默認true。
2.enabled:是否使用data binding
3.version:data binding使用版本


dataBinding的使用:

dataBinding{
    enabled true
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

關於DataBinding的詳細用法


  • defualtConfig{}
defaultConfig{}是所有flavor都共有的配置。

英文解釋:The default configuration, inherited by all product flavors (if any are defined).


defaultConfig的使用:

 defaultConfig {
        applicationId "com.example.zhang.demo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

如果項目中包含多個Module,可以將共有的minSdkVersion和targetSdkVersion抽取到Project中的build.gradle文件中。具體細節下一章節。


  • dexOptions{}
dexOptions{}對應的是DexOptions

DexOptions屬性:

1.additionalParameters:給dx添加一系列附加的參數
2.javaMaxHeapSize:當調用dx時指定-Xmx值。
3.jumboMode:使用jumbo(龐大的)模式
4.keepRuntimeAnnotatedClasses:保持所有類中的運行時的註解在主Dex中。
5.maxProcessCount:可以使用Dex的最大併發進程數。默認爲46.optimize:運行在dx編譯器是否有optimize標記。
7.preDexLibraries:是否預先dex庫,它可以改善增量的生成,但是在clear build可能會變慢
8.threadCount:當dx運行時使用的線程的數量。默認4個。


dexOptions{}的用法:

dexOptions {
    preDexLibraries  false
    javaMaxHeapSize "4g"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

  • externalNativeBuild{}
externalNativeBuild{}對應的是ExternalNativeBuild

ExternalNativeBuild的屬性:

1.cmake:CMake工具編譯選項。
2.ndkBuild:ndk-build選項。


在externalNativeBuild{}中有2個模塊,cmake{}和ndkBuild{}模塊

------------------------------------------------
cmake{}對應的是CmakeOptions

CmakeOption的屬性:
1.path:你的CmakeLists.txt編譯腳本的相對路徑。

--------------------------------------------------
ndkBuild{}對應的是NdkBuildOptions

NdkBuildOptions的屬性:
1.path:你的Android.mk文件的相對路徑。

--------------------------------------------------


externalNativeBuild{}的用法:

externalNativeBuild{
    ndkBuild{
        path file("src\\main\\jni\\Android.mk")
    }

    cmake {
        path "src/main/cpp/CMakeLists.txt"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

Android Studio2.2 配置NDK

Android studio 2.2 使用cmake編譯NDK


  • jacoco{}
jacoco{}對應於JacocoOptions

JacocoOptions的屬性:
1.version:過時

英文原文:
note: this property is deprecated and will be removed in a future version of the plugin.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

  • lintOptions{}
lintOptions{}對應於LintOptions


LintOptions的屬性:
1.abortOnError:如果發現錯誤,lint工具是否應該退出這個程序。true表示退出。
2.absolutePaths:是否在輸出錯誤的時候,lint應該展示出全路徑。默認是相對路徑,也就是默認false3.check:精確的檢查(蒐集)問題的集合,默認情況下,任何問題都可以通過LintOptions.getEnable()啓用,沒有問題可以通過LintOptions.getDisable()使之無效。
4.checkAllWarnings:是否檢查所有警告,包括那些默認關閉。
5.disable:通過id's來壓制這個問題,允許修改
6.enable:通過id's來處理這個問題,循序修改,他會將添加id,並返回一個集合。
7.explainIssues:返回lint是否包含錯誤問題的解釋(注意:HTML和XML報告會無條件的去做,忽略這個設置)。
8.htmlOutput:html輸出方式。
9.htmlReport:我們應該是否寫一個HTML報告,默認true, 這個使用場景由LintOptions.getHtmlOutput()控制。
10.ignoreWarings:lint僅僅檢查錯誤,忽略警告。
11.lintConfig:默認配置文件作爲備份。
12.noLines:lint在輸出錯誤日誌的時候,是否包含行數。默認true13.quiet:lint是否應該quiet(安靜)。如:報告文件寫入路徑,不寫消息。
14.severityOverrides:An optional map of severity overrides. The map maps from issue id's to the corresponding severity to use, which must be "fatal", "error", "warning", or "ignore".
15.showAll:lint是否包含所有的輸出。
16.textOutput:文本輸出方式。
17.textReport:是否是文本報告寫入,默認false18.warningAsErrors:lint是否把警告當做錯誤來處理。
19.xmlOutput:XML輸出方式。
20.xmlReport:XML格式寫入報告,默認true------------------------------------------------

LintOptions的方法:

1.check(id):檢查這個id的問題的集合
2.check(ids):
3.disable(id):將id添加到不用啓動的問題集
4.disable(ids):
5.enable(id):將id添加到啓動的問題集
6.enable(ids)
7.error(id):將id添加到錯誤的問題集
8.error(ids)
9.fatal(id):將id添加到fatal級別的問題集
10.fatal(ids)
11.ignore(id):將id添加到ignore級別的問題集
12.ignore(ids)
13.waring(id):將id添加到waring級別的問題集
14.waring(ids)

------------------------------------------------

lintOptions{}的一般用法:

lintOptions {
    abortOnError false
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

LintOptions官方文檔


  • packagingOptions{}
packagingOptions{}對應的是PackagingOptions

Packaging options有三組路徑:first-picks,merges和excludes:


packagingOptions{}的用法:

packagingOptions {
    pickFirsts = [] // Not really needed because the default is empty.
    merges = []     // Not really needed because the default is empty.
    excludes = []
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

PackagingOptions官方文檔


  • productFlavors{}
 manifestPlaceholders:設置打包渠道)productFlavors.all {    //平臺id    flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849501234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950" data-snippet-id="ext.b1a48a92cb402df9f2399a3f023caa45" data-snippet-saved="false" data-codota-status="done" style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 14px; white-space: nowrap; padding: 5px 5px 5px 60px; margin-top: 0px; margin-bottom: 1.1em; line-height: 1.45; color: rgb(51, 51, 51); word-break: break-all; word-wrap: break-word; background-color: rgba(128, 128, 128, 0.047); border: 0px solid rgb(136, 136, 136); border-radius: 0px; position: relative; overflow-y: hidden; overflow-x: auto;">productFlavors{}對應的是ProductFlavors

ProductFlavors的屬性:

1.applicationId:應用程序ID。
2.applicationIdSuffix:應用程序ID後綴。
3.consumerProguardFiles:混淆規則文件被包含在aar包中。
4.dimension:flavor名稱的尺寸。
5.externalNativeBuild:詳情見externalNativeBuild{}
6.flavorDeminsion:過時
7.generatedDensities:過時
8.jackOption:jack配置可選項。
9.javaCompileOptions:Java編譯配置參數
10.manifestPlaceholders:manifest佔位符
11.multiDexEnabled:是否進行dex拆分
12.multiDexKeepFile:文本文件編譯進主dex文件中。
13.multiDexKeepProgroud:文本文件作爲混淆規則編譯進主dex文件中
14.ndk:ndk配置
15.proguardFiles:混淆文件
16.signingConfig:這個flavor的簽名配置信息
17.testApplicationId:測試應用ID
18.testFunctionalTest:
19.testHandleProfiling:
20.testInstrumentationRunner:
21.testInstrumentionRunnerArguments:
22.useJack:過時
23.verctorDrawables:生成矢量圖支持
24.versionCode:版本號
25.versionName:版本名
26.versionNameSuffix:版本名後綴
27.wearAppUnbundled:是否對嵌入式穿戴app進行拆分模式。如果true,那麼這個app將在應用市場被分發爲穿戴設備的app。



productFlavor{}的用法:

productFlavors {

        googlePlay {
        }

        xiaomi {
        }
}
//所有打包配置(批量處理打包渠道--> manifestPlaceholders:設置打包渠道)
productFlavors.all {
    //平臺id
    flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

ProductFlavor官方文檔


  • signingConfig{}
signingConfig{}對應的是SigningConfig

SigningConfig的屬性:

1.keyAlias:簽名使用key的別名
2.KeyPassword:簽名使用的key的密碼
3.storeFile:store簽名文件
4.storePassword:store簽名密碼
5.storeType:store簽名類型
6.v1SigningEnabled:是否使用jar簽名(又名v1簽名)。
7.v2SigningEnabled:是否使用apk簽名(又名v2簽名)。


signingConfig{}的用法:

signingConfigs {
    config {
        keyAlias '...'
        keyPassword '...'
        storeFile file('C:/../Key.jks')
        storePassword '...'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

  • sourceSets{}
sourceSets{}對應的AndroidSourceSet

AndroidSourceSet的屬性:

1.aidl:aidl目錄
2.assets:assets目錄
3.compileConfiguraName:編譯配置資源目錄。
4.java:java代碼目錄(需要編譯成.class文件)
5.jni:jni資源目錄
6.jniLibs:jni庫目錄
7.manifest:AndroidManifest.xml資源文件
8.name:source set名稱。
9.packageConfigurationName:運行時配置的資源集。
10.providedConfigurationName:僅僅編譯時配置的資源集。
11.renderscript:RenderScript腳本資源目錄
12.res:Android資源目錄
13.resource:java資源被複制到輸出到javaresource目錄


AndroidSourceSet的方法:
1.setRoot(path):資源集的根目錄,所有的資源都在這個跟目錄下。


sourceSets{}的使用:

sourceSets {
    //在main目錄中
    main {
        //assets目錄設置
        assets.srcDirs = ['assets']
        //jni目錄設置
        jni.srcDirs 'src/main/jni'
        //jni庫設置
        jniLibs.srcDir 'src/main/jniLibs'
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

  • splits{}
splits{}對應的是Splites

Splits的屬性:

1.abi:ABI設置
2.abiFilters:用於多個apk的ABI篩選列表
3.density:密度設置
4.densityFilters:用於多個apk的密度篩選列表
5.language:語言設置。
6.languageFilters:用於多個apk的語言篩選列表

-----------------------------------------------------


Spiltes對應有三個模塊,abi{},density{},language{}


abi{}對應的是AbiSplitOptions

AbiSplitsOptions的屬性:
1.applicableFilters:返回此範圍的所有適用篩選器的列表。
2.enable:是否在這個範圍分裂
3.universalApk:是否創建所有可用的ABIs一個APK。


AbiSplitesOptions的方法:
1.exclude(excludes):排除一些值。
2.include(include):包含一些值。
3.reset():重新設置split配置。

----------------------------------------------------------

density{}對應的是DensitySplitOptions

DensitySplitOptions的屬性:
1.applicableFilters:返回此範圍的所有適用篩選器的列表。
2.auto:編譯系統是否確定分割“language-*”文件夾中的資源。
3.compatibleScreen:兼容屏幕列表
4.enable:是否拆分


DensitySplitOptions的方法:
1.exclude(exclude):排除一些值
2.include(include):包含一些值
3.reset():重新設置split配置。


-------------------------------------------------------

language{}對應的是LanguageSplitOptions

LanguageSplitOptions的屬性:
1.enable:如果true,就是拆分language


LanguageSplitOptions的方法:
1.include(include):包含一個模型。


---------------------------------------------------------

splits{}的用法:

splits {
    density {
        enable true
        exclude 'ldpi', 'mdpi'
        compatibleScreens 'normal', 'large', 'xlarge'
    }
} 

生成結果:
app-hdpi-release.apk
app-universal-release.apk
app-xhdpi-release.apk
app-xxhdpi-release.apk
app-xxxhdpi-release.apk

splits {
    abi {
      enable true
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk true
    }
}

這個就是生成不同手機架構的app
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89

APK-splite官方文檔

Splite官方文檔

參考文章


  • testOptions{}
testOptions{}對應的是TestOptions

TestOptions的屬性:
1.reportDir:報告目錄
2.resultDir:結果目錄
3.unitTests:單元測試配置參數

TestOptions包含unitTests{}

-------------------------------------------------------

unitTests{}對應的是UnitTestOptions

UnitTestOptions的屬性:
1.returnDefaultValues:無論unmocked方法從android.jar中拋出異常或是默認值(0或null)。


UnitTestOtions的方法:
all(configClosure):配置所有單元測試任務。

-------------------------------------------------

testOptions{}的使用:

testOptions {
    resultsDir = "$project.buildDir/foo/results"
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

參考文檔


AppExtension文檔

Gradle翻譯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章