-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarketSkusCreator.gradle
74 lines (68 loc) · 3.95 KB
/
marketSkusCreator.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
apply from: '../utils.gradle'
ext {
fillArrays = { variant, fileIsInRoot ->
// logger.info("fillArrays: {}", variant.productFlavors[0].name)
// println("fillArrays: " + variant.productFlavors[0].name)
variant.productFlavors.each {
logger.info("fillArrays: {}", it.name)
println("fillArrays: " + it.name)
}
def pathToFileWithData
if (fileIsInRoot) {
pathToFileWithData = "marketSkus.properties"
fillSkusData(variant, pathToFileWithData)
} else {
pathToFileWithData = "config/" + variant.productFlavors[0].name + "/" + variant.productFlavors[2].name + "/marketSkus.properties"
def buildTypeName = variant.buildType.name
def flavorMergedName = variant.productFlavors[0].name + variant.productFlavors[1].name + variant.productFlavors[2].name
println("pathToFileWithData: " + pathToFileWithData)
println("buildTypeName: " + buildTypeName)
println("flavorMergedName: " + flavorMergedName)
println("getCurrentFlavor(): " + getCurrentFlavor())
if (getCurrentFlavor().equalsIgnoreCase(flavorMergedName) && buildTypeName.equalsIgnoreCase(getCurrentBuildType())) {
logger.lifecycle('flavorName/buildTypeName: {}/{}', flavorMergedName, buildTypeName)
fillSkusData(variant, pathToFileWithData)
}
}
}
fillSkusData = { variant, pathToFileWithData ->
//add market skus to buildConfig
//there is a way to store it in res... but it's awful
//http://stackoverflow.com/a/41655569/3212712
//Load market SKUs
if (rootProject.file(pathToFileWithData).exists()) {
def marketSkusPropertiesFile = rootProject.file(pathToFileWithData);
def properties = new Properties()
properties.load(new FileInputStream(marketSkusPropertiesFile))
//ver4 purchases and subscriptions 09.18
variant.resValue('string', 'ver4_skus', properties.get("marketSkusVer4"))
variant.resValue('string', 'ver4_skus_parent', properties.get("marketSkusVer4Parent"))
variant.resValue('string', 'ver4_inapp_skus', properties.get("marketSkusInappVer4"))
variant.resValue('string', 'ver4_subs_no_ads', properties.get("noAdsSkuVer4"))
variant.resValue('string', 'ver4_subs_free_trial', properties.get("subsFreeTrialVer4"))
//version 01.18
// logger.lifecycle('pathToFileWithData: {}', pathToFileWithData)
// logger.lifecycle('properties: {}', properties.propertyNames().toList().toListString())
variant.resValue('string', 'ver3_skus', properties.get("marketSkusVer3"))
variant.resValue('string', 'ver3_inapp_skus', properties.get("marketSkusInappVer3"))
variant.resValue('string', 'ver3_subs_no_ads', properties.get("noAdsSkuVer3"))
variant.resValue('string', 'ver3_subs_free_trial', properties.get("subsFreeTrialVer3"))
//deprecated
variant.resValue('string', 'old_skus', properties.get("marketSkusOld"))
variant.resValue('string', 'ver_2_skus', properties.get("marketSkusVer2"))
//level up inapp
variant.resValue('string', 'inapp_skus', properties.get("marketSkusInapp"))
//no ads subs
variant.resValue('string', 'subs_no_ads_old', properties.get("noAdsSkuOld"))
variant.resValue('string', 'subs_no_ads_ver_2', properties.get("noAdsSkuVer2"))
//free trail subs
variant.resValue('string', 'subs_free_trial', properties.get("subsFreeTrial"))
} else {
logger.lifecycle('pathToFileWithData: {}', pathToFileWithData)
throw new GradleException("You need to have marketSkus.properties file in root of project with " +
"marketSkusOld," +
"marketSkusVer2," +
" variables to build project")
}
}
}