gradle

Gradle不知道的配置,不止是编译运行打包依赖

application的gradle

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
//对整个项目的gradle进行配置
buildscript {
//编译依赖的仓库,也就是gradle的仓库
repositories {
jcenter()
}
dependencies {
//grale的依赖,这里是Google指定的版本和真正的版本不一致
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
//module的依赖仓库
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
//clean时清空项目根目录的bulid文件夹
task clean(type: Delete) {
delete rootProject.buildDir
}

setting的gradle

1
2
3
//项目包含的module
include ':app'
include ':bluetoothDemo'

moudle的gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//使用app插件
apply plugin: 'com.android.application'
//library使用插件 apply plugin: 'com.android.library'
android {
signingConfigs {
config {
keyAlias 'xxxx'
keyPassword 'xxxx'
storeFile file('H:/xxx.jks')
storePassword 'xxxx'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
//真正的包名
applicationId "com.zwang.jxc"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//开启分包,64k方法数
multiDexEnabled true
}
//指定打包后应用名称
applicationVariants.all {variant ->
variant.outputs.each {output ->
def outputFile = output.outputFile
def fileName
if (outputFile != null && outputFile.name.endsWith('.apk')) {
if (variant.buildType.name.equals('release')) {
fileName = "应用 _${defaultConfig.versionName}_${defaultConfig.versionCode}.apk"
} else if (variant.buildType.name.equals('debug')) {
fileName = "应用_${defaultConfig.versionName}_${defaultConfig.versionCode}_debug.apk"
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
//混淆
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//打包内存分配
dexOptions {
javaMaxHeapSize "4g"
}
//编译打包不同版本,编译时间减少一半
productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 16
}
}
}
dependencies {
//依赖的文件位置
compile fileTree(include: ['*.jar'], dir: 'libs')
//jar宝依赖
compile files('libs/butterknife-7.0.1.jar')
//仓库依赖
compile 'com.android.support:appcompat-v7:25.3.1'
//分包依赖
compile 'com.android.support:multidex:1.0.1'
//解决第三方库冲突
//build.gradle所在目录下执行gradlew -q app:dependencies命令查看依赖情况
compile('cn.qqtheme.framework:WheelPicker:latest.release') {
//解决特定的
exclude module: 'support-v4'
//解决一类的
exclude group: 'com.android.support'
}
//library依赖
compile project(':bluetoothDemo')
//更新依赖,指定版本号只会更新该版本号
compile("com.tencent.tinker:tinker-android-lib:1.7.6") {
changing = true
}
}

gradle.properties

1
2
3
4
5
6
7
8
9
# 守护进程
org.gradle.daemon=true
# 并行编译
org.gradle.parallel=true
#代理
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080