-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioning.gradle
58 lines (50 loc) · 2.01 KB
/
versioning.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
ext {
/**
* Builds an Android version code from the version of the project.
* This is designed to handle the -SNAPSHOT and -RC format.
*
* I.e. during development the version ends with -SNAPSHOT. As the code stabilizes and release nears
* one or many Release Candidates are tagged. These all end with "-RC1", "-RC2" etc.
* And the final release is without any suffix.
* @return
*/
buildVersionCode = {
//The rules is as follows:
//-SNAPSHOT counts as 0
//-RC* counts as the RC number, i.e. 1 to 98
//final release counts as 99.
//Thus you can only have 98 Release Candidates, which ought to be enough for everyone
def candidate = "99"
def (major, minor, patch) = version.toLowerCase().replaceAll('-', '').tokenize('.')
if (patch.endsWith("snapshot")) {
candidate = "0"
patch = patch.replaceAll("[^0-9]","")
} else {
def rc
(patch, rc) = patch.tokenize("rc")
if (rc) {
candidate = rc
}
}
(major, minor, patch, candidate) = [major, minor, patch, candidate].collect{it.toInteger()}
(major * 1000000) + (minor * 10000) + (patch * 100) + candidate;
}
renameApk = { variant ->
variant.outputs.each { output ->
def apkPath = output.outputFile.parentFile
def baseName = project.archivesBaseName
// if it's a release build, the type is implicit, imo, so add it otherwise
if (variant.buildType.name != 'release') {
baseName += "-${variant.buildType.name}"
}
// add version name and version code
baseName += "-v${variant.versionName}"
// if the variant will not be zipAligned, specify that
if (!output.zipAlign) {
baseName += '-unaligned'
}
// set the output file
output.outputFile = new File(apkPath, "${baseName}.apk");
}
}
}