module中的build.gradle的文件配置。
一般主要包括如下根节点:apply plugin
必须放在第一行,它可以指定这个module是一个应用(用 apply plugin: ‘com.Android.application’ 配置),或是一个库(用 apply plugin: ‘com.android.library’ 配置)。
allprejects
依赖中一些lib的仓储位置。有些lib的仓储位置是一些特别的地址,在这里进行设置。
eg:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
dependencies
项目中的依赖库,在这里设置。
- 1
- 1
表示 编译时,可以依赖包括libs下的jar包。如果项目中有jar包,必须添加此行才能依赖jar
- 1
- 1
表示依赖libs下的android-async-http-master.jar
- 1
- 1
表示 依赖本地的library类型的叫做 library 的 module。
- 1
- 1
表示依赖远程库 com.android.support:appcompat-v7:21.0.3。
主要讲讲 android 根节点
android节点主要包含一下节点:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
我们来逐一认识下:
- 1
- 2
- 1
- 2
这两个是指定的编译的SDK版本,以及编辑工具版本。
defaultConfig
这个是默认配置,相当于eclipse中manifest中的一些基本配置,buildType中也将自动继承。
它里面可以放入很多配置,如下面buildTypes/release的一些配置也可放入其中:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
这里,如果是apk项目必须要applicationId 配置,表示的是包名。但如果是library类型的则不需要。
下面一次是:最小sdk版本15,目标sdk版本21,代码版本1,版本名称1.0等apk的基本信息。
ndk部分,作用是可以直接编译ndk代码,不需要自己执行。
buildType
这里进行编译配置,系统默认有release(发布配置)和debug(调试配置)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
其中,release 能进行缩量混淆配置(减小apk体积)minifyEnabled true,以及 进行混淆文件设置 proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’,还能对签名工具进行配置 signingConfigs signingConfigs.release.
compileOptions
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
对Java的版本配置,以便使用对应版本的一些新特性。
sourceSets
重新指向源码路径
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
lintOptions
- 1
- 2
- 3
- 1
- 2
- 3
这个设置编译的lint开关。程序在build的时候,会执行lint检查,有任何错误或者警告提示,都会终止构建,我们可以将其关掉。
productFlavors
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
productFlavors块,你可以配置多个产品风味(免费版、付费版、不同渠道版)。这里你可以创建不同版本的app,通过重写defaultConfig{}的设置。productFlavors是可选的。默认情况下,系统不会自动创建。每个flavor都可以自己的的application id。
signingConfigs
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
包签名的配置,你可以设置具体的签名文件,签名密码等等
更多内容请看:Android官方AS配置文档地址:https://developer.android.com/studio/build/index.html