forked from mozilla/MozStumbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
288 lines (232 loc) · 8.66 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// each of the version numbers must be 0-99
def versionMajor = 1
def versionMinor = 2 // minor feature releases
def versionPatch = 0 // This should be bumped for hot fixes
def versionBuild = 0 // This is used to denote which release
// flavor is used (github/playstore/fdroid)
// Double check the versioning
for (versionPart in [versionBuild, versionPatch, versionMinor, versionMajor]) {
assert 0 <= versionPart
assert versionPart <= 99
}
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+'
// Gradle download task is from: https://github.com/michel-kraemer/gradle-download-task
classpath 'de.undercouch:gradle-download-task:1.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
ivy {
url 'http://mozilla-services.github.io/ivy-repo'
}
}
import de.undercouch.gradle.tasks.download.Download
import java.util.regex.Pattern
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
}
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
// I'm so happy I have to compute the versionCode, versionName
// and then duplicate it in the manifest. yay android.
writeVersionCode(versionCode)
writeVersionName(versionName)
buildConfigField "boolean", "ROBOLECTRIC", "false"
buildConfigField "String", "MOZILLA_API_KEY", getMozillaApiKey()
buildConfigField "String", "TILE_SERVER_URL", getTileServerUrl()
buildConfigField "boolean", "LABEL_MAP_TILES", "false"
buildConfigField "boolean", "GITHUB", "false"
buildConfigField "boolean", "PLAYSTORE", "false"
// Crash report settings
buildConfigField "String", "ACRA_URI", getAcraURI()
buildConfigField "String", "ACRA_USER", getAcraUser()
buildConfigField "String", "ACRA_PASS", getAcraPass()
}
signingConfigs {
release
}
buildTypes {
debug {
jniDebugBuild true
// set this to false if you want your debug builds to have
// standard unlabelled tiles.
buildConfigField "boolean", "LABEL_MAP_TILES", "false"
}
release {
runProguard true
proguardFile 'proguard.cfg'
signingConfig signingConfigs.release
}
github.initWith(buildTypes.release)
github {
buildConfigField "boolean", "GITHUB", "true"
}
playstore.initWith(buildTypes.release)
playstore {
buildConfigField "boolean", "PLAYSTORE", "true"
}
unittest.initWith(buildTypes.debug)
unittest {
buildConfigField "boolean", "ROBOLECTRIC", "true"
}
}
sourceSets {
androidTest.setRoot('src/test')
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
}
dependencies {
androidTestCompile 'junit:junit:4.10'
androidTestCompile 'org.robolectric:robolectric:2.3'
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3'
compile 'com.crankycoder:SimpleKML:1.0'
compile 'org.slf4j:slf4j-android:1.7.7'
compile 'com.ocpsoft:ocpsoft-pretty-time:1.0.7'
// https://developer.android.com/tools/support-library/features.html
// In general, we recommend including the v4 support and v7 appcompat
// libraries, because they support a wide range of Android versions and
// provide APIs for recommended user interface patterns.
compile "com.android.support:support-v4:19.1.+"
compile 'com.android.support:appcompat-v7:19.1.0'
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
compile "joda-time:joda-time:2.2"
// Acralyzer crash reports
compile 'ch.acra:acra:4.5.0'
// osmdroid stuff
compile "org.apache.httpcomponents:httpmime:4.0.1"
compile "org.apache.james:apache-mime4j:0.6"
}
tasks.withType(JavaCompile) {
options.compilerArgs = ['-Xlint:all', '-Werror', '-Xlint:-deprecation']
}
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
android.signingConfigs.release.storeFile = rootProject.file(p.StoreFile)
android.signingConfigs.release.storePassword = p.StorePassword
android.signingConfigs.release.keyAlias = p.KeyAlias
android.signingConfigs.release.keyPassword = p.KeyPassword
} else {
println "No private.properties file was found.";
android.buildTypes.release.signingConfig = null
}
String getAcraURI() {
// Yeah, this is lame, opening the file again. Sosume.
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
if (p['ACRA_URI'] == null) {
return '""';
}
return '"' + p['ACRA_URI'] + '"'
}
return '""';
}
String getAcraUser() {
// Yeah, this is lame, opening the file again. Sosume.
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
if (p['ACRA_USER'] == null) {
return '""';
}
return '"' + p['ACRA_USER'] + '"'
}
return '""';
}
String getAcraPass() {
// Yeah, this is lame, opening the file again. Sosume.
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
if (p['ACRA_PASS'] == null) {
return '""';
}
return '"' + p['ACRA_PASS'] + '"'
}
return '""';
}
String getMozillaApiKey() {
// Yeah, this is lame, opening the file again. Sosume.
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
def result = '"' + p['MozAPIKey'] + '"';
println "Writing custom MozAPIKey: ["+result+"]";
return result;
}
println "No private.properties for Mozilla API Key configuration.."
return "null";
}
String getTileServerUrl() {
// Yeah, this is lame, opening the file again. Sosume.
File signFile = rootProject.file('private.properties')
if (signFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(signFile))
if (p['TileServerURL']) {
def result = '"' + p['TileServerURL'] + '"';
println "Using custom TileServerURL: ["+result+"]";
return result;
} else if (p['MapAPIKey']) {
def result = "\"http://api.tiles.mapbox.com/v3/${p['MapAPIKey']}/\"";
println "Using MapAPIKey: ["+result+"]";
return result;
}
}
println "No private.properties for TileServer configuration."
return "null";
}
void writeVersionCode(int versionCode) {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def manifestContent = matcher.replaceAll("versionCode=\"" + versionCode + "\"")
manifestFile.write(manifestContent)
}
void writeVersionName(String versionName) {
def manifestFile = file("src/main/AndroidManifest.xml")
def patternVersionNumber = Pattern.compile("versionName=\"[^\"]*\"")
def manifestText = manifestFile.getText()
def matcherVersionNumber = patternVersionNumber.matcher(manifestText)
def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + versionName + "\"")
manifestFile.write(manifestContent)
}
// Yay for apk basenames that you can only figure out by reading the
// gradle source.
project.archivesBaseName = "MozStumbler";