forked from medic/cht-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
430 lines (361 loc) · 11.9 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
buildscript {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://plugins.gradle.org/m2/' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.5'
}
}
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.github.spotbugs'
apply from: 'coverage.gradle'
// enable verbose lint warnings
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:deprecation'
}
}
task checkstyle(type: Checkstyle) {
description 'Check code standard'
group 'verification'
configFile file('config/checkstyle.xml')
source 'src'
classpath = files()
ignoreFailures = false
}
task pmd(type: Pmd) {
ruleSetFiles = files('config/pmd.xml')
ruleSets = []
ignoreFailures = false
source 'src'
exclude '**/**.png'
exclude '**/**.mp3'
exclude '**/**.bats'
dependencies {
pmd 'net.sourceforge.pmd:pmd-java:6.44.0'
pmd 'net.sourceforge.pmd:pmd-xml:6.44.0'
}
}
spotbugs {
ignoreFailures = false
showStackTraces = true
showProgress = true
effort = 'default'
reportLevel = 'default'
maxHeapSize = '1g'
omitVisitors = [
'FindReturnRef' // This app exchanges data with external applications, we assume is safe.
]
onlyAnalyze = [ 'org.medicmobile.webapp.mobile.*' ]
}
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
google()
flatDir {
dirs 'libs'
}
}
def getVersionCode = {
int versionCode = 2
if (System.env.CI == 'true' && System.env.RELEASE_VERSION && System.env.RELEASE_VERSION.startsWith('v')) {
def versionParts = System.env.RELEASE_VERSION.split(/[^0-9]+/)
if (versionParts.length != 4 && versionParts.length != 5)
throw new RuntimeException("Unexpected version number - should be of formatted as 'v1.2.3' or 'v1.2.3-alpha.4', but was: $System.env.RELEASE_VERSION")
versionParts = versionParts.drop(1).collect { Integer.parseInt(it) }
int alphaPart = versionParts.size() == 4 ? versionParts[3] : 99
if (versionParts[1] > 99 || versionParts[2] > 99 || alphaPart > 99)
throw new RuntimeException('Version part greater than 99 not allowed.')
versionCode = (100 * 100 * 100 * versionParts[0]) + (100 * 100 * versionParts[1]) + (100 * versionParts[2]) + alphaPart
if (versionCode > 2100000000 / 10)
throw new RuntimeException('versionCode bigger than max allowed by Google Play.')
}
return versionCode * 10
}
def getVersionName = {
System.env.RELEASE_VERSION ?: 'SNAPSHOT'
}
android {
compileSdkVersion 33
buildToolsVersion '30.0.3'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
//noinspection OldTargetApi
targetSdkVersion 33
minSdkVersion 21 // Android 5.0
versionCode getVersionCode()
versionName getVersionName()
archivesBaseName = "${project.name}-${versionName}"
//For espresso tests
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Test user credentials
buildConfigField "String", "TEST_USERNAME", "\"${System.env.ANDROID_TEST_USERNAME}\""
buildConfigField "String", "TEST_PASSWORD", "\"${System.env.ANDROID_TEST_PASSWORD}\""
buildConfigField "boolean", "IS_TRAINING_APP", 'false'
if (System.env.ANDROID_TEST_URL) {
buildConfigField "String", "SERVER_URL", "\"${System.env.ANDROID_TEST_URL}\""
} else {
buildConfigField "String", "SERVER_URL", '"https://gamma-cht.dev.medicmobile.org"'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
}
applicationVariants.all { variant ->
buildConfigField "String", "LOG_TAG", '"MedicMobile"'
buildConfigField "Long", "TTL_LAST_URL", '24l * 60 * 60 * 1000' // 24 hs max time last URL loaded is remembered
// Every APK requires a unique version code.
// So when compiling multiple APKS for the different ABIs, use the first digit
variant.outputs.each { output ->
def versionAugmentation = (output.getFilter(com.android.build.OutputFile.ABI) == 'arm64-v8a') ? 1 : 0
output.versionCodeOverride = variant.versionCode * 10 + versionAugmentation
}
}
signingConfigs {
release {
storeFile file(System.env.ANDROID_KEYSTORE_PATH ?: signingConfigs.debug.storeFile)
storePassword System.env.ANDROID_KEYSTORE_PASSWORD ?: signingConfigs.debug.storePassword
keyAlias System.env.ANDROID_KEY_ALIAS ?: signingConfigs.debug.keyAlias
keyPassword System.env.ANDROID_KEY_PASSWORD ?: signingConfigs.debug.keyPassword
}
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
shrinkResources true
signingConfig signingConfigs.release
}
}
lintOptions {
lintConfig = new File('config/lint.xml')
disable 'UnusedResources' // linter can't handle static imports, so just skip this test
disable 'MissingTranslation'
disable 'StringFormatCount'
warningsAsErrors true
xmlReport false
if (System.env.CI == 'true') {
abortOnError true
htmlReport false
textReport true
textOutput 'stdout'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
flavorDimensions 'brand'
productFlavors {
unbranded {
// we will not create project-specific src directories
// for `unbranded` - it will use the defaults in
// src/main
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile'
}
medicmobiledemo {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.medicmobiledemo'
}
medicmobilegamma {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.medicmobilegamma'
}
medicmobilegamma_training {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.medicmobilegamma_training'
buildConfigField "boolean", "IS_TRAINING_APP", 'true'
}
bracuganda {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.bracuganda'
}
cic_guatemala {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.cic_guatemala'
}
cmmb_kenya {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.cmmb_kenya'
}
ebpp_indonesia {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.ebpp_indonesia'
}
hope_through_health {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.hope_through_health'
}
livinggoods {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.livinggoods'
}
livinggoodskenya {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.livinggoodskenya'
}
livinggoods_assisted_networks {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.livinggoods_assisted_networks'
}
livinggoods_innovation_ke_supervisor {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.livinggoods_innovation_ke_supervisor'
}
livinggoods_innovation_ke_hivst {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.livinggoods_innovation_ke_hivst'
}
moh_kenya_siaya_white {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_kenya_siaya'
}
moh_kenya_siaya_red {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_kenya_siaya_red'
}
moh_kenya_siaya_green {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_kenya_siaya_green'
}
moh_kenya_siaya_black {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_kenya_siaya_black'
}
moh_mali {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_mali'
}
moh_zanzibar_training {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_zanzibar_training'
}
moh_zanzibar {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_zanzibar'
}
musomali {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.musomali'
}
pih_malawi {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.pih_malawi'
}
pih_malawi_supervisor {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.pih_malawi_supervisor'
}
safaridoctors_kenya {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.safaridoctors_kenya'
}
vhw_burundi {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.vhw_burundi'
}
surveillance_covid19_kenya {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.surveillance_covid19_kenya'
}
trippleeighty {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.trippleeighty'
}
covid_moh_mali {
dimension = 'brand'
applicationId = "org.medicmobile.webapp.mobile.covid_moh_mali"
}
icm_ph_chc {
dimension = 'brand'
applicationId = "org.medicmobile.webapp.mobile.icm_ph_chc"
}
vhtapp_uganda {
dimension = 'brand'
applicationId = "org.medicmobile.webapp.mobile.vhtapp_uganda"
}
itech_aurum {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.itech_aurum'
}
itech_malawi {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.itech_malawi'
}
alerte_niger {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.alerte_niger'
}
chis_ne {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.chis_ne'
}
cht_rci {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.cht_rci'
}
moh_mali_chw {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_mali_chw'
}
moh_niger_chw {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_niger_chw'
}
moh_kenya_echis {
dimension = 'brand'
applicationId = 'org.medicmobile.webapp.mobile.moh_kenya_echis'
}
}
splits {
abi {
enable !project.hasProperty('abi')
reset()
include(
'armeabi-v7a',
'arm64-v8a',
//'x86_64', //--> uncomment to be able to deploy the app in
//'x86', //--> Android virtual devices
)
universalApk false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.core:core:1.7.0'
implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.fragment:fragment:1.4.1'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.5.3'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.0.0'
testImplementation 'com.google.android:android-test:4.1.1.4'
testImplementation 'org.robolectric:robolectric:4.7'
testImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha05'
testImplementation 'androidx.test.espresso:espresso-intents:3.5.0-alpha05'
testImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.5.0-alpha05'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:core:1.4.0'
androidTestImplementation 'org.hamcrest:hamcrest-library:2.2'
}