-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
89 lines (71 loc) · 2.01 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
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// Android 默认的编译工具库插件
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
jcenter()
}
// Javadoc设定为UTF-8了
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
}
}
/**
* 生成版本的时间
*/
static def releaseTime() {
return new Date().format("yyyy_MMdd")
}
/**
* 生成VersionCode
*/
static def generateVersionCode() {
return new Date().format("yyyyMMddHH")
}
/**
* 重命名Apk的方法
*/
def renameAPK(android, variant, output) {
def flavor = variant.productFlavors[0];
def flavorName;
def versionName;
if (flavor == null) {
flavorName = ""
versionName = android.defaultConfig.versionName
} else {
versionName = flavor.versionName
flavorName = flavor.name
}
if (versionName == null || versionName.toString().equals("null")) {
versionName = variant.versionName;
}
if (versionName == null || versionName.toString().equals("null")) {
versionName = ""
}
def versionNameSuffix = variant.buildType.versionNameSuffix
if (versionNameSuffix.toString().equals("null")) {
versionNameSuffix = ""
}
def buildTypeName = variant.buildType.name;
if (buildTypeName.equals("debug")) {
buildTypeName = "dev"
} else if (buildTypeName.equals("release")) {
buildTypeName = "prod"
}
def outputFile = output.outputFile
if (outputFile != null) {
if (flavorName.equals("") || flavorName.equals("null")) {
output.outputFileName = "${APK_PREFIX}_${buildTypeName}_v${versionName}${versionNameSuffix}_${releaseTime()}.apk"
} else {
output.outputFileName = "${APK_PREFIX}_${buildTypeName}_${flavorName}_v${versionName}${versionNameSuffix}_${releaseTime()}.apk"
}
}
}