-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
126 lines (113 loc) · 4.66 KB
/
build.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
apply plugin: 'com.android.application'
android {
signingConfigs {
releaseConfig {
keyAlias 'test_jenkins_release'
keyPassword ALIAS_PASSWORD
storeFile file('./../keystore/test_jenkins_release_key.jks')
storePassword STORE_PASSWORD
}
}
//渠道Flavors
flavorDimensions("flavor")
productFlavors {
xiaomi {
dimension "flavor"
}
wandoujia {
dimension "flavor"
}
}
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version
defaultConfig {
applicationId project.APPLICATION_ID
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode Integer.parseInt(project.VERSION_CODE)
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseConfig
}
debug {
signingConfig signingConfigs.releaseConfig
}
}
//修改生成的apk名字及输出文件夹
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 拼接apk名称
def flavorName = ""
productFlavors.eachWithIndex { productFlavor, int index ->
flavorName += productFlavor.name
if (index != (productFlavors.size()-1)) {
flavorName += "-"
}
}
def fileName = "app#app-${flavorName}-${variant.buildType.name}-${defaultConfig.versionName}-${buildTime()}.apk"
outputFileName = fileName
// 是否为Jenkins打包,输出路径不同
def outDirectory
if ("true".equals(IS_JENKINS)) {
def date = Calendar.getInstance()
def timeStr = date.get(Calendar.YEAR) + (((date.get(Calendar.MONTH) + 1) >= 10 ? date.get(Calendar.MONTH) + 1 : "0" + (date.get(Calendar.MONTH) + 1))) + (date.get(Calendar.DAY_OF_MONTH) >= 10 ? date.get(Calendar.DAY_OF_MONTH) : "0" + date.get(Calendar.DAY_OF_MONTH)) + "_" + (date.get(Calendar.HOUR_OF_DAY) >= 10 ? date.get(Calendar.HOUR_OF_DAY) : "0" + date.get(Calendar.HOUR_OF_DAY)) + (date.get(Calendar.MINUTE) >= 10 ? date.get(Calendar.MINUTE) : "0" + date.get(Calendar.MINUTE))
outDirectory = BUILD_PATH_JENKINS
outDirectory = outDirectory + "\\" + flavorName + "\\" + variant.buildType.name + "\\" + timeStr
} else {
outDirectory = outputFile.parent
}
variant.getPackageApplication().outputDirectory = new File(outDirectory)
outputFileName = fileName
}
}
}
}
// 返回编译Apk日期函数
def buildTime() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
// 在最后一个task后执行生成二维码胡操作
gradle.taskGraph.whenReady { graph ->
graph.allTasks[graph.allTasks.size()-1].doLast {
if ("true".equals(IS_JENKINS)) {
println '---------------------doLast------------------------'
}
}
}
task testTask {
println 'do testTask'
}
// 在最后一个task后执行生成二维码胡操作
//gradle.taskGraph.whenReady { graph ->
// graph.allTasks[graph.allTasks.size()-1].doLast {
// println '---------------------doLast------------------------'
// // jenkins打包生成二维码
// if ("true".equals(IS_JENKINS)) {
// tasks.create(name: 'generateOR', type: Exec, overwrite: true) {
// println '---------------------generateQR------------------------'
// // 执行jenkinsQR.py,生成二维码
// def pycmd = "python jenkinsQR.py " + BUILD_TYPE + ' ' + timeStr + ' ' + BUILD_PATH_JENKINS + ' ' + fileName
// pycmd.execute()
// println pycmd
// }
// }
// }
//}