/
build.gradle
136 lines (118 loc) · 4.36 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
apply plugin: 'android'
archivesBaseName = "demo"
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':library:ActionBarSherlock:library')
compile project(':library:UnifiedPreference:library')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
versionName '1.0.1'
packageName = 'com.corner23.android.demo'
}
productFlavors {
rock
amazonFree {
packageName = 'com.corner23.android.demo.amazon.free'
}
amazonPaid {
packageName = 'com.corner23.android.demo.amazon.paid'
}
playFree {
packageName = 'com.corner23.android.demo.play.free'
}
playPaid {
packageName = 'com.corner23.android.demo.play.paid'
}
}
signingConfigs {
release {
if (project.hasProperty('demoKeyAlias') &&
project.hasProperty('demoStoreFile') &&
project.hasProperty('demoStorePassword') &&
project.hasProperty('demoKeyPassword')) {
keyAlias = demoKeyAlias
storeFile = file(demoStoreFile)
storePassword = demoStorePassword
keyPassword = demoKeyPassword
} else {
signingConfig = null
}
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
versionNameSuffix "-SNAPSHOT"
}
release {
signingConfig signingConfigs.release
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
}
android.applicationVariants.all { variant ->
variant.mergeResources.doFirst {
if (variant.name.startsWith("AmazonPaid")) {
android.sourceSets.debug.res.srcDirs = ['src/amazonPaidDebug/res']
android.sourceSets.release.res.srcDirs = ['src/amazonPaidRelease/res']
} else if (variant.name.startsWith("AmazonFree")) {
android.sourceSets.debug.res.srcDirs = ['src/amazonFreeDebug/res']
android.sourceSets.release.res.srcDirs = ['src/amazonFreeRelease/res']
} else {
android.sourceSets.debug.res.srcDirs = ['src/debug/res']
android.sourceSets.release.res.srcDirs = ['src/release/res']
}
}
// launch after install
variant.install.doLast {
def packageSuffix = variant.buildType.packageNameSuffix ? variant.buildType.packageNameSuffix : ""
def packageName = variant.productFlavors.packageName[0] ? variant.productFlavors.packageName[0] : android.defaultConfig.packageName
def startupClass = packageName + packageSuffix + '/com.corner23.android.demo.MainActivity'
def result = exec {
executable = 'adb'
args = ['shell', 'am', 'start', '-c', 'android.intent.category.LAUNCHER', '-n', startupClass]
}
}
variant.assemble.doLast {
rename_and_moveout_apk(variant)
}
}
def rename_and_moveout_apk(targetVariant) {
// get hash of current commit
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'git'
args = ['rev-parse', '--short', 'HEAD']
standardOutput = os
}
project.ext.gitHash = os.toString().trim();
}
// replace output apk name to <product>-<version>-<buildtype>-<githash>.apk
def versionSuffix = targetVariant.buildType.versionNameSuffix ? targetVariant.buildType.versionNameSuffix : ""
def versionName = targetVariant.mergedFlavor.versionName + versionSuffix + "-${gitHash}";
if (targetVariant.zipAlign) {
def apkFinal = targetVariant.outputFile;
def apkFinalNewName = apkFinal.name.replace(targetVariant.buildType.name, versionName);
copy {
from "$apkFinal"
into "$rootProject.projectDir/out"
rename ("$apkFinal.name", "$apkFinalNewName")
}
}
def apkProcess = targetVariant.packageApplication.outputFile;
def apkProcessNewName = apkProcess.name.replace(targetVariant.buildType.name, versionName);
copy {
from "$apkProcess"
into "$rootProject.projectDir/out"
rename ("$apkProcess.name", "$apkProcessNewName")
}
}
clean.doLast {
project.delete "$rootProject.projectDir/out"
}