Gradle for Android (簡體中文版)

凱文·貝利格裡姆斯 (Kevin Pelgrims)

已絕版

買這商品的人也買了...

相關主題

商品描述

<內容簡介>

Gradle是Android 開發小組於2013年推出的作為Android 應用的首選的構建系統。Gradle可以很容易地擴展構建,並插入到現有的構建過程中來。它提供了一套類Groovy 的DSL 語言,用於申明構建和創建任務,讓依賴管理變得更加簡單。此外,它是完全免費和開源的。本書共分9章,依次介紹了Gradle的基礎知識、基本自定義構建、依賴管理、創建構建Variants、管理多模塊構建、運行測試、創建tasks和插件、設置持續集成,以及高級自定義構建。

<章節目錄>
1 Gradle和Android Studio入門........................................... .................................................. 1
1.1 Android Studio .............................................. .................................................. .......................1
1.2理解Gradle基礎...................... .................................................. .............................................3
1.2.1項目和任務................................................ .................................................. ..............3
1.2.2構建生命週期............................. .................................................. .............................4
1.2.3構建配置文件.............. .................................................. ............................................4
1.2.4項目結構.................................................. .................................................. ................5
1.3創建新項目............................. .................................................. .............................................6
1.4 Gradle Wrapper入門.................................................. .................................................. ........10
1.4.1獲取Gradle Wrapper ................................... .................................................. ..........10
1.4.2運行基本構建任務................................ .................................................. ................12
1.5遷移出Eclipse ............................. .................................................. .......................................13
1.5.1導入嚮導..... .................................................. .................................................. .........13
1.5.2手動遷移................................... .................................................. .............................15
1.6總結.................. .................................................. .................................................. ................17
2基本自定義構建............................ .................................................. ................................. 19
2.1理解Gradle文件............ .................................................. .................................................. ...19
2.1.1 settings文件......................................... .................................................. .................20
Gradle for Android中文版
【XII】
2.1.2頂層構建文件.................. .................................................. ......................................20
2.1.3模塊的構建文件.... .................................................. ................................................21
2.2任務入門................................................ .................................................. ............................23
2.2.1基礎任務................ .................................................. ................................................24
2.2 .2 Android任務.............................................. .................................................. ...........24
2.2.3 Android Studio ................................. .................................................. ......................25
2.3自定義構建....................... .................................................. .................................................27
2.3.1操控manifest條目............................................ .................................................. ....28
2.3.2 BuildConfig和資源....................................... .................................................. ........29
2.3.3項目範圍的設置.................................. .................................................. ..................30
2.3.4項目屬性.......................... .................................................. ......................................30
2.3.5默認的任務..... .................................................. .................................................. .....32
2.4總結.......................................... .................................................. ..........................................32
3依賴管理.... .................................................. .................................................. .................. 33
3.1依賴倉庫............................ .................................................. ................................................33
3.1 .1預定義依賴倉庫............................................ .................................................. ........34
3.1.2遠程倉庫.................................... .................................................. ............................35
3.1.3本地倉庫................ .................................................. ................................................36
3.2本地依賴................................................ .................................................. ............................37
3.2.1文件依賴................ .................................................. ................................................37
3.2 .2原生依賴庫............................................. .................................................. ...............37
3.2.3依賴項目............................. .................................................. ...................................38
3.3依賴概念........... .................................................. .................................................. ...............39
3.3.1配置.............................. .................................................. ..........................................39
3.3.2語義化版本. .................................................. .................................................. .........40
3.3.3動態化版本.................................. .................................................. ..........................40
3.4 Android Studio .................... .................................................. ...............................................41
3.5總結.................................................. .................................................. ..................................43
目錄
【XIII】
4創建構建Variant ....... .................................................. .................................................. ... 44
4.1構建類型........................................... .................................................. .................................45
4.1.1創建構建類型.......... .................................................. ..............................................45
4.1.2源集................................................ .................................................. ........................47
4.1.3依賴..................... .................................................. .................................................. .49
4.2 product flavor ............................................. .................................................. ........................49
4.2.1創建product flavor ................... .................................................. .............................49
4.2.2源集............... .................................................. .................................................. .......50
4.2.3多種定製的版本.................................. .................................................. ..................50
4.3構建variant ............................ .................................................. ............................................51
4.3.1任務. .................................................. .................................................. .....................52
4.3.2源集....................... .................................................. .................................................52
4.3.3源集合併資源和manifest ......................................... ..............................................52
4.3.4創建構建variant ............................................... .................................................. ....53
4.3.5 variant過濾器....................................... .................................................. ................55
4.4簽名配置.............................. .................................................. ..............................................56
4.5總結. .................................................. .................................................. .................................58
5管理多模塊構建........... .................................................. .................................................. 59
5.1解剖多模塊構建............................................ .................................................. ....................59
5.1.1重訪構建生命週期..................... .................................................. ...........................61
5.1.2模塊任務................. .................................................. ...............................................62
5.2將模塊添加到項目.............................................. .................................................. ..............62
5.2.1添加一個Java依賴庫........................... .................................................. ...............63
5.2.2添加一個Android依賴庫.......................... .................................................. ..........64
5.2.3融合Android Wear ................................. .................................................. ...............64
5.2.4使用Google App Engine ........................... .................................................. ............65
5.3提示和最佳實踐............................... .................................................. .................................69
5.3.1在Android Studio中運行模塊任務...... .................................................. ...............69
5.3.2加速多模塊構建........................... .................................................. .........................70
Gradle for Android中文版
【XIV】
5.3.3模塊耦合........... .................................................. .................................................. ...70
5.4總結............................................ .................................................. ........................................71
6運行測試...... .................................................. .................................................. ................ 72
6.1單元測試.............................. .................................................. ..............................................72
6.1.1 JUnit ................................................. .................................................. ......................72
6.1.2 Robolectric ....................... .................................................. ......................................76
6.2功能測試........ .................................................. .................................................. ..................77
6.3測試覆蓋率........................... .................................................. .............................................81
6.4總結.. .................................................. .................................................. ................................82
7創建任務和插件............ .................................................. ................................................. 83
7.1理解Groovy ............................................... .................................................. ........................83
7.1.1簡介..................... .................................................. .................................................. .84
7.1.2類和成員變量......................................... .................................................. ...............85
7.1.3方法.............................. .................................................. ..........................................85
7.1.4 Closures... .................................................. .................................................. .............86
7.1.5集合................................ .................................................. ........................................87
7.1.6 Gradle中的Groovy .. .................................................. ............................................88
7.2任務入門.. .................................................. .................................................. ........................89
7.2.1定義任務.................... .................................................. ............................................89
7.2.2任務剖析.................................................. .................................................. ..............91
7.2.3使用任務來簡化release過程.......................... .................................................. ....94
7.3 Hook到Android插件........................................ .................................................. .................97
7.3.1自動重命名APK......................... .................................................. ..........................97
7.3.2動態創建新的任務............... .................................................. .................................98
7.4創建自己的插件........... .................................................. .................................................. .100
7.4.1創建一個簡單的插件........................................ .................................................. ..100
7.4.2分發插件.......................................... .................................................. ....................101
目錄
【XV】
7.4.3使用自定義插件.................. .................................................. ................................103
7.5總結............... .................................................. .................................................. .................104
8設置持續集成............................ .................................................. .................................. 105
8.1 Jenkins ............. .................................................. .................................................. ...............105
8.1.1設置Jenkins............................. .................................................. ............................106
8.1.2配置構建................ .................................................. ..............................................107
8.2 TeamCity . .................................................. .................................................. .......................109
8.2.1設置TeamCity ..................... .................................................. ................................110
8.2.2配置構建............ .................................................. .................................................. 110
8.3 Travis CI.............................................. .................................................. ............................. 111
8.4自動化進階................ .................................................. .................................................. ....113
8.4.1 SDK mananger插件....................................... .................................................. .....114
8.4.2運行測試....................................... .................................................. .......................114
8.4.3持續部署..................... .................................................. .........................................115
8.4.4 Beta分發包.. .................................................. .................................................. .....116
8.5總結.......................................... .................................................. ........................................117
9高級自定義構建.... .................................................. .................................................. ......118
9.1減少APK文件大小...................................... .................................................. ....................118
9.1.1 ProGuard ......................... .................................................. .....................................119
9.1.2縮減資源....... .................................................. .................................................. .....120
9.2加速構建......................................... .................................................. .................................121
9.2.1 Gradle參數........... .................................................. ...............................................122
9.2. 2 Android Studio ............................................... .................................................. ......123
9.2.3 Profiling....................................... .................................................. .........................124
9.2.4 Jack和Jill.................. .................................................. ..........................................125
9.3忽略Lint .... .................................................. .................................................. .....................126
9.4在Gradle中使用Ant ...................... .................................................. ...................................126
9.4.1在Gradle中運行Ant任務..... .................................................. ............................126
Gradle for Android中文版
【XVI】
9.4.2導入整個Ant腳本...... .................................................. ........................................127
9.4.3屬性..... .................................................. .................................................. ...............129
9.5高級應用部署.............................. .................................................. ....................................129
9.6總結........... .................................................. .................................................. .....................131