forked from Clam-/TraditionalT9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
192 lines (170 loc) · 4.93 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import groovy.swing.SwingBuilder
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
def execThing ( String cmdStr ) {
def stdout = new ByteArrayOutputStream()
String prefix = System.getenv("GITCMDPREFIX")
if (prefix != null) {
String cmd = prefix + cmdStr
exec {
commandLine cmd.tokenize()
standardOutput = stdout
}
} else {
exec {
commandLine cmdStr.tokenize()
standardOutput = stdout
}
}
return stdout
}
def computeVersionName = { ->
String ver = "git-source"
try {
if (execThing(" git status -z").toString().trim().equals("")) {
return "git-" + execThing(' git log -1 --format="%h"').toString().trim()
} else {
return ver
}
} catch (all) {
println "Cannot run git (not in path?), using default versioning"
}
return ver
}
def getProps() {
Properties props = new Properties()
File f = new File("t9build.properties")
if (!f.exists()) {
f.createNewFile()
}
props.load(new FileInputStream(f))
return props
}
def saveProps(Properties props) {
props.store(new FileOutputStream(new File("t9build.properties")), null)
}
// -PincrementBuildNumber assembleRelease
def computeVersionNumber = { ->
Properties props = getProps()
int verNum = Integer.valueOf(props.getProperty("verNum", "0"))
if (project.hasProperty('incrementBuildNumber')) {
verNum++
}
props.setProperty("verNum", String.valueOf(verNum))
saveProps(props)
return verNum
}
android {
compileSdkVersion 8
buildToolsVersion "19.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
versionCode computeVersionNumber()
versionName computeVersionName()
}
// http://stackoverflow.com/a/19130098
signingConfigs {
release {
storeFile file(System.getenv("KEYSTORE"))
storePassword ''
keyAlias System.getenv("KEYALIAS")
keyPassword ''
}
}
buildTypes {
release {
signingConfig android.signingConfigs.release
// http://stackoverflow.com/a/24650026
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-release", "-" + android.defaultConfig.versionName)
)
}
}
}
}
}
task getDictSizes {
inputs.dir fileTree(dir:'assets', excludes:['dict.properties'])
outputs.file "t9build.properties"
doLast {
println "Calculating dict size..."
inputs.getFiles().each {File file ->
println "dict: "+ file.name
ant.propertyfile(file:"assets/dict.properties") {
entry(key: "size."+ file.name, value: file.length())
}
}
}
}
preBuild.dependsOn getDictSizes
preBuild.mustRunAfter getDictSizes
// https://www.timroes.de/2014/01/19/using-password-prompts-with-gradle-build-files/
def getPass(String msg) {
def pass = ''
if(System.console() == null) {
new SwingBuilder().edt {
dialog(modal: true, // Otherwise the build will continue running before you closed the dialog
title: 'Enter password', // Dialog title
alwaysOnTop: true, // pretty much what the name says
resizable: false, // Don't allow the user to resize the dialog
locationRelativeTo: null, // Place dialog in center of the screen
pack: true, // We need to pack the dialog (so it will take the size of it's children)
show: true // Let's show it
) {
vbox { // Put everything below each other
label(text: msg)
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = new String(input.password); // Set pass variable to value of input field
dispose(); // Close dialog
})
} // vbox end
} // dialog end
} // edt end
} else {
pass = System.console().readPassword("\nPlease enter key passphrase: ")
pass = new String(pass)
}
if(pass.size() <= 0) {
throw new InvalidUserDataException("You must enter a password to proceed.")
}
return pass
}
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':assembleRelease')) {
android.signingConfigs.release.storePassword = getPass("Please enter Key Store passphrase:")
android.signingConfigs.release.keyPassword = getPass("Please enter Key passphrase:")
} // end if has task
} // end whenReady