forked from owntracks/android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
317 lines (267 loc) · 12.3 KB
/
build.gradle.kts
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
plugins {
id("com.android.application")
id("com.github.triplet.play") version "3.1.0"
kotlin("android")
kotlin("kapt")
id("io.objectbox")
id("com.hiya.jacoco-android")
id("scabbard.gradle") version "0.4.0"
}
val versionMajor = 2
val versionMinor = 3
val versionPatch = 0
//TODO need to increment this manually at the moment, as GPP is broken
val versionBuild = 0 // This value is managed by the gradle publisher plugin. Build numbers get incremented on publish
val googleMapsAPIKey = extra.get("google_maps_api_key")?.toString() ?: "PLACEHOLDER_API_KEY"
android {
compileSdkVersion(30)
defaultConfig {
applicationId = "org.owntracks.android"
minSdkVersion(21)
targetSdkVersion(30)
versionCode = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
javaCompileOptions {
annotationProcessorOptions {
arguments(mapOf("eventBusIndex" to "org.owntracks.android.EventBusIndex"))
}
}
resConfigs("en", "de", "fr", "es", "ru", "ca")
testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
/* TODO Get this lot sorted when the orchestrator / coverage / clearPackageData bug gets fixed */
// testInstrumentationRunnerArguments clearPackageData: "true"
// testInstrumentationRunnerArguments coverageFilePath: "/sdcard/"
// testInstrumentationRunnerArguments coverage: "true"
}
signingConfigs {
register("release") {
keyAlias = "upload"
keyPassword = System.getenv("KEYSTORE_PASSPHRASE")
storeFile = file("../owntracks.release.keystore.jks")
storePassword = System.getenv("KEYSTORE_PASSPHRASE")
}
}
buildTypes {
named("release") {
isMinifyEnabled = true
isShrinkResources = true
isZipAlignEnabled = true
proguardFiles = mutableListOf(getDefaultProguardFile("proguard-android.txt"), file("proguard-rules.pro"))
resValue("string", "GOOGLE_MAPS_API_KEY", googleMapsAPIKey)
signingConfig = signingConfigs.findByName("release")
}
named("debug") {
isMinifyEnabled = false
isShrinkResources = false
isZipAlignEnabled = true
proguardFiles = mutableListOf(getDefaultProguardFile("proguard-android.txt"), file("proguard-rules.pro"))
resValue("string", "GOOGLE_MAPS_API_KEY", googleMapsAPIKey)
applicationIdSuffix = ".debug"
isTestCoverageEnabled = true
}
}
buildFeatures {
dataBinding = true
viewBinding = true
}
packagingOptions {
exclude("META-INF/DEPENDENCIES.txt")
exclude("META-INF/LICENSE.txt")
exclude("META-INF/NOTICE.txt")
exclude("META-INF/NOTICE")
exclude("META-INF/LICENSE")
exclude("META-INF/DEPENDENCIES")
exclude("META-INF/notice.txt")
exclude("META-INF/license.txt")
exclude("META-INF/dependencies.txt")
exclude("META-INF/LGPL2.1")
exclude("META-INF/proguard/androidx-annotations.pro")
}
lintOptions {
baselineFile = file("../../lint/lint-baseline.xml")
isCheckAllWarnings = true
isWarningsAsErrors = false
isAbortOnError = false
disable("TypographyFractions", "TypographyQuotes", "Typos", "UnsafeExperimentalUsageError", "UnsafeExperimentalUsageWarning")
}
testOptions {
animationsDisabled = true
unitTests {
isIncludeAndroidResources = true
isIncludeAndroidResources = true
}
// execution "ANDROIDX_TEST_ORCHESTRATOR"
}
tasks.withType<Test> {
testLogging {
events("passed", "skipped", "failed")
setExceptionFormat("full")
}
reports.junitXml.isEnabled = true
reports.html.isEnabled = false
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
buildToolsVersion = "29.0.3"
}
kapt {
correctErrorTypes = true
}
val daggerVersion = "2.33"
val okHttpVersion = "4.9.1"
val jacksonVersion = "2.12.2"
val materialDialogsVersion = "0.9.6.0"
val espressoVersion = "3.3.0"
val androidxTestVersion = "1.3.0"
val kotlinCoroutinesVersion = "1.4.3-native-mt"
dependencies {
implementation("androidx.preference:preference:1.1.1")
implementation("com.takisoft.preferencex:preferencex:1.1.0")
implementation("com.google.android.material:material:1.3.0")
implementation("androidx.work:work-runtime:2.5.0")
// Explicit dependency on conscrypt to give up-to-date TLS support on all devices
implementation("org.conscrypt:conscrypt-android:2.5.1")
// Play Services libraries
implementation("com.google.android.gms:play-services-maps:17.0.0")
implementation("com.google.android.gms:play-services-location:18.0.0")
// Utility libraries
implementation("com.google.dagger:dagger:${daggerVersion}")
implementation("com.google.dagger:dagger-android-support:${daggerVersion}")
implementation("com.google.dagger:dagger-android:${daggerVersion}")
implementation("org.greenrobot:eventbus:3.2.0")
implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5")
implementation("com.squareup.okhttp3:okhttp:${okHttpVersion}")
implementation("com.squareup.okhttp3:logging-interceptor:${okHttpVersion}")
implementation("com.fasterxml.jackson.core:jackson-core:${jacksonVersion}")
implementation("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${jacksonVersion}")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCoroutinesVersion}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${kotlinCoroutinesVersion}")
implementation("com.jakewharton.timber:timber:4.7.1")
implementation("com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.2")
implementation("org.apache.httpcomponents.core5:httpcore5:5.1")
implementation("commons-codec:commons-codec:1.15")
implementation("org.threeten:threetenbp:1.5.0")
implementation("com.github.joschi.jackson:jackson-datatype-threetenbp:$jacksonVersion")
// Widget libraries
implementation("com.rengwuxian.materialedittext:library:2.1.4")
implementation("com.mikepenz:materialdrawer:6.1.2@aar") { isTransitive = true }
implementation("com.mikepenz:materialize:1.2.1@aar")
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.test.espresso:espresso-idling-resource:${espressoVersion}")
// These Java EE libs are no longer included in JDKs, so we include explicitly
kapt("javax.xml.bind:jaxb-api:2.3.1")
kapt("com.sun.xml.bind:jaxb-core:2.3.0.1")
kapt("com.sun.xml.bind:jaxb-impl:2.3.2")
// Preprocessors
kapt("org.greenrobot:eventbus-annotation-processor:3.2.0")
kapt("com.google.dagger:dagger-compiler:${daggerVersion}")
kapt("com.google.dagger:dagger-android-processor:${daggerVersion}")
kaptTest("com.google.dagger:dagger-compiler:${daggerVersion}")
kaptTest("com.google.dagger:dagger-android-processor:${daggerVersion}")
testImplementation("androidx.test:core:${androidxTestVersion}")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
testImplementation("android.arch.core:core-testing:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:${espressoVersion}")
androidTestImplementation("androidx.test.espresso:espresso-contrib:${espressoVersion}")
androidTestImplementation("androidx.test.espresso:espresso-intents:${espressoVersion}")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test:core-ktx:${androidxTestVersion}")
androidTestImplementation("com.schibsted.spain:barista:3.9.0") {
exclude("org.jetbrains.kotlin")
}
androidTestImplementation("com.squareup.okhttp3:mockwebserver:${okHttpVersion}")
androidTestImplementation("androidx.test:rules:${androidxTestVersion}")
androidTestImplementation("androidx.test:runner:${androidxTestVersion}")
androidTestUtil("androidx.test:orchestrator:${androidxTestVersion}")
}
// Publishing
val serviceAccountCreds = file("owntracks-android-7a8e1517bde3.json")
play {
if (serviceAccountCreds.exists()) {
enabled.set(true)
serviceAccountCredentials.set(serviceAccountCreds)
} else {
enabled.set(false)
}
track.set("internal")
resolutionStrategy.set(com.github.triplet.gradle.androidpublisher.ResolutionStrategy.AUTO)
}
// Espresso test screenshot gathering
val reportsDirectory = File("$buildDir/reports/androidTests/connected/flavors/debugAndroidTest")
val screenshotsDeviceFolder = "/storage/emulated/0/Download/testscreenshots"
val createScreenshotDirectoryTask = tasks.register<Exec>("createScreenshotDirectory") {
group = "reporting"
description = "Creates screenshot directory on connected device"
executable = "${android.adbExecutable}"
args(mutableListOf("shell", "mkdir", "-p", screenshotsDeviceFolder))
}
val embedScreenshotsTask = tasks.register("embedScreenshots") {
group = "reporting"
description = "Embeds the screenshots in the test report"
doFirst {
val screenshotsDirectory = File(reportsDirectory, "testscreenshots/")
if (!screenshotsDirectory.exists()) {
println("Could not find screenshots. Skipping...")
return@doFirst
}
screenshotsDirectory
.listFiles()!!
.forEach { testClassDirectory ->
val testClassName = testClassDirectory.name
testClassDirectory.listFiles()?.forEach failedFile@{
val testName = it.name
val testNameWithoutExtension = it.nameWithoutExtension
val testClassJunitReportFile = File(reportsDirectory, "${testClassName}.html")
if (!testClassJunitReportFile.exists()) {
println("Could not find JUnit report file for test class '${testClassJunitReportFile}'")
return@failedFile
}
val testJunitReportContent = testClassJunitReportFile.readText()
val failedHeaderPatternToFind = "<h3 class=\"failures\">${testNameWithoutExtension}</h3>"
val failedPatternToReplace = "$failedHeaderPatternToFind <img src=\"testscreenshots/${testClassName}/${testName}\" width =\"360\" />"
val successRecordPatternToFind = "<td>${testNameWithoutExtension}</td>"
val successPatternToReplace = "<td>${testNameWithoutExtension} <a href=\"testscreenshots/${testClassName}/${testName}\">(screenshot)</a></td>"
testClassJunitReportFile.writeText(testJunitReportContent
.replace(failedHeaderPatternToFind, failedPatternToReplace)
.replace(successRecordPatternToFind, successPatternToReplace)
)
}
}
}
}
val fetchScreenshotsTask = tasks.register<Exec>("fetchScreenshots") {
group = "reporting"
description = "Fetches espresso screenshots from the device"
executable = "${android.adbExecutable}"
args("pull", screenshotsDeviceFolder, reportsDirectory.toString())
finalizedBy(clearScreenshotsTask)
dependsOn(createScreenshotDirectoryTask)
doFirst {
reportsDirectory.mkdirs()
}
}
val clearScreenshotsTask = tasks.register<Exec>("clearScreenshots") {
group = "reporting"
description = "Removes screenshots from connected device"
executable = "${android.adbExecutable}"
args("shell", "rm", "-rf", screenshotsDeviceFolder)
finalizedBy(embedScreenshotsTask)
}
tasks.whenTaskAdded {
if (name == "connectedDebugAndroidTest") {
finalizedBy(fetchScreenshotsTask)
}
}
scabbard {
enabled = !gradle.startParameter.toString().contains("assembleRelease")
fullBindingGraphValidation = true
failOnError = true
outputFormat = "svg"
}