forked from cgeo/cgeo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
643 lines (547 loc) · 24.2 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
import org.apache.tools.ant.filters.ReplaceTokens
/*
* Run "gradlew" or "gradlew cgeoHelp" in the parent directory for a help of how to use this build file.
*/
/*
* Android plugin, http://developer.android.com/tools/building/plugin-for-gradle.html
*/
apply plugin: 'com.android.application'
/*
* https://github.com/KeepSafe/dexcount-gradle-plugin
* dex counting can take several seconds, therefore do this only on the CI server
*/
if (isContinuousIntegrationServer()) {
apply plugin: 'com.getkeepsafe.dexcount'
}
android {
compileSdkVersion 29 // TODO SAF: leave at 29 until done, change to 30 when done
compileOptions {
// use the diamond operator and some other goodies in Android
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
//noinspection OldTargetApi
targetSdkVersion 29 // TODO SAF: leave at 29 until done, change to 30 when done
versionName versionNameFromDate()
versionCode versionCodeFromDate(0)
// NOTE: must match the package in the test directory and must be different from the app package
testApplicationId "cgeo.geocaching.test"
//testHandlingProfiling true
testFunctionalTest true
// set the default test runner to be used by IDE and command line
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// by convention, the folder name "main" is used for the APK file name. we want cgeo instead
archivesBaseName = "cgeo"
// this is necessary to move .google_measurement_service into a app-specific namespace (see https://github.com/kotmyrevich/analytics-issues/issues/784)
applicationId = "cgeo.geocaching"
// include only those language resources from libraries which we actively maintain ourselves in the translation project at https://crowdin.com/project/cgeo
// not yet enough translations (~50%): "is","iw"(="he"),"lb"
def locales = [ "en","ar","ca","ceb","cs","da","de","el","es","fi","fil","fr","hu","in","it","ja","ko","lt","lv","nb","nl","pl","pt","ro","ru","sk","sl","sv","tl","tr","uk","zh","zh-rTW" ]
// needed for in-app language selector
buildConfigField "String[]", "TRANSLATION_ARRAY", "new String[]{\""+locales.join("\",\"")+"\"}"
resConfigs locales
}
// signing is handled via private.properties
signingConfigs {
release
}
buildFeatures {
viewBinding true
}
buildTypes {
debug {
// debug build name contains git commit for better reproduction of bugs
versionNameSuffix "-" + GitCommit.currentShort() + " developer build"
// additional proguard rules just for the test code
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', '../tests/proguard-project.txt'
// code coverage
testCoverageEnabled isContinuousIntegrationServer()
// replace in AndroidManifest.xml
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher_debug",
appIconRound: "@mipmap/ic_launcher_debug_round"
]
}
nightly {
def nightlyName = System.getenv('NB') // NB, NB1, ...
versionNameSuffix "-$nightlyName-" + GitCommit.currentShort()
signingConfig signingConfigs.release
// use release version of source code library dependencies
matchingFallbacks = ['release']
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher_nightly",
appIconRound: "@mipmap/ic_launcher_nightly_round"
]
}
rc {
def rcName = System.getenv('RC') // RC, RC1, RC2 ...
versionNameSuffix "-$rcName"
signingConfig signingConfigs.release
// use release version of source code library dependencies
matchingFallbacks = ['release']
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher_rc",
appIconRound: "@mipmap/ic_launcher_rc_round"
]
}
legacy {
signingConfig signingConfigs.release
// use release version of source code library dependencies
matchingFallbacks = ['release']
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher",
appIconRound: "@mipmap/ic_launcher_round"
]
}
release {
signingConfig signingConfigs.release
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher",
appIconRound: "@mipmap/ic_launcher_round"
]
}
}
buildTypes.all { buildType ->
// enable proguard and remove unused code
minifyEnabled true
// remove unused resources in addition to unused code
shrinkResources true
// proguard rules
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
testBuildType "debug" //the default BuildType
sourceSets {
// application sources in source set "main"
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'thirdparty', '../common/src'] // no need for annotation generated sources
res.srcDirs = ['res']
assets.srcDirs = ['assets']
aidl.srcDirs = ['src'] // default src/main/aidl creates package name conflicts in Eclipse
jni.srcDirs = []
}
// local unit tests, which can be executed without a device
test {
setRoot("../tests")
manifest.srcFile '../tests/AndroidManifest.xml'
java.srcDir '../tests/src'
resources.srcDirs = ['../tests/src']
res.srcDirs = ['../tests/res']
}
// device/emulator based instrumentation tests in source set "androidTest"
androidTest{
// map tests to the Eclipse style test project instead of the default app/src/androidTest/java
setRoot("../tests")
manifest.srcFile '../tests/AndroidManifest.xml'
java {
srcDir '../tests/src-android'
}
resources.srcDirs = ['../tests/src']
res.srcDirs = ['../tests/res']
}
// TODO: the package cgeo.geocaching.test.mock is currently duplicated in both "src" and "src-android". if a shared source folder is used instead, then we get java.lang.VerificationExceptions, because the 2 unit test frameworks modify the classes in different ways
}
testOptions {
resultsDir = "$project.buildDir/build/test-results"
}
lintOptions {
// we do not accept lint errors when building
abortOnError true
// Warnings shall not fail build
warningsAsErrors false
// abort release builds in case of FATAL errors
checkReleaseBuilds true
absolutePaths false
// ExtraTranslation - old translation will be deleted by the next crowdin import
disable 'ExtraTranslation'
// deactivate this rule only on CI
// see https://github.com/cgeo/cgeo/issues/9224
// Resource IDs will be non-final in Android Gradle Plugin version 5.0
if (isContinuousIntegrationServer()) {
disable 'NonConstantResourceId'
}
}
packagingOptions {
// you can double click an APK file in Android Studio 2.2+ to see what's in there
// license files of libs are not needed in our APK
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'COPYING'
exclude 'COPYING.LESSER'
exclude '.readme'
// AndroidAnnotations
exclude 'androidannotations-api.properties'
// mapsforge
exclude 'META-INF/maven/org.mapsforge/mapsforge-map-reader/pom.properties'
exclude 'META-INF/maven/org.mapsforge/mapsforge-map-reader/pom.xml'
exclude 'META-INF/maven/org.mapsforge/mapsforge-map/pom.properties'
exclude 'META-INF/maven/org.mapsforge/mapsforge-map/pom.xml'
exclude 'COPYING.LESSER.v3'
exclude 'COPYING.v3'
// Play Services
exclude 'build-data.properties'
// rxjava
exclude 'META-INF/rxandroid.properties'
exclude 'META-INF/rxjava.properties'
}
flavorDimensions "javaCompilerTime" // all flavours must be assigned a dimension
productFlavors {
// make sure to not have any flavour lexicographically smaller than "basic". Android Studio takes the first alphabetical flavor in new installations.
basic {
dimension "javaCompilerTime"
buildConfigField "String", "SPECIAL_BUILD", '""'
}
nojit {
dimension "javaCompilerTime"
buildConfigField "String", "SPECIAL_BUILD", '"Disabled JIT"'
}
}
// remove the "-basic" flavour name from the generated APK, have the flavor remain only for special builds
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = outputFileName.replace('-basic-', '-')
}
}
// special version code for nightly and rc builds
applicationVariants.all { variant ->
if (variant.buildType.name == 'nightly') {
variant.outputs.all {
setVersionCodeOverride(versionCodeFromDate(10000000))
}
}
if (variant.buildType.name == 'rc') {
variant.outputs.all {
setVersionCodeOverride(versionCodeFromDate(-1))
}
}
if (variant.buildType.name == 'legacy') {
def legacyName = System.getenv('LEGACY_VERSION_NAME')
def legacyVersion = System.getenv('LEGACY_VERSION_CODE') as Integer
if (legacyName != null && legacyVersion != null) {
variant.outputs.all {
setVersionNameOverride(legacyName)
setVersionCodeOverride(legacyVersion)
}
}
}
// debug and release builds have offset zero, no special handling here
}
// tests rely on JUnit-based classes
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
}
dependencies {
// AndroidAnnotations, https://github.com/excilys/androidannotations/wiki/building-project-gradle
def androidAnnotationsVersion = '4.8.0'
annotationProcessor "org.androidannotations:androidannotations:$androidAnnotationsVersion"
implementation "org.androidannotations:androidannotations-api:$androidAnnotationsVersion"
// Apache Commons
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'org.apache.commons:commons-compress:1.20'
implementation 'org.apache.commons:commons-lang3:3.11'
implementation 'org.apache.commons:commons-text:1.9'
// commons-io 2.6 uses java.nio.file.Path - which is first contained in Android API26
// could be replaced by Storage Access Framework
//noinspection GradleDependency
implementation 'commons-io:commons-io:2.5'
// AssertJ for testing, needed both for local unit tests and Android instrumentation tests
def assertJVersion = '2.9.1'
testImplementation "org.assertj:assertj-core:$assertJVersion"
androidTestImplementation "org.assertj:assertj-core:$assertJVersion"
// SpotBugs (successor of FindBugs)
implementation 'net.jcip:jcip-annotations:1.0'
implementation 'com.github.spotbugs:spotbugs-annotations:4.2.1'
// GeographicLib
implementation 'net.sf.geographiclib:GeographicLib-Java:1.51'
// Jackson XML processing
def jacksonVersion = '2.12.3'
implementation "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
implementation "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
// Jsoup HTML parsing
implementation 'org.jsoup:jsoup:1.13.1'
// Junit only needed for local unit tests
testImplementation 'junit:junit:4.13.2'
// Leak Canary, memory leak detection
def leakCanaryVersion = '2.7'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
implementation "com.squareup.leakcanary:plumber-android:$leakCanaryVersion"
// Locus Maps integration
implementation "com.asamm:locus-api-android:0.9.32"
// Mapsforge new version
def mapsforgeVersion = '905e9d48bb' // master as of 31.3.21, see https://jitpack.io/#mapsforge/mapsforge
implementation "com.github.mapsforge.mapsforge:mapsforge-core:$mapsforgeVersion"
implementation "com.github.mapsforge.mapsforge:mapsforge-map:$mapsforgeVersion"
implementation "com.github.mapsforge.mapsforge:mapsforge-map-android:$mapsforgeVersion"
implementation "com.github.mapsforge.mapsforge:mapsforge-map-reader:$mapsforgeVersion"
implementation "com.github.mapsforge.mapsforge:mapsforge-themes:$mapsforgeVersion"
/* previous declaration - version 0.15.0
implementation "org.mapsforge:mapsforge-core:$mapsforgeVersion"
implementation "org.mapsforge:mapsforge-map:$mapsforgeVersion"
implementation "org.mapsforge:mapsforge-map-android:$mapsforgeVersion"
implementation "org.mapsforge:mapsforge-map-reader:$mapsforgeVersion"
implementation "org.mapsforge:mapsforge-themes:$mapsforgeVersion"
*/
configurations {
all*.exclude group: 'net.sf.kxml', module: 'kxml2' // duplicate XmlPullParser class
}
// used by mapsforge
implementation 'com.caverock:androidsvg:1.4'
// Maps.ME integration
implementation project(":mapswithme-api")
// Metadata Extractor, EXIF location extraction from images
implementation 'com.drewnoakes:metadata-extractor:2.16.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
// Play Services
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
// somehow there is a transitive play service dependency which we don't want
configurations.all*.exclude module: "play-services-measurement"
// Support Library Design
implementation 'com.google.android.material:material:1.3.0'
// ProcessPhoenix, reliable process restart
implementation 'com.jakewharton:process-phoenix:2.0.0'
// RxJava
implementation 'io.reactivex.rxjava3:rxjava:3.0.12'
implementation "io.reactivex.rxjava3:rxandroid:3.0.0"
// Support Library AppCompat
implementation 'androidx.appcompat:appcompat:1.2.0'
// Support Library core (used for eg. HtmlCompat)
implementation 'androidx.core:core:1.3.2'
// Support Library ExifInterface
implementation 'androidx.exifinterface:exifinterface:1.3.2'
// Support Library GridLayout used by the coordinate calculator
implementation 'androidx.gridlayout:gridlayout:1.0.0'
// Support Library RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.0'
// Support Annotations. use same version for the main app and the test app
def annotationVersion = '1.2.0'
implementation "androidx.annotation:annotation:$annotationVersion"
androidTestImplementation "androidx.annotation:annotation:$annotationVersion"
// Testing Support Libraries
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Drag n drop for listview
implementation 'asia.ivity.android:drag-sort-listview:1.0'
// needed for chrome custom tabs
implementation 'androidx.browser:browser:1.3.0'
// ViewPagerIndicator, view pager titles for cache details and similar view pager based activities
// this is a fork of the original viewpager library
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
// Zxing barcode reader integration
implementation 'com.google.zxing:android-integration:3.3.0'
// MarkDown view
def markwonVersion = '4.6.2';
implementation "io.noties.markwon:core:${markwonVersion}"
}
/*
* un-mocking of Android classes that don't depend on the Android device, but are portable Java only, like SparseArray
*/
apply plugin: 'de.mobilej.unmock'
/*
* verify existence of the necessary keys for compilation, instead of waiting for a compile error
*/
project.afterEvaluate{
preBuild.dependsOn("verifyCgeoKeys")
}
tasks.register('verifyCgeoKeys') {
group = 'verification'
description = 'Checks for the existence of keys.xml to successfully compile cgeo.'
doFirst {
def keysFile = file("res/values/keys.xml")
if (!keysFile.exists()) {
// copy keys from private.properties to keys.xml. used by the CI server at least
def propertiesFile = rootProject.file("private.properties")
if (propertiesFile.exists()) {
copy {
from "templates/keys.xml"
into ("res/values")
def properties = new Properties()
propertiesFile.withInputStream {
properties.load(it)
}
filter(ReplaceTokens, tokens: properties)
filter { it.replaceAll("@.+?@", "") }
}
}
}
if (!keysFile.exists()) {
throw new InvalidUserDataException("You must provide API keys for c:geo to compile successfully. Please read the 'API keys' section in the README.md file for further details.")
}
}
}
/*
* version number from the current date, plus an offset defined by the build type (to define which versions overwrite each other)
*/
static def versionCodeFromDate(offset) {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return Integer.valueOf(formattedDate) + offset
}
/*
* version name based on current date
*/
static def versionNameFromDate() {
def date = new Date()
def formattedDate = date.format('yyyy.MM.dd')
return formattedDate
}
class GitCommit {
static String commitId
/*
* get the most recent git commit ID
*/
static String current() {
if (commitId == null) {
Process p = ['git', 'rev-parse', 'HEAD'].execute()
if (p.waitFor() != 0) {
throw new Error("Unable to get git commit id: " + p.err.text)
}
commitId = p.text.trim()
}
return commitId
}
static String currentShort() {
return current().substring(0, 7)
}
}
/*
* check whether this is a local build or a CI server build
*/
static def isContinuousIntegrationServer() {
return System.getenv('BUILD_NUMBER') != null
}
/*
* have a run task for our builds to launch the app directly from gradle
*/
android.applicationVariants.all { variant ->
if (variant.installProvider) {
tasks.register("run${variant.name.capitalize()}") {
group 'cgeo'
description "Installs the ${variant.description} and runs the main activity. Depends on 'adb' being on the PATH."
dependsOn tasks.named(variant.installProvider.name)
doFirst {
def classpath = variant.applicationId
if (variant.buildType.applicationIdSuffix) {
classpath -= "${variant.buildType.applicationIdSuffix}"
}
def launchClass = "${variant.applicationId}/${classpath}.MainActivity"
try {
project.exec {
executable = project.android.getAdbExe().toString()
args = ['shell', 'am', 'start', '-n', launchClass]
}
}
catch (RuntimeException e) {
throw new IllegalStateException("Cannot execute 'adb'. Please add %ANDROID_HOME%\\platform-tools to the PATH environment variable and restart your IDE", e)
}
}
}
}
}
// run device and non device tests together with one task. also fixes the bug that gradle optimizes tests away in repeated runs
// This uses eager task creation API.
tasks.create('testDebug') {
group 'verification'
description "Tests the debug build both with device-dependent and device-independent tests."
dependsOn 'testBasicDebugUnitTest', 'connectedBasicDebugAndroidTest'
}
/*
* signing of release APK, use a properties file like in templates/private.properties
*/
// dynamically load the signing values from private.properties
File privatePropertiesFile = rootProject.file('private.properties')
if (privatePropertiesFile.exists()) {
Properties properties = new Properties()
properties.load(new FileInputStream(privatePropertiesFile))
android.signingConfigs {
release {
storeFile file(properties.getProperty('key.store'))
storePassword properties.getProperty('key.store.password')
keyAlias properties.getProperty('key.alias')
keyPassword properties.getProperty('key.alias.password')
}
}
android.buildTypes.release.signingConfig android.signingConfigs.release
}
// check existence of private properties, show an error message
tasks.register('verifyPrivateProperties') {
doLast {
if (!rootProject.file('private.properties').exists()) {
throw new InvalidUserDataException("For signing the release build you must provide a file private.properties in the root directory. Copy templates/private.properties and change the values.")
}
}
}
// copy preferences containing user and password to the device
tasks.register('copyDefaultPreferencesToAndroid') {
dependsOn 'installBasicDebug'
doFirst {
def preferences = file('cgeo.geocaching_preferences.xml')
if (preferences.exists()) {
try {
project.exec {
executable = project.android.getAdbExe().toString()
args = ['push', 'cgeo.geocaching_preferences.xml', '/data/local/tmp/cgeo.geocaching_preferences.xml']
}
project.exec {
executable = project.android.getAdbExe().toString()
args = ['shell', 'run-as', 'cgeo.geocaching', 'mkdir', '/data/data/cgeo.geocaching/shared_prefs/']
}
project.exec {
executable = project.android.getAdbExe().toString()
args = ['shell', 'run-as', 'cgeo.geocaching', 'cp', '/data/local/tmp/cgeo.geocaching_preferences.xml', '/data/data/cgeo.geocaching/shared_prefs/cgeo.geocaching_preferences.xml']
}
project.exec {
executable = project.android.getAdbExe().toString()
args = ['shell', 'run-as', 'cgeo.geocaching', 'ls', '-l', '/data/data/cgeo.geocaching/shared_prefs/']
}
project.exec {
executable = project.android.getAdbExe().toString()
args = ['shell', 'getprop', 'ro.build.version.release']
}
}
// we might not actually have permission to copy the preferences on actual devices, let's continue running the app then
catch (RuntimeException e) {
print(e.message)
}
}
}
}
tasks.whenTaskAdded { theTask ->
// only verify the existence of private.properties, when the file is really needed
if (theTask.name == "packageRelease") {
theTask.dependsOn "verifyPrivateProperties"
}
// copy default preferences before starting the app
if (theTask.name == "runBasicDebug" || theTask.name == "connectedBasicDebugAndroidTest") {
theTask.dependsOn "copyDefaultPreferencesToAndroid"
}
}
/*
* own checkstyle configuration
* Android plugin doesn't interoperate with the Checkstyle plugin
*/
apply plugin: 'checkstyle'
tasks.register('checkstyle', Checkstyle) {
group 'verification'
description 'Check code standard'
configFile file("${project.rootDir}/checkstyle.xml")
source 'src'
source '../tests/src'
source '../tests/src-android'
include '**/*.java'
classpath = files()
}
tasks.named('check') {
dependsOn tasks.named('checkstyle')
}