-
Notifications
You must be signed in to change notification settings - Fork 143
/
fonts.gradle
56 lines (47 loc) · 2.13 KB
/
fonts.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
/**
* Task to copy icon font files
*/
def config = project.hasProperty("vectoricons") ? project.vectoricons : [];
def iconFontsDir = config.iconFontsDir ?: "../../assets/fonts";
def iconFontNames = config.iconFontNames ?: [ "*.ttf" ];
gradle.projectsEvaluated {
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add("")
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
// Create variant and target names
def flavorNameCapitalized = "${productFlavorName.capitalize()}"
def buildNameCapitalized = "${buildTypeName.capitalize()}"
def targetName = "${flavorNameCapitalized}${buildNameCapitalized}"
def targetPath = productFlavorName ?
"${productFlavorName}/${buildTypeName}" :
"${buildTypeName}"
// Create task for copying fonts
def currentFontTask = tasks.create(
name: "copy${targetName}IconFonts",
type: Copy) {
iconFontNames.each { name ->
from(iconFontsDir)
include(name)
into("${buildDir}/intermediates/assets/${targetPath}/fonts/")
}
}
currentFontTask.dependsOn("merge${targetName}Resources")
currentFontTask.dependsOn("merge${targetName}Assets")
[
"process${flavorNameCapitalized}Armeabi-v7a${buildNameCapitalized}Resources",
"process${flavorNameCapitalized}X86${buildNameCapitalized}Resources",
"processUniversal${targetName}Resources",
"process${targetName}Resources"
].each { name ->
Task dependentTask = tasks.findByPath(name);
if (dependentTask != null) {
dependentTask.dependsOn(currentFontTask)
}
}
}
}
}