├── .gitignore ├── README.md ├── SUMMARY.md ├── advanced_build_customization ├── README.md ├── aapt_optionsaapt.md ├── article.md ├── build_options.md ├── buildtype_and_product_flavor_property_referencebuildtypeproduct_flavor.md ├── java_compilation_optionsjava.md ├── manipulation_taskstask.md └── using_sourcecompatibility_17jdk17sourcecompatibility.md ├── basic_project ├── README.md ├── android_tasks.md ├── basic_build_customization.md ├── build_tasks.md ├── build_types.md ├── configuring_the_structure.md ├── general_tasks.md ├── java_project_tasksjavatask.md ├── manifest_entries_manifest.md ├── project_structure.md ├── running_proguard_proguard.md ├── signing_configurations.md └── simple_build_files.md ├── book.json ├── build_variants ├── README.md ├── build_type__+_product_flavor_=_build_variant+=.md ├── building_and_tasks.md ├── multi-flavor_variants.md ├── product_flavor_configurationproduct_flavor.md ├── product_flavors.md ├── sourcesets_and_dependencies.md └── testing.md ├── cover.jpg ├── cover_small.png ├── dependenciesandroid_libraries_and_multi-project_setupandroid ├── README.md ├── creating_a_library_project.md ├── dependencies_on_binary_packages.md ├── differences_between_a_project_and_a_library_project.md ├── library_projects.md ├── library_publication.md ├── local_packages.md ├── multi_project_setup.md ├── referencing_a_library.md └── remote_artifacts.md ├── introduction ├── README.md ├── goals_of_the_new_build_systemgradle.md └── why_gradlegradle.md ├── node_modules ├── gitbook-plugin-disqus │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── book │ │ └── plugin.js │ ├── index.js │ └── package.json └── gitbook-plugin-ga │ ├── .npmignore │ ├── LICENSE │ ├── README.md │ ├── book │ └── plugin.js │ ├── index.js │ └── package.json ├── requirements └── README.md └── testing ├── README.md ├── basics_and_configuration.md ├── lint_supportlint.md ├── multi-projects_reports.md ├── running_tests.md ├── single_projects.md ├── test_reports.md └── testing_android_librariesandroid.md /.gitignore: -------------------------------------------------------------------------------- 1 | /_book -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Gradle Android插件用户指南翻译 2 | --- 3 | 4 | Gradle Plugin User Guide 官方原文地址 5 | http://tools.android.com/tech-docs/new-build-system/user-guide 6 | 7 | 中文版在线阅读地址 8 | http://avatarqing.github.io/Gradle-Plugin-User-Guide-Chinese-Verision 9 | 10 | GitHub地址 11 | https://github.com/AvatarQing/Gradle-Plugin-User-Guide-Chinese-Verision 12 | 13 | 本指南的翻译内容均出自于CSDN的__琴弦第七__,本人只是对其做出微小修正,对照了英文原文归纳整理成markdown格式的文本并生成gitbook,方便大家阅读学习。[翻译原文地址点此打开](http://blog.csdn.net/qinxiandiqi/article/category/2394347)。 14 | 15 | --- 16 | 17 | __琴弦第七__ 18 | 19 | google推出了全新的Android Studio集成开发环境,其中Android项目的结构与Eclipse的Android项目结构有很大的区别,原因就在于两开发环境使用的构建工具不同。 20 | 21 | Android Studio使用Gradle构建工具,Eclipse的ADT插件使用的是Ant构建工具。因为两个构建工具的区别,导致习惯了Eclipse开发环境的开发者刚开始比较难适应Android Studio。如果要迁移到Android Studio,建议最好了解下Gradle构建工具。Gradle构建工具是任务驱动型的构建工具,并且可以通过各种Plugin插件扩展功能以适应各种构建任务。对应Android项目的Gradle插件就是Android Gradle Plugin。本文是Google官方的Android Gradle Plugin使用指南翻译,以方便我大天朝开发者学习。如英语水平还不错的同学,建议直接查看官方原文,本人的理解和翻译难免有所疏漏。 22 | 23 | --- 24 | 25 | License 26 | 27 | 采用[知识共享 署名-非商业性使用-相同方式共享 4.0 国际 许可协议](http://creativecommons.org/licenses/by-nc-sa/4.0/)进行许可。 28 | 29 | 30 | [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/AvatarQing/gradle-plugin-user-guide-chinese-verision/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 31 | 32 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [译者序](README.md) 4 | * [Introduction(简介)](introduction/README.md) 5 | * [Goals of the new Build System(gradle构建系统的目标)](introduction/goals_of_the_new_build_systemgradle.md) 6 | * [Why Gradle?(为什么使用gradle)](introduction/why_gradlegradle.md) 7 | * [Requirements(要求)](requirements/README.md) 8 | * [Basic Project(基本项目)](basic_project/README.md) 9 | * [Simple build files(简单的构建文件)](basic_project/simple_build_files.md) 10 | * [Project Structure(项目结构)](basic_project/project_structure.md) 11 | * [Configuring the Structure](basic_project/configuring_the_structure.md) 12 | * [Build Tasks(构建任务)](basic_project/build_tasks.md) 13 | * [General Tasks(通用任务)](basic_project/general_tasks.md) 14 | * [Java project tasks(Java项目的Task)](basic_project/java_project_tasksjavatask.md) 15 | * [Android tasks](basic_project/android_tasks.md) 16 | * [Basic Build Customization(基本的构建定制)](basic_project/basic_build_customization.md) 17 | * [Manifest entries (Manifest属性)](basic_project/manifest_entries_manifest.md) 18 | * [Build Types(构建类型)](basic_project/build_types.md) 19 | * [signing configurations(签名配置)](basic_project/signing_configurations.md) 20 | * [Running Proguard(运行 Proguard)](basic_project/running_proguard_proguard.md) 21 | * [Dependencies,Android Libraries and Multi-project setup(依赖关系,Android库和多项目设置)](dependenciesandroid_libraries_and_multi-project_setupandroid/README.md) 22 | * [Dependencies on binary packages(依赖二进制包)](dependenciesandroid_libraries_and_multi-project_setupandroid/dependencies_on_binary_packages.md) 23 | * [Local packages(本地包)](dependenciesandroid_libraries_and_multi-project_setupandroid/local_packages.md) 24 | * [Remote artifacts(远程文件)](dependenciesandroid_libraries_and_multi-project_setupandroid/remote_artifacts.md) 25 | * [Multi project setup(多项目设置)](dependenciesandroid_libraries_and_multi-project_setupandroid/multi_project_setup.md) 26 | * [Library projects(库项目)](dependenciesandroid_libraries_and_multi-project_setupandroid/library_projects.md) 27 | * [Creating a Library Project(创建一个库项目)](dependenciesandroid_libraries_and_multi-project_setupandroid/creating_a_library_project.md) 28 | * [Differences between a Project and a Library Project(普通项目和库项目之间的区别)](dependenciesandroid_libraries_and_multi-project_setupandroid/differences_between_a_project_and_a_library_project.md) 29 | * [Referencing a Library(引用一个库项目)](dependenciesandroid_libraries_and_multi-project_setupandroid/referencing_a_library.md) 30 | * [Library Publication(库项目发布)](dependenciesandroid_libraries_and_multi-project_setupandroid/library_publication.md) 31 | * [Testing(测试)](testing/README.md) 32 | * [Basics and Configuration(基本知识和配置)](testing/basics_and_configuration.md) 33 | * [Running tests(运行测试)](testing/running_tests.md) 34 | * [Testing Android Libraries(测试Android库)](testing/testing_android_librariesandroid.md) 35 | * [Test reports(测试报告)](testing/test_reports.md) 36 | * [Single projects(独立项目)](testing/single_projects.md) 37 | * [Multi-projects reports(多项目报告)](testing/multi-projects_reports.md) 38 | * [Lint support(Lint支持)](testing/lint_supportlint.md) 39 | * [Build Variants(构建变种版本)](build_variants/README.md) 40 | * [Product flavors(不同定制的产品)](build_variants/product_flavors.md) 41 | * [Build Type + Product Flavor = Build Variant(构建类型+定制产品=构建变种版本)](build_variants/build_type__+_product_flavor_=_build_variant+=.md) 42 | * [Product Flavor Configuration(Product Flavor的配置)](build_variants/product_flavor_configurationproduct_flavor.md) 43 | * [Sourcesets and Dependencies(源组件和依赖关系)](build_variants/sourcesets_and_dependencies.md) 44 | * [Building and Tasks(构建和任务)](build_variants/building_and_tasks.md) 45 | * [Testing(测试)](build_variants/testing.md) 46 | * [Multi-flavor variants](build_variants/multi-flavor_variants.md) 47 | * [Advanced Build Customization(高级构建定制)](advanced_build_customization/README.md) 48 | * [Build options(构建选项)](advanced_build_customization/build_options.md) 49 | * [Java Compilation options(Java编译选项)](advanced_build_customization/java_compilation_optionsjava.md) 50 | * [aapt options(aapt选项)](advanced_build_customization/aapt_optionsaapt.md) 51 | * [dex options(dex选项)](advanced_build_customization/article.md) 52 | * [Manipulation tasks(操作task)](advanced_build_customization/manipulation_taskstask.md) 53 | * [BuildType and Product Flavor property reference(BuildType和Product Flavor属性参考)](advanced_build_customization/buildtype_and_product_flavor_property_referencebuildtypeproduct_flavor.md) 54 | * [Using sourceCompatibility 1.7(使用(JDK)1.7版本的sourceCompatibility)](advanced_build_customization/using_sourcecompatibility_17jdk17sourcecompatibility.md) 55 | 56 | -------------------------------------------------------------------------------- /advanced_build_customization/README.md: -------------------------------------------------------------------------------- 1 | # Advanced Build Customization(高级构建定制) 2 | -------------------------------------------------------------------------------- /advanced_build_customization/aapt_optionsaapt.md: -------------------------------------------------------------------------------- 1 | # aapt options(aapt选项) 2 | 3 | android { 4 | aaptOptions { 5 | noCompress 'foo', 'bar' 6 | ignoreAssetsPattern "!.svn:!.git:!.ds_store:!*.scc:.*:_*:!CVS:!thumbs.db:!picasa.ini:!*~" 7 | } 8 | } 9 | 10 | 这将影响所有使用aapt的task。 11 | -------------------------------------------------------------------------------- /advanced_build_customization/article.md: -------------------------------------------------------------------------------- 1 | # dex options(dex选项) 2 | 3 | android { 4 | dexOptions { 5 | incremental false 6 | 7 | preDexLibraries = false 8 | 9 | jumboMode = false 10 | 11 | } 12 | } 13 | 14 | 这将应用所有使用dex的task。 15 | -------------------------------------------------------------------------------- /advanced_build_customization/build_options.md: -------------------------------------------------------------------------------- 1 | # Build options(构建选项) 2 | -------------------------------------------------------------------------------- /advanced_build_customization/buildtype_and_product_flavor_property_referencebuildtypeproduct_flavor.md: -------------------------------------------------------------------------------- 1 | # BuildType and Product Flavor property reference(BuildType和Product Flavor属性参考) 2 | 3 | coming soon。。。。= = 4 | 对于Gradle的task(DefaultTask,JavaCompile,Copy,Zip),请参考Gradle文档。 5 | -------------------------------------------------------------------------------- /advanced_build_customization/java_compilation_optionsjava.md: -------------------------------------------------------------------------------- 1 | # Java Compilation options(Java编译选项) 2 | 3 | android { 4 | compileOptions { 5 | sourceCompatibility = "1.6" 6 | targetCompatibility = "1.6" 7 | } 8 | } 9 | 10 | 默认值是“1.6”。这个设置将影响所有task编译Java源代码。 11 | -------------------------------------------------------------------------------- /advanced_build_customization/manipulation_taskstask.md: -------------------------------------------------------------------------------- 1 | # Manipulation tasks(操作task) 2 | 3 | 基础Java项目有一组有限的task用于互相处理生成一个输出。 4 | `classes`是一个编译Java源代码的task。可以在build.gradle文件中通过脚本很容易使用`classes`。这是`project.tasks.classes`的缩写。 5 | 6 | 在Android项目中,相比之下这就有点复杂。因为Android项目中会有大量相同的task,并且它们的名字基于_Build Types_和_Product Flavor_生成。 7 | 8 | 为了解决这个问题,`android`对象有两个属性: 9 | 10 | * `applicationVariants`(只适用于app plugin) 11 | * `libraryVariants`(只适用于library plugin) 12 | * `testVariants`(两个plugin都适用) 13 | 14 | 这三个都会分别返回一个ApplicationVariant、LibraryVariant和TestVariant对象的[DomainObjectCollection](http://www.gradle.org/docs/current/javadoc/org/gradle/api/DomainObjectCollection.html 15 | )。 16 | 17 | 注意使用这三个collection中的其中一个都会触发生成所有对应的task。这意味着使用collection之后不需要更改配置。 18 | 19 | DomainObjectCollection可以直接访问所有对象,或者通过过滤器进行筛选。 20 | 21 | android.applicationVariants.each { variant -> 22 | .... 23 | } 24 | 25 | 这三个variant类都共享下面的属性: 26 | 27 | 属性名 |属性类型 |说明 28 | ------------- |:-------------:| -----: 29 | name |String |Variant的名字,必须是唯一的。 30 | description |String |Variant的描述说明。 31 | dirName |String|Variant的子文件夹名,必须也是唯一的。可能也会有不止一个子文件夹,例如“debug/flavor1” 32 | baseName |String |Variant输出的基础名字,必须唯一。 33 | outputFile |File |Variant的输出,这是一个可读可写的属性。 34 | processManifest |ProcessManifest |处理Manifest的task。 35 | aidlCompile |AidlCompile |编译AIDL文件的task。 36 | renderscriptCompile |RenderscriptCompile |编译Renderscript文件的task。 37 | mergeResources |MergeResources |混合资源文件的task。 38 | mergeAssets |MergeAssets |混合asset的task。 39 | processResources|ProcessAndroidResources |处理并编译资源文件的task。 40 | generateBuildConfig |GenerateBuildConfig |生成BuildConfig类的task。 41 | javaCompile |JavaCompile |编译Java源代码的task。 42 | processJavaResources|Copy |处理Java资源的task。 43 | assemble |DefaultTask |Variant的标志性assemble task。 44 | 45 | ApplicationVariant类还有以下附加属性: 46 | 47 | 属性名 |属性类型 |说明 48 | ------------- |:-------------:| -----: 49 | buildType |BuildType |Variant的BuildType。 50 | productFlavors |List |Variant的ProductFlavor。一般不为空但也允许空值。 51 | mergedFlavor |ProductFlavor |android.defaultConfig和variant.productFlavors的合并。 52 | signingConfig |SigningConfig |Variant使用的SigningConfig对象。 53 | isSigningReady |boolean |如果是true则表明这个Variant已经具备了所有需要签名的信息。 54 | testVariant |BuildVariant |将会测试这个Variant的TestVariant。 55 | dex |Dex |将代码打包成dex的task。如果这个Variant是个库,这个值可以为空。 56 | packageApplication |PackageApplication |打包最终APK的task。如果这个Variant是个库,这个值可以为空。 57 | zipAlign |ZipAlign |zip压缩APK的task。如果这个Variant是个库或者APK不能被签名,这个值可以为空。 58 | install |DefaultTask |负责安装的task,不能为空。 59 | uninstall |DefaultTask |负责卸载的task。 60 | 61 | LibraryVariant类还有以下附加属性: 62 | 63 | 属性名 |属性类型 |说明 64 | ------------- |:-------------:| -----: 65 | buildType |BuildType |Variant的BuildType. 66 | mergedFlavor |ProductFlavor |The defaultConfig values 67 | testVariant |BuildVariant |用于测试这个Variant。 68 | packageLibrary |Zip |用于打包库项目的AAR文件。如果是个库项目,这个值不能为空。 69 | 70 | TestVariant类还有以下属性: 71 | 72 | 属性名 |属性类型 |说明 73 | ------------- |:-------------:| -----: 74 | buildType |BuildType |Variant的Build Type。 75 | productFlavors |List |Variant的ProductFlavor。一般不为空但也允许空值。 76 | mergedFlavor |ProductFlavor |android.defaultConfig和variant.productFlavors的合并。 77 | signingConfig |SigningConfig |Variant使用的SigningConfig对象。 78 | isSigningReady |boolean |如果是true则表明这个Variant已经具备了所有需要签名的信息。 79 | testedVariant |BaseVariant |TestVariant测试的BaseVariant 80 | dex |Dex |将代码打包成dex的task。如果这个Variant是个库,这个值可以为空。 81 | packageApplication |PackageApplication |打包最终APK的task。如果这个Variant是个库,这个值可以为空。 82 | zipAlign |ZipAlign |zip压缩APK的task。如果这个Variant是个库或者APK不能被签名,这个值可以为空。 83 | install |DefaultTask |负责安装的task,不能为空。 84 | uninstall |DefaultTask |负责卸载的task。 85 | connectedAndroidTest |DefaultTask |在连接设备上行执行Android测试的task。 86 | providerAndroidTest |DefaultTask |使用扩展API执行Android测试的task。 87 | 88 | Android task特有类型的API: 89 | 90 | * ProcessManifest 91 | * File manifestOutputFile 92 | * AidlCompile 93 | * File sourceOutputDir 94 | * RenderscriptCompile 95 | * File sourceOutputDir 96 | * File resOutputDir 97 | * MergeResources 98 | * File outputDir 99 | * MergeAssets 100 | * File outputDir 101 | * ProcessAndroidResources 102 | * File manifestFile 103 | * File resDir 104 | * File assetsDir 105 | * File sourceOutputDir 106 | * File textSymbolOutputDir 107 | * File packageOutputFile 108 | * File proguardOutputFile 109 | * GenerateBuildConfig 110 | * File sourceOutputDir 111 | * Dex 112 | * File outputFolder 113 | * PackageApplication 114 | * File resourceFile 115 | * File dexFile 116 | * File javaResourceDir 117 | * File jniDir 118 | * File outputFile 119 | * 直接在Variant对象中使用“outputFile”可以改变最终的输出文件夹。 120 | * ZipAlign 121 | * File inputFile 122 | * File outputFile 123 | * 直接在Variant对象中使用“outputFile”可以改变最终的输出文件夹。 124 | 125 | 每个task类型的API由于Gradle的工作方式和Android plugin的配置方式而受到限制。 126 | 首先,Gradle意味着拥有的task只能配置输入输出的路径和一些可能使用的选项标识。因此,task只能定义一些输入或者输出。 127 | 128 | 其次,这里面大多数task的输入都不是单一的,一般都混合了_sourceSet_、_Build Type_和_Product Flavor_中的值。为了保持构建文件的简单和可读性,目标是要让开发者通过DSL语言修改这些对象来配饰构建的过程,而不是深入修改输入和task的选项。 129 | 130 | 另外需要注意,除了ZipAlign这个task类型,其它所有类型都要求设置私有数据来让它们运行。这意味着不可能自动创建这些类型的新task实例。 131 | 132 | 这些API也可能会被更改。一般来说,目前的API是围绕着给定task的输入和输出入口来添加额外的处理(如果需要的时候)。欢迎反馈意见,特别是那些没有预见过的需求。 133 | 134 | 对于Gradle的task(DefaultTask,JavaCompile,Copy,Zip),请参考Gradle文档。 135 | -------------------------------------------------------------------------------- /advanced_build_customization/using_sourcecompatibility_17jdk17sourcecompatibility.md: -------------------------------------------------------------------------------- 1 | # Using sourceCompatibility 1.7(使用(JDK)1.7版本的sourceCompatibility) 2 | 3 | 使用Android KitKat(19版本的buildTools)就可以使用diamond operator,multi-catch,switch中使用字符串,try with resource等等(译注:都是JDK7的一些新特性,详情请参考JDK7文档)。设置使用1.7版本,需要修改你的构建文件: 4 | 5 | android { 6 | compileSdkVersion 19 7 | buildToolsVersion "19.0.0" 8 | 9 | defaultConfig { 10 | minSdkVersion 7 11 | targetSdkVersion 19 12 | } 13 | 14 | compileOptions { 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | targetCompatibility JavaVersion.VERSION_1_7 17 | } 18 | } 19 | 20 | --- 21 | 22 | > 注意:你可以将`minSdkVersion`的值设置为19之前的版本,只是你只能使用除了try with resources之外的其它新语言特性。如果你想要使用try with resources特性,你就需要把`minSdkVersion`也设置为19。 23 | 24 | --- 25 | 26 | 你同样也需要确认Gradle使用1.7或者更高版本的JDK(Android Gradle plugin也需要0.6.1或者更高的版本)。 27 | -------------------------------------------------------------------------------- /basic_project/README.md: -------------------------------------------------------------------------------- 1 | # Basic Project(基本项目) 2 | 3 | 一个Gradle项目的构建过程定义在build.gradle文件中,位于项目的根目录下。 4 | -------------------------------------------------------------------------------- /basic_project/android_tasks.md: -------------------------------------------------------------------------------- 1 | # Android tasks 2 | 3 | Android plugin使用相同的约定以兼容其他插件,并且附加了自己的标识性task,包括: 4 | * `assemble` 5 | 这个task用于组合项目中的所有输出。 6 | * `check` 7 | 这个task用于执行所有检查。 8 | * `connectedCheck` 9 | 这个task将会在一个指定的设备或者模拟器上执行检查,它们可以同时在所有连接的设备上执行。 10 | * `deviceCheck` 11 | 通过APIs连接远程设备来执行检查,这是在CL服务器上使用的。 12 | * `build` 13 | 这个task执行assemble和check的所有工作。 14 | * `clean` 15 | 这个task清空项目的所有输出。 16 | 17 | 这些新的标识性task是必须的,以保证能够在没有设备连接的情况下执行定期检查。 18 | 注意`build` task不依赖于`deviceCheck`或者`connectedCheck`。 19 | 20 | 一个Android项目至少拥有两个输出:debug APK(调试版APK)和release APK(发布版APK)。每一个输出都拥有自己的标识性task以便能够单独构建它们。 21 | * `assemble` 22 | * `assembleDebug` 23 | * `assembleRelease` 24 | 25 | 它们都依赖于其它一些tasks以完成构建一个APK需要多个步骤。其中assemble task依赖于这两个task,所以执行`assemble`将会同时构建出两个APK。 26 | 27 | --- 28 | 29 | > 小提示:gradle在命令行终端上支持骆驼命名法的task简称,例如,执行 30 | 31 | > gradle aR 32 | 33 | > 命令等同于执行 34 | 35 | > gradle assembleRelease。 36 | 37 | --- 38 | 39 | check task也拥有自己的依赖: 40 | * `check` 41 | * `lint` 42 | * `connectedCheck` 43 | * `connectedAndroidTest` 44 | * `connectedUiAutomatorTest`(目前还没有应用到) 45 | * `deviceCheck` 46 | * 这个test依赖于test创建时,其它实现测试扩展点的插件。 47 | 48 | 最后,只要task能够被安装(那些要求签名的task),android plugin就会为所有构建类型(`debug`,`release`,`test`)安装或者卸载。 49 | -------------------------------------------------------------------------------- /basic_project/basic_build_customization.md: -------------------------------------------------------------------------------- 1 | # Basic Build Customization(基本的构建定制) 2 | 3 | Android plugin提供了大量DSL用于直接从构建系统定制大部分事情。 4 | -------------------------------------------------------------------------------- /basic_project/build_tasks.md: -------------------------------------------------------------------------------- 1 | # Build Tasks(构建任务) 2 | -------------------------------------------------------------------------------- /basic_project/build_types.md: -------------------------------------------------------------------------------- 1 | # Build Types(构建类型) 2 | 3 | 默认情况下,Android Plugin会自动给项目设置同时构建应用程序的debug和release版本。 4 | 两个版本之间的不同主要围绕着能否在一个安全设备上调试,以及APK如何签名。 5 | 6 | Debug版本采用使用通用的name/password键值对自动创建的数字证书进行签名,以防止构建过程中出现请求信息。Release版本在构建过程中没有签名,需要稍后再签名。 7 | 8 | 这些配置通过一个`BuildType`对象来配置。默认情况下,这两个实例都会被创建,分别是一个`debug`版本和一个`release`版本。 9 | 10 | Android plugin允许像创建其他构建类型一样定制`debug`和`release`实例。这需要在`buildTypes`的DSL容器中配置: 11 | 12 | android { 13 | buildTypes { 14 | debug { 15 | applicationIdSuffix ".debug" 16 | } 17 | 18 | jnidebug.initWith(buildTypes.debug) 19 | jnidebug { 20 | packageNameSuffix ".jnidebug" 21 | jnidebugBuild true 22 | } 23 | } 24 | } 25 | 26 | 以上代码片段实现了以下功能: 27 | 28 | * 配置默认的`debug`构建类型 29 | * 将debug版本的包名设置为.debug以便能够同时在一台设备上安装_debug_和_release_版本的apk。 30 | * 创建了一个名为`jnidebug`的新构建类型,并且这个构建类型是`debug`构建类型的一个副本。 31 | * 继续配置`jnidebug`构建类型,允许使用JNI组件,并且也添加了不一样的包名后缀。 32 | 33 | 创建一个新的构建类型就是简单的在`buildType`标签下添加一个新的元素,并且可以使用`initWith()`或者直接使用闭包来配置它。 34 | 35 | 以下是一些可能使用到的属性和默认值: 36 | 37 | Property name |Default values for debug |Default values for release / other 38 | ------------- |:-------------:| -----: 39 | `debuggable` |true |false 40 | `jniDebugBuild` |false |false 41 | `renderscriptDebugBuild` |false |false 42 | `renderscriptOptimLevel` |3 |3 43 | `applicationIdSuffix` |null |null 44 | `versionNameSuffix` |null |null 45 | `signingConfig` |android.signingConfigs.debug |null 46 | `zipAlign` |false |true 47 | `runProguard` |false |false 48 | `proguardFile` |N/A (set only) |N/A (set only) 49 | `proguardFiles` |N/A (set only) |N/A (set only) 50 | 51 | 除了以上属性之外,_Build Type_还会受项目源码和资源影响: 52 | 对于每一个Build Type都会自动创建一个匹配的_sourceSet_。默认的路径为: 53 | 54 | src// 55 | 56 | 这意味着_BuildType_名称不能是_main_或者_androidTest_(因为这两个是由plugin强制实现的),并且他们互相之间都必须是唯一的。 57 | 58 | 跟其他sourceSet设置一样,Build Type的source set路径可以重新被定向: 59 | 60 | android { 61 | sourceSets.jnidebug.setRoot('foo/jnidebug') 62 | } 63 | 64 | 另外,每一个_Build Type_都会创建一个新的assemble任务。 65 | 66 | `assembleDebug`和`assembleRelease`两个Task在上面已经提到过,这里要讲这两个Task从哪里被创建。当`debug`和`release`构建类型被预创建的时候,它们的tasks就会自动创建对应的这个两个Task。 67 | 68 | 上面提到的build.gradle代码片段中也会实现`assembleJnidebug` task,并且`assemble`会像依赖于`assembleDebug`和`assembleRelease`一样依赖于`assembleJnidebug`。 69 | 70 | 提示:你可以在终端下输入gradle aJ去运行`assembleJnidebug task`。 71 | 72 | 可能会使用到的情况: 73 | 74 | * release模式不需要,只有debug模式下才使用到的权限 75 | * 自定义的debug实现 76 | * 为debug模式使用不同的资源(例如当资源的值由绑定的证书决定) 77 | 78 | _BuildType_的代码和资源通过以下方式被使用: 79 | 80 | * manifest将被混合进app的manifest 81 | * 代码行为只是另一个资源文件夹 82 | * 资源将叠加到main的资源中,并替换已存在的资源。 83 | -------------------------------------------------------------------------------- /basic_project/configuring_the_structure.md: -------------------------------------------------------------------------------- 1 | # Configuring the Structure 2 | 3 | 当默认的项目结构不适用的时候,你可能需要去配置它。根据Gradle文档,重新为Java项目配置_sourceSets_可以使用以下方法: 4 | 5 | sourceSets { 6 | main { 7 | java { 8 | srcDir 'src/java' 9 | } 10 | resources { 11 | srcDir 'src/resources' 12 | } 13 | } 14 | } 15 | 16 | --- 17 | 18 | > 注意:`srcDir`将会被添加到指定的已存在的源文件夹中(这在Gradle文档中没有提到,但是实际上确实会这样执行)。 19 | 20 | --- 21 | 22 | 替换默认的源代码文件夹,你可能想要使用能够传入一个路径数组的`srcDirs`来替换单一的`srcDir`。以下是使用调用对象的另一种不同方法: 23 | 24 | sourceSets { 25 | main.java.srcDirs = ['src/java'] 26 | main.resources.srcDirs = ['src/resources'] 27 | } 28 | 29 | 想要获取更多信息,可以参考Gradle文档中关于[Java Pluign](http://gradle.org/docs/current/userguide/java_plugin.html)的部分。 30 | 31 | Android Plugin使用的是类似的语法。但是由于它使用的是自己的_sourceSets_,这些配置将会被添加在`android`对象中。 32 | 33 | 以下是一个示例,它使用了旧项目结构中的main源码,并且将`androidTest` _sourceSet_组件重新映射到_tests_文件夹。 34 | 35 | android { 36 | sourceSets { 37 | main { 38 | manifest.srcFile 'AndroidManifest.xml' 39 | java.srcDirs = ['src'] 40 | resources.srcDirs = ['src'] 41 | aidl.srcDirs = ['src'] 42 | renderscript.srcDirs = ['src'] 43 | res.srcDirs = ['res'] 44 | assets.srcDirs = ['assets'] 45 | } 46 | 47 | androidTest.setRoot('tests') 48 | } 49 | } 50 | 51 | --- 52 | 53 | > 注意:由于旧的项目结构将所有的源文件(java,aidl,renderscripthe和java资源文件)都放在同一个目录里面,所以我们需要将这些_sourceSet_组件重新映射到`src`目录下。 54 | 55 | --- 56 | 57 | > 注意:`setRoot()`方法将移动整个组件(包括它的子文件夹)到一个新的文件夹。示例中将会移动`src/androidTest/*`到`tests/*`下。 58 | 以上这些是Android特有的,如果配置在Java的_sourceSets_里面将不会有作用。 59 | 60 | --- 61 | 62 | 以上也是将旧构建系统项目迁移到新构建系统需要做的迁移工作。 63 | -------------------------------------------------------------------------------- /basic_project/general_tasks.md: -------------------------------------------------------------------------------- 1 | # General Tasks(通用任务) 2 | 3 | 添加一个插件到构建文件中将会自动创建一系列构建任务(build tasks)去执行(注:gradle属于任务驱动型构建工具,它的构建过程是基于Task的)。Java plugin和Android plugin都会创建以下task: 4 | 5 | * `assemble` 6 | 这个task将会组合项目的所有输出。 7 | 8 | * `check` 9 | 这个task将会执行所有检查。 10 | 11 | * `build` 12 | 这个task将会执行assemble和check两个task的所有工作 13 | 14 | * `clean` 15 | 这个task将会清空项目的输出。 16 | 17 | 实际上`assemble`,`check`,`build`这三个task不做任何事情。它们只是一个Task标志,用来告诉android plugin添加实际需要执行的task去完成这些工作。 18 | 19 | 这就允许你去调用相同的task,而不需要考虑当前是什么类型的项目,或者当前项目添加了什么plugin。 20 | 例如,添加了_findbugs_ plugin将会创建一个新的task并且让`check` task依赖于这个新的task。当`check` task被调用的时候,这个新的task将会先被调用。 21 | 22 | 在命令行环境中,你可以执行以下命令来获取更多高级别的task: 23 | 24 | gradle tasks 25 | 26 | 查看所有task列表和它们之间的依赖关系可以执行以下命令: 27 | 28 | gradle tasks --all 29 | 30 | --- 31 | 32 | > 注意:Gradle会自动监视一个task声明的所有输入和输出。 33 | 两次执行`build` task并且期间项目没有任何改动,gradle将会使用UP-TO-DATE通知所有task。这意味着第二次build执行的时候不会请求任何task执行。这允许task之间互相依赖,而不会导致不需要的构建请求被执行。 34 | 35 | --- 36 | -------------------------------------------------------------------------------- /basic_project/java_project_tasksjavatask.md: -------------------------------------------------------------------------------- 1 | # Java project tasks(Java项目的Task) 2 | 3 | Java plugin主要创建了两个task,依赖于main task(一个标识性的task): 4 | * `assemble` 5 | * `jar` 6 | 这个task创建所有输出 7 | * `check` 8 | * `test` 9 | 这个task执行所有的测试。 10 | 11 | `jar` task自身直接或者间接依赖于其他task:`classes` task将会被调用于编译java源码。 12 | `testClasses` task用于编译测试,但是它很少被调用,因为`test` task依赖于它(类似于`classes` task)。 13 | 14 | 通常情况下,你只需要调用到`assemble`和`check`,不需要其他task。 15 | 16 | 你可以在Gradle文档中查看[java plugin](http://gradle.org/docs/current/userguide/java_plugin.html)的全部task。 17 | -------------------------------------------------------------------------------- /basic_project/manifest_entries_manifest.md: -------------------------------------------------------------------------------- 1 | # Manifest entries (Manifest属性) 2 | 3 | 通过DSL可以配置一下manifest选项: 4 | 5 | * minSdkVersion 6 | * targetSdkVersion 7 | * versionName 8 | * applicationId (有效的包名 -- 更多详情请查阅[ApplicationId 对比 PackageName](http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename)) 9 | * package Name for the test application 10 | * Instrumentation test runner 11 | 12 | 例如: 13 | 14 | android { 15 | compileSdkVersion 19 16 | buildToolsVersion "19.0.0" 17 | 18 | defaultConfig { 19 | versionCode 12 20 | versionName "2.0" 21 | minSdkVersion 16 22 | targetSdkVersion 16 23 | } 24 | } 25 | 26 | 在`android`元素中的`defaultConfig`元素中定义所有配置。 27 | 28 | 之前的Android Plugin版本使用packageName来配置manifest文件中的packageName属性。从0.11.0版本开始,你需要在build.gradle文件中使用applicationId来配置manifest文件中的packageName属性。 29 | 这是为了消除应用程序的packageName(也是程序的ID)和java包名所引起的混乱。 30 | 31 | 在构建文件中定义的强大之处在于它是动态的。 32 | 例如,可以从一个文件中或者其它自定义的逻辑代码中读取版本信息: 33 | 34 | 35 | def computeVersionName() { 36 | ... 37 | } 38 | 39 | android { 40 | compileSdkVersion 19 41 | buildToolsVersion "19.0.0" 42 | 43 | defaultConfig { 44 | versionCode 12 45 | versionName computeVersionName() 46 | minSdkVersion 16 47 | targetSdkVersion 16 48 | } 49 | } 50 | 51 | 注意:不要使用与在给定范围内的getter方法可能引起冲突的方法名。例如,在defaultConfig{...}中调用getVersionName()将会自动调用defaultConfig.getVersionName()方法,你自定义的getVersionName()方法就被取代掉了。 52 | 53 | 如果一个属性没有使用DSL进行设置,一些默认的属性值将会被使用。以下表格是可能使用到的值: 54 | 55 | Property Name |Default value in DSL object|Default value 56 | ------------- |:-------------: | -----: 57 | `versionCode` |-1 |value from manifest if present 58 | `versionName` |null |value from manifest if present 59 | `minSdkVersion` |-1 |value from manifest if present 60 | `targetSdkVersion`|-1 |value from manifest if present 61 | `applicationId` |null |value from manifest if present 62 | `testApplicationId` |null |applicationId + “.test” 63 | `testInstrumentationRunner` |null|android.test.InstrumentationTestRunner 64 | `signingConfig` |null |null 65 | `proguardFile` |N/A (set only) |N/A (set only) 66 | `proguardFiles` |N/A (set only) |N/A (set only) 67 | 68 | 如果你在构建脚本中使用自定义代码逻辑请求这些属性,那么第二列的值将非常重要。例如,你可能会写: 69 | 70 | if (android.defaultConfig.testInstrumentationRunner == null) { 71 | // assign a better default... 72 | } 73 | 74 | 如果这个值一直保持null,那么在构建执行期间将会实际替换成第三列的默认值。但是在DSL元素中并没有包含这个默认值,所以,你无法查询到这个值。 75 | 除非是真的需要,这是为了预防解析应用的manifest文件。 76 | -------------------------------------------------------------------------------- /basic_project/project_structure.md: -------------------------------------------------------------------------------- 1 | # Project Structure(项目结构) 2 | 3 | 上面提到的基本的构建文件需要一个默认的文件夹结构。Gradle遵循约定优先于配置的概念,在可能的情况尽可能提供合理的默认配置参数。 4 | 5 | 基本的项目开始于两个名为“source sets”的组件,即main source code和test code。它们分别位于: 6 | 7 | * src/main/ 8 | * src/androidTest/ 9 | 10 | 里面每一个存在的文件夹对应相应的源组件。 11 | 对于Java plugin和Android plugin来说,它们的Java源代码和资源文件路径如下: 12 | 13 | * java/ 14 | * resources/ 15 | 16 | 但对于Android plugin来说,它还拥有以下特有的文件和文件夹结构: 17 | 18 | * AndroidManifest.xml 19 | * res/ 20 | * assets/ 21 | * aidl/ 22 | * rs/ 23 | * jni/ 24 | 25 | --- 26 | 27 | > 注意:src/androidTest/AndroidManifest.xml是不需要的,它会自动被创建。 28 | 29 | --- 30 | -------------------------------------------------------------------------------- /basic_project/running_proguard_proguard.md: -------------------------------------------------------------------------------- 1 | # Running Proguard(运行 Proguard) 2 | 3 | 从Gradle Plugin for ProGuard version 4.10之后就开始支持ProGuard。ProGuard插件是自动添加进来的。如果_Build Type_的_runProguard_属性被设置为true,对应的task将会自动创建。 4 | 5 | android { 6 | buildTypes { 7 | release { 8 | runProguard true 9 | proguardFile getDefaultProguardFile('proguard-android.txt') 10 | } 11 | } 12 | 13 | productFlavors { 14 | flavor1 { 15 | } 16 | flavor2 { 17 | proguardFile 'some-other-rules.txt' 18 | } 19 | } 20 | } 21 | 22 | 发布版本将会使用它的Build Type中声明的规则文件,product flavor(定制的产品版本)将会使用对应flavor中声明的规则文件。 23 | 24 | 这里有两个默认的规则文件: 25 | 26 | * proguard-android.txt 27 | * proguard-android-optimize.txt 28 | 29 | 这两个文件都在SDK的路径下。使用_getDefaultProguardFile()_可以获取这些文件的完整路径。它们除了是否要进行优化之外,其它都是相同的。 30 | -------------------------------------------------------------------------------- /basic_project/signing_configurations.md: -------------------------------------------------------------------------------- 1 | # signing configurations(签名配置) 2 | 3 | 对一个应用程序签名需要以下: 4 | 5 | * 一个Keystory 6 | * 一个keystory密码 7 | * 一个key的别名 8 | * 一个key的密码 9 | * 存储类型 10 | 11 | 位置,键名,两个密码,还有存储类型一起形成了签名配置。 12 | 13 | 默认情况下,`debug`被配置成使用一个debug keystory。 14 | debug keystory使用了默认的密码和默认key及默认的key密码。 15 | debug keystory的位置在$HOME/.android/debug.keystroe,如果对应位置不存在这个文件将会自动创建一个。 16 | 17 | `debug` _Build Type_(构建类型) 会自动使用`debug` _SigningConfig_ (签名配置)。 18 | 19 | 可以创建其他配置或者自定义内建的默认配置。通过`signingConfigs`这个DSL容器来配置: 20 | 21 | android { 22 | signingConfigs { 23 | debug { 24 | storeFile file("debug.keystore") 25 | } 26 | 27 | myConfig { 28 | storeFile file("other.keystore") 29 | storePassword "android" 30 | keyAlias "androiddebugkey" 31 | keyPassword "android" 32 | } 33 | } 34 | 35 | buildTypes { 36 | foo { 37 | debuggable true 38 | jniDebugBuild true 39 | signingConfig signingConfigs.myConfig 40 | } 41 | } 42 | } 43 | 44 | 以上代码片段修改debug keystory的路径到项目的根目录下。在这个例子中,这将自动影响其他使用到`debug`构建类型的构建类型。 45 | 46 | 这里也创建了一个新的`Single Config`(签名配置)和一个使用这个新签名配置的新的`Build Type`(构建类型)。 47 | 48 | --- 49 | > 注意:只有默认路径下的debug keystory不存在时会被自动创建。更改debug keystory的路径并不会自动在新路径下创建debug keystory。如果创建一个新的不同名字的_SignConfig_,但是使用默认的debug keystore路径来创建一个非默认的名字的SigningConing,那么还是会在默认路径下创建debug keystory。换句话说,会不会自动创建是根据keystory的路径来判断,而不是配置的名称。 50 | 51 | --- 52 | 53 | > 注意:虽然经常使用项目根目录的相对路径作为keystore的路径,但是也可以使用绝对路径,尽管这并不推荐(除了自动创建出来的debug keystore)。 54 | 55 | --- 56 | 57 | > __注意:如果你将这些文件添加到版本控制工具中,你可能不希望将密码直接写到这些文件中。下面Stack Overflow链接提供从控制台或者环境变量中获取密码的方法: 58 | http://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-using-gradle 59 | 我们以后还会在这个指南中添加更多的详细信息。__ 60 | 61 | --- 62 | -------------------------------------------------------------------------------- /basic_project/simple_build_files.md: -------------------------------------------------------------------------------- 1 | # Simple build files(简单的构建文件) 2 | 3 | 一个最简单的Gradle纯Java项目的build.gradle文件包含以下内容: 4 | 5 | apply plugin: 'java' 6 | 7 | 这里引入了Gradle的Java插件。这个插件提供了所有构建和测试Java应用程序所需要的东西。 8 | 9 | 最简单的Android项目的build.gradle文件包含以下内容: 10 | 11 | buildscript { 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | classpath 'com.android.tools.build:gradle:0.11.1' 18 | } 19 | } 20 | 21 | apply plugin: 'android' 22 | 23 | android { 24 | compileSdkVersion 19 25 | buildToolsVersion "19.0.0" 26 | } 27 | 28 | 这里包括了Android build file的3个主要部分: 29 | 30 | `buildscrip{...}`这里配置了驱动构建过程的代码。 31 | 32 | 在这个部分,它声明了使用Maven仓库,并且声明了一个maven文件的依赖路径。这个文件就是包含了0.11.1版本android gradle插件的库。 33 | 34 | --- 35 | 36 | > 注意:这里的配置只影响控制构建过程的代码,不影响项目源代码。项目本身需要声明自己的仓库和依赖关系,稍后将会提到这部分。 37 | 38 | --- 39 | 40 | 接下来,跟前面提到的Java Plugin一样添加了`android` plugin。 41 | 42 | 最后,`andorid{...}`配置了所有android构建过程需要的参数。这里也是Android DSL的入口点。 43 | 44 | 默认情况下,只需要配置目标编译SDK版本和编译工具版本,即`compileSdkVersion`和`buildToolsVersion`属性。 45 | 这个`complieSdkVersion`属性相当于旧构建系统中project.properites文件中的`target`属性。这个新的属性可以跟旧的`target`属性一样指定一个int或者String类型的值。 46 | 47 | --- 48 | 49 | > 重要:你只能添加`android` plugin。同时添加`java` plugin会导致构建错误。 50 | 51 | --- 52 | 53 | > 注意:你同样需要在相同路径下添加一个local.properties文件,并使用sdk.dir属性来设置SDK路径。 54 | 另外,你也可以通过设置`ANDROID_HOME`环境变量,这两种方式没有什么不同,根据你自己的喜好选择其中一种设置。 55 | 56 | --- 57 | -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "github": "avatarqing", 3 | "githubHost": "https://github.com/", 4 | "plugins": [ 5 | "ga", 6 | "disqus" 7 | ], 8 | "pluginsConfig": { 9 | "ga": { 10 | "token": "UA-52789423-7" 11 | }, 12 | "disqus": { 13 | "shortName": "AvatarQing" 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /build_variants/README.md: -------------------------------------------------------------------------------- 1 | # Build Variants(构建变种版本) 2 | 3 | 新构建系统的一个目标就是允许为同一个应用创建不同的版本。 4 | 5 | 这里有两个主要的使用情景: 6 | 7 | 1. 同一个应用的不同版本。 8 | 例如一个免费的版本和一个收费的专业版本。 9 | 2. 同一个应用需要打包成不同的apk以发布Google Play Store。 10 | [点击此处][1]查看更多详细信息。 11 | 3. 综合1和2两种情景。 12 | 13 | 这个目标就是要让在同一个项目里生成不同的APK成为可能,以取代以前需要使用一个库项目和两个及两个以上的应用项目分别生成不同APK的做法。 14 | 15 | [1]: http://developer.android.com/google/play/publishing/multiple-apks.html 16 | -------------------------------------------------------------------------------- /build_variants/build_type__+_product_flavor_=_build_variant+=.md: -------------------------------------------------------------------------------- 1 | # Build Type + Product Flavor = Build Variant(构建类型+定制产品=构建变种版本) 2 | 3 | 正如前面章节所提到的,每一个_Build Type_都会生成一个新的APK。 4 | 5 | _Product Flavor_同样也会做这些事情:项目的输出将会拼接所有可能的_Build Type_和_Product Flavor_(如果有Flavor定义存在的话)的组合。 6 | 7 | 每一种组合(包含_Build Type_和_Product Flavor_)就是一个_Build Variant_(构建变种版本)。 8 | 9 | 例如,在上面的Flavor声明例子中与默认的`debug`和`release`两个_Build Type_将会生成4个_Build Variant_: 10 | 11 | * Flavor1 - debug 12 | * Flavor1 - release 13 | * Flavor2 - debug 14 | * Flavor2 - release 15 | 16 | 项目中如果没有定义flavor同样也会有_Build Variant_,只是使用的是默认的flavor和配置。`default`(默认)的flavor/config是没有名字的,所以生成的Build Variant列表看起来就跟_Build Type_列表一样。 17 | -------------------------------------------------------------------------------- /build_variants/building_and_tasks.md: -------------------------------------------------------------------------------- 1 | # Building and Tasks(构建和任务) 2 | 3 | 我们前面提到每一个_Build Type_会创建自己的assemble< name >task,但是_Build Variant_是_Build Type_和_Product Flavor_的组合。 4 | 5 | 当使用_Product Flavor_的时候,将会创建更多的assemble-type task。分别是: 6 | 7 | 1. assemble< Variant Name > 8 | 允许直接构建一个Variant版本,例如`assembleFlavor1Debug`。 9 | 2. assemble< Build Type Name > 10 | 允许构建指定Build Type的所有APK,例如`assembleDebug`将会构建Flavor1Debug和Flavor2Debug两个Variant版本。 11 | 3. assemble< Product Flavor Name > 12 | 允许构建指定flavor的所有APK,例如`assembleFlavor1`将会构建Flavor1Debug和Flavor1Release两个Variant版本。 13 | 14 | 另外`assemble` task会构建所有可能组合的Variant版本。 15 | -------------------------------------------------------------------------------- /build_variants/multi-flavor_variants.md: -------------------------------------------------------------------------------- 1 | # Multi-flavor variants 2 | 3 | 在一些情况下,一个应用可能需要基于多个标准来创建多个版本。例如,Google Play中的multi-apk支持4个不同的过滤器。区分创建的不同APK的每一个过滤器要求能够使用多维的Product Flavor。 4 | 5 | 假如有个游戏需要一个免费版本和一个付费的版本,并且需要在multi-apk支持中使用ABI过滤器(译注:ABI,应用二进制接口,优点是不需要改动应用的任何代码就能够将应用迁移到任何支持相同ABI的平台上)。这个游戏应用需要3个ABI和两个特定应用版本,因此就需要生成6个APK(没有因计算不同_Build Types_生成的Variant版本)。 6 | 然而,注意到在这个例子中,为三个ABI构建的付费版本源代码都是相同,因此创建6个flavor来实现不是一个好办法。 7 | 相反的,使用两个flavor维度,并且自动构建所有可能的Variant组合。 8 | 9 | 这个功能的实现就是使用Flavor Groups。每一个Group代表一个维度,并且flavor都被分配到一个指定的Group中。 10 | 11 | android { 12 | ... 13 | 14 | flavorGroups "abi", "version" 15 | 16 | productFlavors { 17 | freeapp { 18 | flavorGroup "version" 19 | ... 20 | } 21 | 22 | x86 { 23 | flavorGroup "abi" 24 | ... 25 | } 26 | 27 | ... 28 | } 29 | } 30 | 31 | `andorid.flavorGroups`数组按照先后排序定义了可能使用的group。每一个_Product Flavor_都被分配到一个group中。 32 | 33 | 上面的例子中将_Product Flavor_分为两组(即两个维度),为别为abi维度[x86,arm,mips]和version维度[freeapp,paidapp],再加上默认的_Build Type_有[debug,release],这将会组合生成以下的Build Variant: 34 | 35 | * x86-freeapp-debug 36 | * x86-freeapp-release 37 | * arm-freeapp-debug 38 | * arm-freeapp-release 39 | * mips-freeapp-debug 40 | * mips-freeapp-release 41 | * x86-paidapp-debug 42 | * x86-paidapp-release 43 | * arm-paidapp-debug 44 | * arm-paidapp-release 45 | * mips-paidapp-debug 46 | * mips-paidapp-release 47 | 48 | `android.flavorGroups`中定义的group排序非常重要(Variant命名和优先级等)。 49 | 50 | 每一个Variant版本的配置由几个`Product Flavor`对象决定: 51 | 52 | * android.defaultConfig 53 | * 一个来自abi组中的对象 54 | * 一个来自version组中的对象 55 | 56 | flavorGroups中的排序决定了哪一个flavor覆盖哪一个,这对于资源来说非常重要,因为一个flavor中的值会替换定义在低优先级的flavor中的值。 57 | 58 | flavor groups使用最高的优先级定义,因此在上面例子中的优先级为: 59 | 60 | abi > version > defaultConfig 61 | 62 | Multi-flavors项目同样拥有额外的sourceSet,类似于Variant的sourceSet,只是少了Build Type: 63 | 64 | * `android.sourceSets.x86Freeapp` 65 | 位于src/x86Freeapp/ 66 | * `android.sourceSets.armPaidapp` 67 | 位于src/armPaidapp/ 68 | * 等等... 69 | 70 | 这允许在flavor-combination的层次上进行定制。它们拥有过比基础的flavor sourceSet更高的优先级,但是优先级低于Build Type的sourceSet。 71 | -------------------------------------------------------------------------------- /build_variants/product_flavor_configurationproduct_flavor.md: -------------------------------------------------------------------------------- 1 | # Product Flavor Configuration(Product Flavor的配置) 2 | 3 | 每一个flavor都是通过闭包来配置的: 4 | 5 | android { 6 | ... 7 | 8 | defaultConfig { 9 | minSdkVersion 8 10 | versionCode 10 11 | } 12 | 13 | productFlavors { 14 | flavor1 { 15 | packageName "com.example.flavor1" 16 | versionCode 20 17 | } 18 | 19 | flavor2 { 20 | packageName "com.example.flavor2" 21 | minSdkVersion 14 22 | } 23 | } 24 | } 25 | 26 | 注意_ProductFlavor_类型的`android.productFlavors.*`对象与`android.defaultConfig`对象的类型是相同的。这意味着它们共享相同的属性。 27 | 28 | `defaultConfig`为所有的flavor提供基本的配置,每一个flavor都可以重设这些配置的值。在上面的例子中,最终的配置结果将会是: 29 | 30 | * `flavor1` 31 | * `packageName`: com.example.flavor1 32 | * `minSdkVersion`: 8 33 | * `versionCode`: 20 34 | * `flavor2` 35 | * `packageName`: com.example.flavor2 36 | * `minSdkVersion`: 14 37 | * `versionCode`: 10 38 | 39 | 通常情况下,_Build Type_的配置会覆盖其它的配置。例如,_Build Type_的`packageNameSuffix`会被追加到_Product Flavor_的`packageName`上面。 40 | 41 | 也有一些情况是一些设置可以同时在_Build Type_和_Product Flavor_中设置。在这种情况下,按照个别为主的原则决定。 42 | 43 | 例如,`signingConfig`就这种属性的一个例子。 44 | `signingConfig`允许通过设置`android.buildTypes.release.signingConfig`来为所有的`release`包共享相同的_SigningConfig_。也可以通过设置`android.productFlavors.*.signingConfig`来为每一个release包指定它们自己的_SigningConfig_。 45 | -------------------------------------------------------------------------------- /build_variants/product_flavors.md: -------------------------------------------------------------------------------- 1 | # Product flavors(不同定制的产品) 2 | 3 | 一个product flavor定义了从项目中构建了一个应用的自定义版本。一个单一的项目可以同时定义多个不同的flavor来改变应用的输出。 4 | 5 | 这个新的设计概念是为了解决不同的版本之间的差异非常小的情况。虽然最项目终生成了多个定制的版本,但是它们本质上都是同一个应用,那么这种做法可能是比使用库项目更好的实现方式。 6 | 7 | Product flavor需要在`productFlavors`这个DSL容器中声明: 8 | 9 | android { 10 | .... 11 | 12 | productFlavors { 13 | flavor1 { 14 | ... 15 | } 16 | 17 | flavor2 { 18 | ... 19 | } 20 | } 21 | } 22 | 23 | 这里创建了两个flavor,名为`flavor1`和`flavor2`。 24 | 25 | --- 26 | 27 | > 注意:flavor的命名不能与已存在的_Build Type_或者`androidTest`这个_sourceSet_有冲突。 28 | -------------------------------------------------------------------------------- /build_variants/sourcesets_and_dependencies.md: -------------------------------------------------------------------------------- 1 | # Sourcesets and Dependencies(源组件和依赖关系) 2 | 3 | 与_Build Type_类似,_Product Flavor_也会通过它们自己的_sourceSet_提供代码和资源。 4 | 5 | 上面的例子将会创建4个_sourceSet_: 6 | 7 | * `android.sourceSets.flavor1` 8 | 位于src/flavor1/ 9 | * `android.sourceSets.flavor2` 10 | 位于src/flavor2/ 11 | * `android.sourceSets.androidTestFlavor1` 12 | 位于src/androidTestFlavor1/ 13 | * `android.sourceSets.androidTestFlavor2` 14 | 位于src/androidTestFlavor2/ 15 | 16 | 这些_sourceSet_用于与`android.sourceSets.main`和_Build Type_的_sourceSet_来构建APK。 17 | 18 | 下面的规则用于处理所有使用的sourceSet来构建一个APK: 19 | 20 | * 多个文件夹中的所有的源代码(src/*/java)都会合并起来生成一个输出。 21 | * 所有的Manifest文件都会合并成一个Manifest文件。类似于_Build Type_,允许_Product Flavor_可以拥有不同的的组件和权限声明。 22 | * 所有使用的资源(Android res和assets)遵循的优先级为_Build Type_会覆盖_Product Flavor_,最终覆盖`main` _sourceSet_的资源。 23 | * 每一个_Build Variant_都会根据资源生成自己的R类(或者其它一些源代码)。Variant互相之间没有什么是共享的。 24 | 25 | 最终,类似_Build Type_,_Product Flavor_也可以有它们自己的依赖关系。例如,如果使用flavor来生成一个基于广告的应用版本和一个付费的应用版本,其中广告版本可能需要依赖于一个广告SDK,但是另一个不需要。 26 | 27 | dependencies { 28 | flavor1Compile "..." 29 | } 30 | 31 | 在这个例子中,src/flavor1/AndroidManifest.xml文件中可能需要声明访问网络的权限。 32 | 33 | 每一个Variant也会创建额外的sourceSet: 34 | 35 | * `android.sourceSets.flavor1Debug` 36 | 位于src/flavor1Debug/ 37 | * `android.sourceSets.flavor1Release` 38 | 位于src/flavor1Release/ 39 | * `android.sourceSets.flavor2Debug` 40 | 位于src/flavor2Debug/ 41 | * `android.sourceSets.flavor2Release` 42 | 位于src/flavor2Release/ 43 | 44 | 这些sourceSet拥有比Build Type的sourceSet更高的优先级,并允许在Variant的层次上做一些定制。 45 | -------------------------------------------------------------------------------- /build_variants/testing.md: -------------------------------------------------------------------------------- 1 | # Testing(测试) 2 | 3 | 测试multi-flavors项目非常类似于测试简单的项目。 4 | 5 | `androidTest` _sourceSet_用于定义所有flavor共用的测试,但是每一个flavor也可以有它自己特有的测试。 6 | 7 | 正如前面提到的,每一个flavor都会创建自己的测试sourceSet: 8 | 9 | * `android.sourceSets.androidTestFlavor1` 10 | 位于src/androidTestFlavor1/ 11 | * `android.sourceSets.androidTestFlavor2` 12 | 位于src/androidTestFlavor2/ 13 | 14 | 同样的,它们也可以拥有自己的依赖关系: 15 | 16 | dependencies { 17 | androidTestFlavor1Compile "..." 18 | } 19 | 20 | 这些测试可以通过main的标志性`deviceCheck` task或者main的`androidTest` task(当flavor被使用的时候这个task相当于一个标志性task)来执行。 21 | 22 | 每一个flavor也拥有它们自己的task来这行这些测试:androidTest< VariantName >。例如: 23 | 24 | * `androidTestFlavor1Debug` 25 | * `androidTestFlavor2Debug` 26 | 27 | 同样的,每一个Variant版本也会创建对应的测试APK构建task和安装或卸载task: 28 | 29 | * `assembleFlavor1Test` 30 | * `installFlavor1Debug` 31 | * `installFlavor1Test` 32 | * `uninstallFlavor1Debug` 33 | * ... 34 | 35 | 最终的HTML报告支持根据flavor合并生成。 36 | 下面是测试结果和报告文件的路径,第一个是每一个flavor版本的结果,后面的是合并起来的结果: 37 | 38 | * build/androidTest-results/flavors/< FlavorName > 39 | * build/androidTest-results/all/ 40 | * build/reports/androidTests/flavors< FlavorName > 41 | * build/reports/androidTests/all/ 42 | -------------------------------------------------------------------------------- /cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvatarQing/Gradle-Plugin-User-Guide-Chinese-Verision/e47e460d1f26e920bf5d779cd7ed21c3891f7add/cover.jpg -------------------------------------------------------------------------------- /cover_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvatarQing/Gradle-Plugin-User-Guide-Chinese-Verision/e47e460d1f26e920bf5d779cd7ed21c3891f7add/cover_small.png -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/README.md: -------------------------------------------------------------------------------- 1 | # Dependencies,Android Libraries and Multi-project setup(依赖关系,Android库和多项目设置) 2 | 3 | Gradle项目可以依赖于其它组件。这些组件可以是外部二进制包,或者是其它的Gradle项目。 4 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/creating_a_library_project.md: -------------------------------------------------------------------------------- 1 | # Creating a Library Project(创建一个库项目) 2 | 3 | 一个库项目与通常的Android项目非常类似,只是有一点小区别。 4 | 5 | 尽管构建库项目不同于构建应用程序,它们使用了不同的plugin。但是在内部这些plugin共享了大部分相同的代码,并且它们都由相同的com.android.tools.build.gradle.jar提供。 6 | 7 | buildscript { 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | 14 | dependencies { 15 | classpath 'com.android.tools.build:gradle:0.5.6' 16 | } 17 | 18 | } 19 | 20 | apply plugin: 'android-library' 21 | 22 | android { 23 | compileSdkVersion 15 24 | } 25 | 26 | 这里创建了一个使用API 15编译_SourceSet_的库项目,并且依赖关系的配置方法与应用程序项目的配置方法一样,同样也支持自定义配置。 27 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/dependencies_on_binary_packages.md: -------------------------------------------------------------------------------- 1 | # Dependencies on binary packages(依赖二进制包) 2 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/differences_between_a_project_and_a_library_project.md: -------------------------------------------------------------------------------- 1 | # Differences between a Project and a Library Project(普通项目和库项目之间的区别) 2 | 3 | 一个库项目的main输出是一个.aar包(它代表Android的归档文件)。它组合了编译代码(例如jar包或者是本地的.so文件)和资源(manifest,res,assets)。 4 | 一个库项目同样也可以独立于应用程序生成一个测试用的apk来测试。 5 | 6 | 标识Task同样适用于库项目(`assembleDebug`,`assembleRelease`),因此在命令行上与构建一个项目没有什么不同。 7 | 8 | 其余的部分,库项目与应用程序项目一样。它们都拥有build type和product flavor,也可以生成多个aar版本。 9 | 记住大部分Build Type的配置不适用于库项目。但是你可以根据库项目是否被其它项目使用或者是否用来测试来使用自定义的sourceSet改变库项目的内容。 10 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/library_projects.md: -------------------------------------------------------------------------------- 1 | # Library projects(库项目) 2 | 3 | 在上面的多项目配置中,`:libraries:lib1`和`:libraries:lib2`可能是一个Java项目,并且`:app`这个Android项目将会使用它们的jar包输出。 4 | 5 | 但是,如果你想要共享代码来访问Android API或者使用Android样式的资源,那么这些库就不能是通常的Java项目,而应该是Android库项目。 6 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/library_publication.md: -------------------------------------------------------------------------------- 1 | # Library Publication(库项目发布) 2 | 3 | 一般情况下一个库只会发布它的_release_ Variant(变种)版本。这个版本将会被所有引用它的项目使用,而不管它们本身自己构建了什么版本。这是由于Gradle的限制,我们正在努力消除这个问题,所以这只是临时的限制。 4 | 5 | 你可以控制哪一个Variant版本作为发行版: 6 | 7 | android { 8 | defaultPublishConfig "debug" 9 | } 10 | 11 | 注意这里的发布配置名称引用的是完整的Variant版本名称。_Relesae_,_debug_只适用于项目中没有其它特性版本的时候使用。如果你想要使用其它Variant版本取代默认的发布版本,你可以: 12 | 13 | android { 14 | defaultPublishConfig "flavor1Debug" 15 | } 16 | 17 | 将库项目的所有Variant版本都发布也是可能的。我们计划在一般的项目依赖项目(类似于上述所说的)情况下允许这种做法,但是由于Gradle的限制(我们也在努力修复这个问题)现在还不太可能。 18 | 默认情况下没有启用发布所有Variant版本。可以通过以下启用: 19 | 20 | android { 21 | publishNonDefault true 22 | } 23 | 24 | 理解发布多个Variant版本意味着发布多个arr文件而不是一个arr文件包含所有Variant版本是非常重要的。每一个arr包都包含一个单一的Variant版本。 25 | 发布一个变种版本意味着构建一个可用的arr文件作为Gradle项目的输出文件。无论是发布到一个maven仓库,还是其它项目需要创建一个这个库项目的依赖都可以使用到这个文件。 26 | 27 | Gradle有一个默认文件的概念。当添加以下配置后就会被使用到: 28 | 29 | compile project(':libraries:lib2') 30 | 31 | 创建一个其它发布文件的依赖,你需要指定具体使用哪一个: 32 | 33 | dependencies { 34 | flavor1Compile project(path: ':lib1', configuration: 'flavor1Release') 35 | flavor2Compile project(path: ':lib1', configuration: 'flavor2Release') 36 | } 37 | 38 | --- 39 | 40 | > 重要:注意已发布的配置是一个完整的Variant版本,其中包括了build type,并且需要像以上一样被引用。 41 | 42 | --- 43 | 44 | > 重要:当启用非默认发布,maven发布插件将会发布其它Variant版本作为扩展包(按分类器分类)。这意味着不能真正的兼容发布到maven仓库。你应该另外发布一个单一的Variant版本到仓库中,或者允许发布所有配置以支持跨项目依赖。 45 | 46 | --- 47 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/local_packages.md: -------------------------------------------------------------------------------- 1 | # Local packages(本地包) 2 | 3 | 配置一个外部库的jar包依赖,你需要在`compile`配置中添加一个依赖。 4 | 5 | dependencies { 6 | compile files('libs/foo.jar') 7 | } 8 | 9 | android { 10 | ... 11 | } 12 | 13 | --- 14 | 15 | > 注意:这个`dependencies` DSL标签是标准Gradle API中的一部分,所以它不属于`android`标签。 16 | 17 | --- 18 | 19 | 这个`compile`配置将被用于编译main application。它里面的所有东西都被会被添加到编译的classpath中,__同时__也会被打包进最终的APK。 20 | 以下是添加依赖时可能用到的其它一些配置选项: 21 | 22 | * `compile` 23 | main application(主module)。 24 | * `androidTestCompile` 25 | test application(测试module)。 26 | * `debugCompile` 27 | debug Build Type(debug类型的编译)。 28 | * `releaseCompile` 29 | release Build Type(发布类型的编译)。 30 | 31 | 因为没有可能去构建一个没有关联任何_Build Type_(构建类型)的APK,APK默认配置了两个或两个以上的编译配置:`compile`和< buildtype >Compile. 32 | 创建一个新的_Build Type_将会自动创建一个基于它名字的新配置。 33 | 34 | 这对于debug版本需要使用一个自定义库(为了反馈实例化的崩溃信息等)但发布版本不需要,或者它们依赖于同一个库的不同版本时会非常有用。 35 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/multi_project_setup.md: -------------------------------------------------------------------------------- 1 | # Multi project setup(多项目设置) 2 | 3 | Gradle项目也可以通过使用多项目配置依赖于其它Gradle项目。 4 | 5 | 多项目配置的实现通常是在一个根项目路径下将所有项目作为子文件夹包含进去。 6 | 7 | 8 | 例如,给定以下项目结构: 9 | 10 | MyProject/ 11 | + app/ 12 | + libraries/ 13 | + lib1/ 14 | + lib2/ 15 | 16 | 我们可以定义3个项目。Grand将会按照以下名字映射它们: 17 | 18 | :app 19 | :libraries:lib1 20 | :libraries:lib2 21 | 22 | 每一个项目都拥有自己的build.gradle文件来声明自己如何构建。 23 | 另外,在根目录下还有一个_setting.gradle_文件用于声明所有项目。 24 | 这些文件的结构如下: 25 | 26 | MyProject/ 27 | | settings.gradle 28 | + app/ 29 | | build.gradle 30 | + libraries/ 31 | + lib1/ 32 | | build.gradle 33 | + lib2/ 34 | | build.gradle 35 | 36 | 其中setting.gradle的内容非常简单: 37 | 38 | include ':app', ':libraries:lib1', ':libraries:lib2' 39 | 40 | 这里定义了哪一个文件夹才是真正的Gradle项目。 41 | 42 | 其中`:app`项目可能依赖于这些库,这是通过以下依赖配置声明的: 43 | 44 | dependencies { 45 | compile project(':libraries:lib1') 46 | } 47 | 48 | 更多关于多项目配置的信息请参考[这里][1]。 49 | 50 | [1]: http://gradle.org/docs/current/userguide/multi_project_builds.html 51 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/referencing_a_library.md: -------------------------------------------------------------------------------- 1 | # Referencing a Library(引用一个库项目) 2 | 3 | 引用一个库项目的方法与引用其它项目的方法一样: 4 | 5 | dependencies { 6 | compile project(':libraries:lib1') 7 | compile project(':libraries:lib2') 8 | } 9 | 10 | --- 11 | 12 | > 注意:如果你要引用多个库,那么排序将非常重要。这类似于旧构建系统里面的project.properties文件中的依赖排序。 13 | 14 | --- 15 | -------------------------------------------------------------------------------- /dependenciesandroid_libraries_and_multi-project_setupandroid/remote_artifacts.md: -------------------------------------------------------------------------------- 1 | # Remote artifacts(远程文件) 2 | 3 | Gradle支持从Maven或者Ivy仓库中拉取文件。 4 | 5 | 首先必须将仓库添加到列表中,然后必须在依赖中声明Maven或者Ivy声明的文件。 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | 12 | dependencies { 13 | compile 'com.google.guava:guava:11.0.2' 14 | } 15 | 16 | android { 17 | ... 18 | } 19 | 20 | --- 21 | 22 | > 注意:`mavenCentral()`是指定仓库URL的简单方法。Gradle支持远程和本地仓库。 23 | 24 | --- 25 | 26 | > 注意:Gradle会遵循依赖关系的传递性。这意味着如果一个依赖本身依赖于其它东西,这些东西也会一并被拉取回来。 27 | 28 | --- 29 | 30 | 更多关于设置依赖关系的信息,请参考[Gradle用户指南][1]和[DSL][2]文档。 31 | 32 | [1]: http://gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html 33 | [2]: http://gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html 34 | -------------------------------------------------------------------------------- /introduction/README.md: -------------------------------------------------------------------------------- 1 | # Introduction(简介) 2 | 本文档适用于0.9版本的Gradle plugin。由于我们在1.0版本之前介绍的不兼容,所以早期版本可能与本文档有所不同。 3 | -------------------------------------------------------------------------------- /introduction/goals_of_the_new_build_systemgradle.md: -------------------------------------------------------------------------------- 1 | # Goals of the new Build System(gradle构建系统的目标) 2 | 采用Gradle作为新构建系统的目标: 3 | 4 | * 让重用代码和资源变得更加容易。 5 | * 让创建同一应用程序的不同版本变得更加容易,无论是多个apk发布版本还是同一个应用的不同定制版本。 6 | * 让构建过程变得更加容易配置,扩展和定制。 7 | * 整合优秀的IDE 8 | -------------------------------------------------------------------------------- /introduction/why_gradlegradle.md: -------------------------------------------------------------------------------- 1 | # Why Gradle?(为什么使用gradle) 2 | Gradle是一个优秀的构建系统和构建工具,它允许通过插件创建自定义的构建逻辑。 3 | 我们基于Gradle以下的一些特点而选择了它: 4 | 5 | * 采用了Domain Specific Language(DSL语言)来描述和控制构建逻辑。 6 | * 构建文件基于Groovy,并且允许通过混合声明DSL元素和使用代码来控制DSL元素以控制自定义的构建逻辑。 7 | * 支持Maven或者Ivy的依赖管理。 8 | * 非常灵活。允许使用最好的实现,但是不会强制实现的方式。 9 | * 插件可以提供自己的DSL和API以供构建文件使用。 10 | * 良好的API工具供IDE集成。 11 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 FriendCode Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/README.md: -------------------------------------------------------------------------------- 1 | Disqus integration for GitBook 2 | ============== 3 | 4 | You can use install it via **NPM**: 5 | 6 | ``` 7 | $ npm install gitbook-plugin-disqus 8 | ``` 9 | 10 | And use it for your book with: 11 | 12 | ``` 13 | $ gitbook build ./ --plugins=disqus 14 | ``` 15 | 16 | 17 | You can set the Disqus shortname using the plugins configuration in the book.json: 18 | 19 | ``` 20 | { 21 | plugins: ["disqus"], 22 | pluginsConfig: { 23 | "disqus": { 24 | "shortName": "XXXXXXX" 25 | } 26 | } 27 | } 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/book/plugin.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "jQuery"], function(gitbook, $) { 2 | var resetDisqus = function() { 3 | var $disqusDiv = $("
", { 4 | "id": "disqus_thread" 5 | }); 6 | $(".book-body .page-inner").append($disqusDiv); 7 | 8 | if (typeof DISQUS !== "undefined") { 9 | DISQUS.reset({ 10 | reload: true, 11 | config: function () { 12 | this.language = "en"; 13 | this.page.url = window.location.href; 14 | } 15 | }); 16 | } 17 | } 18 | 19 | gitbook.events.bind("start", function(e, config) { 20 | config.disqus = config.disqus || {}; 21 | var disqus_shortname = config.disqus.shortName; 22 | 23 | /* * * DON'T EDIT BELOW THIS LINE * * */ 24 | (function() { 25 | var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; 26 | dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; 27 | (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); 28 | })(); 29 | 30 | resetDisqus(); 31 | }); 32 | 33 | gitbook.events.bind("page.change", resetDisqus); 34 | }); -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | book: { 3 | assets: "./book", 4 | js: [ 5 | "plugin.js" 6 | ] 7 | } 8 | }; -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-disqus/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-disqus", 3 | "description": "Disqus integration into GitBook", 4 | "main": "index.js", 5 | "version": "0.0.1", 6 | "engines": { 7 | "gitbook": "*" 8 | }, 9 | "homepage": "https://github.com/GitbookIO/plugin-disqus", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/GitbookIO/plugin-disqus.git" 13 | }, 14 | "license": "Apache 2", 15 | "bugs": { 16 | "url": "https://github.com/GitbookIO/plugin-disqus/issues" 17 | } 18 | } -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/README.md: -------------------------------------------------------------------------------- 1 | Google Analytics tracking for GitBook 2 | ============== 3 | 4 | You can use install it via **NPM**: 5 | 6 | ``` 7 | $ npm install gitbook-plugin-ga 8 | ``` 9 | 10 | And use it for your book with in the book.json: 11 | 12 | ``` 13 | { 14 | "plugins": ["ga"] 15 | } 16 | ``` 17 | 18 | You can set the Google Analytics tracking ID using the plugins configuration in the book.json: 19 | 20 | ``` 21 | { 22 | "plugins": ["ga"], 23 | "pluginsConfig": { 24 | "ga": { 25 | "token": "UA-XXXX-Y" 26 | } 27 | } 28 | } 29 | ``` 30 | 31 | You can customize the tracker object by passing additional configuration options. You can either pass in `auto`, `none` or an object: 32 | 33 | ``` 34 | { 35 | "plugins": ["ga"], 36 | "pluginsConfig": { 37 | "ga": { 38 | "token": "UA-XXXX-Y", 39 | "configuration": { 40 | "cookieName": "new_cookie_name", 41 | "cookieDomain": "mynew.domain.com" 42 | } 43 | } 44 | } 45 | } 46 | ``` 47 | 48 | For an overview of all available configuration parameters, please refer to the [analytics.js field reference](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create). 49 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/book/plugin.js: -------------------------------------------------------------------------------- 1 | require(["gitbook"], function(gitbook) { 2 | gitbook.events.bind("start", function(e, config) { 3 | config.ga = config.ga || {}; 4 | }); 5 | 6 | gitbook.events.bind("page.change", function() { 7 | ga('send', 'pageview'); 8 | }); 9 | 10 | gitbook.events.bind("exercise.submit", function(e, data) { 11 | 12 | }); 13 | }); -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | book: { 3 | assets: "./book", 4 | js: [ 5 | "plugin.js" 6 | ], 7 | html: { 8 | "body:end": function() { 9 | var config = this.options.pluginsConfig.ga || {}; 10 | 11 | if (!config.token) { 12 | throw "Need to option 'token' for Google Analytics plugin"; 13 | } 14 | 15 | if (!config.configuration) { 16 | config.configuration = 'auto'; 17 | } 18 | 19 | if(typeof config.configuration === 'object' && config.configuration !== null) { 20 | configuration = JSON.stringify(config.configuration); 21 | } 22 | else if (['auto', 'none'].indexOf(config.configuration) != -1) { 23 | configuration = "'" + config.configuration + "'"; 24 | } 25 | 26 | return ""; 32 | } 33 | } 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /node_modules/gitbook-plugin-ga/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-ga", 3 | "description": "Google Analytics tracking for your gitbook", 4 | "main": "index.js", 5 | "version": "0.2.0", 6 | "engines": { 7 | "gitbook": ">=0.4.6" 8 | }, 9 | "homepage": "https://github.com/GitbookIO/plugin-ga", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/GitbookIO/plugin-ga.git" 13 | }, 14 | "license": "Apache 2", 15 | "bugs": { 16 | "url": "https://github.com/GitbookIO/plugin-ga/issues" 17 | }, 18 | "_id": "gitbook-plugin-ga@0.2.0", 19 | "dist": { 20 | "shasum": "456ef5daa08103c47cc38628667a1d34098bfd01", 21 | "tarball": "http://registry.npmjs.org/gitbook-plugin-ga/-/gitbook-plugin-ga-0.2.0.tgz" 22 | }, 23 | "_from": "gitbook-plugin-ga@", 24 | "_npmVersion": "1.4.3", 25 | "_npmUser": { 26 | "name": "samypesse", 27 | "email": "samypesse@gmail.com" 28 | }, 29 | "maintainers": [ 30 | { 31 | "name": "samypesse", 32 | "email": "samypesse@gmail.com" 33 | } 34 | ], 35 | "directories": {}, 36 | "_shasum": "456ef5daa08103c47cc38628667a1d34098bfd01", 37 | "_resolved": "https://registry.npmjs.org/gitbook-plugin-ga/-/gitbook-plugin-ga-0.2.0.tgz", 38 | "readme": "ERROR: No README data found!" 39 | } 40 | -------------------------------------------------------------------------------- /requirements/README.md: -------------------------------------------------------------------------------- 1 | # Requirements(要求) 2 | 3 | * Gradle 1.10 或者 Gradle 1.11 或者 Gradle 1.12,并使用0.11.1插件版本。 4 | * SDK build tools 要求版本19.0.0。一些新的特征可能需要更高版本。 5 | -------------------------------------------------------------------------------- /testing/README.md: -------------------------------------------------------------------------------- 1 | # Testing(测试) 2 | 3 | 构建一个测试程序已经被集成到应用项目中,没有必要再专门建立一个测试项目。 4 | -------------------------------------------------------------------------------- /testing/basics_and_configuration.md: -------------------------------------------------------------------------------- 1 | # Basics and Configuration(基本知识和配置) 2 | 3 | 正如前面所提到的,紧邻`main` _sourceSet_的就是`androidTest` _sourceSet_,默认路径在src/androidTest/下。 4 | 在这个测试_sourceSet_中会构建一个使用Android测试框架,并且可以部署到设备上的测试apk来测试应用程序。这里面包含单元测试,集成测试,和后续UI自动化测试。 5 | 这个测试sourceSet不应该包含AndroidManifest.xml文件,因为这个文件会自动生成。 6 | 7 | 下面这些值可能会在测试应用配置中使用到: 8 | 9 | * `testPackageName` 10 | * `testInstrumentationRunner` 11 | * `testHandleProfiling` 12 | * `testfunctionalTest` 13 | 14 | 正如前面所看到的,这些配置在defaultConfig对象中配置: 15 | 16 | android { 17 | defaultConfig { 18 | testPackageName "com.test.foo" 19 | testInstrumentationRunner "android.test.InstrumentationTestRunner" 20 | testHandleProfiling true 21 | testFunctionalTest true 22 | } 23 | } 24 | 25 | 在测试应用程序的manifest文件中,instrumentation节点的targetPackage属性值会自动使用测试应用的package名称设置,即使这个名称是通过`defaultConfig`或者_Build Type_对象自定义的。这也是manifest文件需要自动生成的一个原因。 26 | 27 | 另外,这个测试_sourceSet_也可以拥有自己的依赖。 28 | 默认情况下,应用程序和他的依赖会自动添加的测试应用的classpath中,但是也可以通过以下来扩展: 29 | 30 | dependencies { 31 | androidTestCompile 'com.google.guava:guava:11.0.2' 32 | } 33 | 34 | 测试应用通过`assembleTest` task来构建。`assembleTest`不依赖于main中的`assemble` task,需要手动设置运行,不能自动运行。 35 | 36 | 目前只有一个_Build Type_被测试。默认情况下是`debug` _Build Type_,但是这也可以通过以下自定义配置: 37 | 38 | android { 39 | ... 40 | testBuildType "staging" 41 | } 42 | -------------------------------------------------------------------------------- /testing/lint_supportlint.md: -------------------------------------------------------------------------------- 1 | # Lint support(Lint支持) 2 | 3 | > Lint支持,译者注:Lint是一个可以检查Android项目中存在的问题的工具 4 | 5 | 从0.7.0版本开始,你可以为项目中一个特定的Variant(变种)版本运行lint,也可以为所有Variant版本都运行lint。它将会生成一个报告描述哪一个Variant版本中存在着问题。 6 | 7 | 你可以通过以下lint选项配置lint。通常情况下你只需要配置其中一部分,以下列出了所有可使用的选项: 8 | 9 | android { 10 | lintOptions { 11 | // set to true to turn off analysis progress reporting by lint 12 | quiet true 13 | // if true, stop the gradle build if errors are found 14 | abortOnError false 15 | // if true, only report errors 16 | ignoreWarnings true 17 | // if true, emit full/absolute paths to files with errors (true by default) 18 | //absolutePaths true 19 | // if true, check all issues, including those that are off by default 20 | checkAllWarnings true 21 | // if true, treat all warnings as errors 22 | warningsAsErrors true 23 | // turn off checking the given issue id's 24 | disable 'TypographyFractions','TypographyQuotes' 25 | // turn on the given issue id's 26 | enable 'RtlHardcoded','RtlCompat', 'RtlEnabled' 27 | // check *only* the given issue id's 28 | check 'NewApi', 'InlinedApi' 29 | // if true, don't include source code lines in the error output 30 | noLines true 31 | // if true, show all locations for an error, do not truncate lists, etc. 32 | showAll true 33 | // Fallback lint configuration (default severities, etc.) 34 | lintConfig file("default-lint.xml") 35 | // if true, generate a text report of issues (false by default) 36 | textReport true 37 | // location to write the output; can be a file or 'stdout' 38 | textOutput 'stdout' 39 | // if true, generate an XML report for use by for example Jenkins 40 | xmlReport false 41 | // file to write report to (if not specified, defaults to lint-results.xml) 42 | xmlOutput file("lint-report.xml") 43 | // if true, generate an HTML report (with issue explanations, sourcecode, etc) 44 | htmlReport true 45 | // optional path to report (default will be lint-results.html in the builddir) 46 | htmlOutput file("lint-report.html") 47 | 48 | // set to true to have all release builds run lint on issues with severity=fatal 49 | // and abort the build (controlled by abortOnError above) if fatal issues are found 50 | checkReleaseBuilds true 51 | // Set the severity of the given issues to fatal (which means they will be 52 | // checked during release builds (even if the lint target is not included) 53 | fatal 'NewApi', 'InlineApi' 54 | // Set the severity of the given issues to error 55 | error 'Wakelock', 'TextViewEdits' 56 | // Set the severity of the given issues to warning 57 | warning 'ResourceAsColor' 58 | // Set the severity of the given issues to ignore (same as disabling the check) 59 | ignore 'TypographyQuotes' 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /testing/multi-projects_reports.md: -------------------------------------------------------------------------------- 1 | # Multi-projects reports(多项目报告) 2 | 3 | 在一个配置了多个应用或者多个库项目的多项目里,当同时运行所有测试的时候,生成一个报告文件记录所有的测试可能是非常有用的。 4 | 5 | 为了实现这个目的,需要使用同一个依赖文件(译注:指的是使用android gradle插件的依赖文件)中的另一个插件。可以通过以下方式添加: 6 | 7 | buildscript { 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:0.5.6' 14 | } 15 | } 16 | 17 | apply plugin: 'android-reporting' 18 | 19 | 这必须添加到项目的根目录下,例如与settings.gradle文件同个目录的build.gradle文件中。 20 | 21 | 之后,在命令行中导航到项目根目录下,输入以下命令就可以运行所有测试并合并所有报告: 22 | 23 | gradle deviceCheck mergeAndroidReports --continue 24 | 25 | --- 26 | 27 | > 注意:这里的--continue选项将允许所有测试,即使子项目中的任何一个运行失败都不会停止。如果没有这个选项,第一个失败测试将会终止全部测试的运行,这可能导致一些项目没有执行过它们的测试。 28 | 29 | --- 30 | -------------------------------------------------------------------------------- /testing/running_tests.md: -------------------------------------------------------------------------------- 1 | # Running tests(运行测试) 2 | 3 | 正如前面提到的,标志性task `connectedCheck`要求一个连接的设备来启动。 4 | 这个过程依赖于`androidTest` task,因此将会运行`androidTest`。这个task将会执行下面内容: 5 | 6 | * 确认应用和测试应用都被构建(依赖于`assembleDebug`和`assembleTest`)。 7 | * 安装这两个应用。 8 | * 运行这些测试。 9 | * 卸载这两个应用。 10 | 11 | 如果有多于一个连接设备,那么所有测试都会同时运行在所有连接设备上。如果其中一个测试失败,不管是哪一个设备算失败。 12 | 13 | 所有测试结果都被保存为XML文档,路径为: 14 | 15 | _build/androidTest-results_ 16 | 17 | (这类似于JUnit的运行结果保存在build/test-results) 18 | 19 | 同样,这也可以自定义配置: 20 | 21 | android { 22 | ... 23 | 24 | testOptions { 25 | resultsDir = "$project.buildDir/foo/results" 26 | } 27 | } 28 | 29 | 这里的`android.testOptions.resultsDir`将由`Project.file(String)`获得。 30 | -------------------------------------------------------------------------------- /testing/single_projects.md: -------------------------------------------------------------------------------- 1 | # Single projects(独立项目) 2 | 3 | 一个项目将会自动生成测试运行。默认位置为:build/reports/androidTests 4 | 5 | 这非常类似于JUnit的报告所在位置build/reports/tests,其它的报告通常位于build/reports/< plugin >/。 6 | 7 | 这个路径也可以通过以下方式自定义: 8 | 9 | android { 10 | ... 11 | 12 | testOptions { 13 | reportDir = "$project.buildDir/foo/report" 14 | } 15 | } 16 | 17 | 报告将会合并运行在不同设备上的测试结果。 18 | -------------------------------------------------------------------------------- /testing/test_reports.md: -------------------------------------------------------------------------------- 1 | # Test reports(测试报告) 2 | 3 | 当运行单元测试的时候,Gradle会输出一份HTML格式的报告以方便查看结果。 4 | Android plugin也是基于此,并且扩展了HTML报告文件,它将所有连接设备的报告都合并到一个文件里面。 5 | -------------------------------------------------------------------------------- /testing/testing_android_librariesandroid.md: -------------------------------------------------------------------------------- 1 | # Testing Android Libraries(测试Android库) 2 | 3 | 测试Android库项目的方法与应用项目的方法类似。 4 | 5 | 唯一的不同在于整个库(包括它的依赖)都是自动作为依赖库被添加到测试应用中。结果就是测试APK不单只包含它的代码,还包含了库项目自己和库的所有依赖。 6 | 库的manifest被组合到测试应用的manifest中(作为一些项目引用这个库的壳)。 7 | 8 | `androidTest` task的变改只是安装(或者卸载)测试APK(因为没有其它APK被安装)。 9 | 10 | 其它的部分都是类似的。 11 | --------------------------------------------------------------------------------