-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon_methods.gradle
More file actions
93 lines (77 loc) · 2.56 KB
/
common_methods.gradle
File metadata and controls
93 lines (77 loc) · 2.56 KB
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
ext {
STRING = "String"
BOOLEAN = "boolean"
INT = "int"
generateVersionCode = { major, minor, patch ->
def majorFactor = 10000
def minorFactor = 100
def patchFactor = 1
if(patch > 99) {
println("warning patch number to high! "+patch)
}
if(minor > 99) {
println("warning minor number to high! "+minor)
}
def versionCode = major*majorFactor + minor*minorFactor + patch*patchFactor
println("versionCode: "+versionCode)
return versionCode
};
generateVersionName = { major, minor, patch ->
def versionName = "${major}.${minor}.${patch}"
println("versionName: "+versionName)
return versionName
};
getVariantFieldValue = { field, buildType, type, key ->
def value
if (field instanceof Map) {
if (field["$buildType"] == null) {
println("not defined explicit param value for \'${key}\' in \'${buildType}\' configuration. Using first value founded")
value = field.entrySet().toList().first().getValue()
} else {
value = field["$buildType"]
}
} else {
value = field
}
if (value != null) {
if (type.toLowerCase().equals("string")) {
value = "\"${value}\""
}
else {
value = "${value}"
}
}
return value
};
setVariantApplicationId = { variant, appId ->
def mergedFlavor = variant.getVariantData().getVariantConfiguration().getMergedFlavor()
mergedFlavor.setApplicationId(appId)
println("applicationId: " + appId)
};
setVariantModeDebugValue = { variant, key, type ->
def value = (variant.buildType.name == 'debug' || variant.buildType.name == 'staging')
setVariantBuildConfigField(variant, value, key, type)
};
setVariantBuildConfigField = { variant, field, key, type ->
def value = getVariantFieldValue(field, variant.buildType.name, type, key)
if (value != null) {
try {
variant.buildConfigField(type, key, value)
println("BuildConfig -> " + type + ":" + key + " = " + value)
} catch (Exception ex) {
println("Null value: BuildConfig -> " + type + ":" + key + " not added!")
}
} else {
println("Null value: BuildConfig -> " + type + ":" + key + " not added!")
}
};
setVariantResValue = { variant, field, key, type ->
def value = getVariantFieldValue(field, variant.buildType.name, type, key)
try {
variant.resValue(type, key, value)
println("Res -> " + type + ":" + key + " = " + value)
} catch (Exception ex) {
println("Null value: Res -> " + type + ":" + key + " = " + value)
}
};
}