forked from element-hq/element-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
378 lines (323 loc) · 14.6 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
import com.android.build.OutputFile
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.appdistribution'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'kotlinx-knit'
apply plugin: 'com.likethesalad.stem'
if (project.hasProperty("coverage")) {
apply plugin: 'jacoco'
}
kapt {
correctErrorTypes = true
}
knit {
files = fileTree(project.rootDir) {
include '**/*.md'
include '**/*.kt'
include '**/*.kts'
exclude '**/build/**'
exclude '**/.gradle/**'
exclude '**/towncrier/template.md'
exclude '**/CHANGES.md'
}
}
// Note: 2 digits max for each value
ext.versionMajor = 1
ext.versionMinor = 5
// Note: even values are reserved for regular release, odd values for hotfix release.
// When creating a hotfix, you should decrease the value, since the current value
// is the value for the next regular release.
ext.versionPatch = 0
static def getGitTimestamp() {
def cmd = 'git show -s --format=%ct'
return cmd.execute().text.trim() as Long
}
static def generateVersionCodeFromTimestamp() {
// It's unix timestamp, minus timestamp of October 3rd 2018 (first commit date) divided by 100: It's incremented by one every 100 seconds.
// plus 20_000_000 for compatibility reason with the previous way the Version Code was computed
// Note that the result will be multiplied by 10 when adding the digit for the arch
return ((getGitTimestamp() - 1_538_524_800) / 100).toInteger() + 20_000_000
}
def generateVersionCodeFromVersionName() {
// plus 4_000_000 for compatibility reason with the previous way the Version Code was computed
// Note that the result will be multiplied by 10 when adding the digit for the arch
return (versionMajor * 1_00_00 + versionMinor * 1_00 + versionPatch) + 4_000_000
}
def getVersionCode() {
if (gitBranchName() == "develop") {
return generateVersionCodeFromTimestamp()
} else {
return generateVersionCodeFromVersionName()
}
}
static def gitRevision() {
def cmd = "git rev-parse --short=8 HEAD"
return cmd.execute().text.trim()
}
static def gitRevisionDate() {
def cmd = "git show -s --format=%ci HEAD^{commit}"
return cmd.execute().text.trim()
}
static def gitBranchName() {
def fromEnv = System.env.BUILDKITE_BRANCH as String ?: ""
if (!fromEnv.isEmpty()) {
return fromEnv
} else {
// Note: this command return "HEAD" on Buildkite, so use the system env 'BUILDKITE_BRANCH' content first
def cmd = "git rev-parse --abbrev-ref HEAD"
return cmd.execute().text.trim()
}
}
// For Google Play build, build on any other branch than main will have a "-dev" suffix
static def getGplayVersionSuffix() {
if (gitBranchName() == "main") {
return ""
} else {
return "-dev"
}
}
static def gitTag() {
def cmd = "git describe --exact-match --tags"
return cmd.execute().text.trim()
}
// For F-Droid build, build on a not tagged commit will have a "-dev" suffix
static def getFdroidVersionSuffix() {
if (gitTag() == "") {
return "-dev"
} else {
return ""
}
}
project.android.buildTypes.all { buildType ->
buildType.javaCompileOptions.annotationProcessorOptions.arguments =
[
validateEpoxyModelUsage: String.valueOf(buildType.name == 'debug')
]
}
// map for the version codes last digit
// x86 must have greater values than arm
// 64 bits have greater value than 32 bits
ext.abiVersionCodes = ["armeabi-v7a": 1, "arm64-v8a": 2, "x86": 3, "x86_64": 4].withDefault { 0 }
def buildNumber = System.env.BUILDKITE_BUILD_NUMBER as Integer ?: 0
android {
// Due to a bug introduced in Android gradle plugin 3.6.0, we have to specify the ndk version to use
// Ref: https://issuetracker.google.com/issues/144111441
ndkVersion "21.3.6528147"
compileSdk versions.compileSdk
defaultConfig {
applicationId "im.vector.app"
// Set to API 21: see #405
minSdk versions.minSdk
targetSdk versions.targetSdk
multiDexEnabled true
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
// `develop` branch will have version code from timestamp, to ensure each build from CI has a incremented versionCode.
// Other branches (main, features, etc.) will have version code based on application version.
versionCode project.getVersionCode()
// Required for sonar analysis
versionName "${versionMajor}.${versionMinor}.${versionPatch}-sonar"
// Generate a random app task affinity
manifestPlaceholders = [appTaskAffinitySuffix: "H_${gitRevision()}"]
buildConfigField "String", "GIT_REVISION", "\"${gitRevision()}\""
buildConfigField "String", "GIT_REVISION_DATE", "\"${gitRevisionDate()}\""
buildConfigField "String", "GIT_BRANCH_NAME", "\"${gitBranchName()}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Keep abiFilter for the universalApk
ndk {
abiFilters "armeabi-v7a", "x86", 'arm64-v8a', 'x86_64'
}
// Ref: https://developer.android.com/studio/build/configure-apk-splits.html
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for armeabi-v7a, x86, arm64-v8a and x86_64.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
// Generate a universal APK that includes all ABIs, so user who install from CI tool can use this one by default.
universalApk true
}
}
applicationVariants.all { variant ->
// assign different version code for each output
def baseVariantVersion = variant.versionCode * 10
variant.outputs.each { output ->
def baseAbiVersionCode = project.ext.abiVersionCodes.get(output.getFilter(OutputFile.ABI))
// Known limitation: it does not modify the value in the BuildConfig.java generated file
// See https://issuetracker.google.com/issues/171133218
output.versionCodeOverride = baseVariantVersion + baseAbiVersionCode
print "ABI " + output.getFilter(OutputFile.ABI) + " \t-> VersionCode = " + output.versionCodeOverride + "\n"
output.outputFileName = output.outputFileName.replace("vector-app", "vector")
}
}
// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
// Disables animations during instrumented tests you run from the command line…
// This property does not affect tests that you run using Android Studio.”
animationsDisabled = true
// Comment to run on Android 12
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
signingConfigs {
debug {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('./signature/debug.keystore')
storePassword 'android'
}
nightly {
keyAlias System.env.ELEMENT_ANDROID_NIGHTLY_KEYID ?: project.property("signing.element.nightly.keyId")
keyPassword System.env.ELEMENT_ANDROID_NIGHTLY_KEYPASSWORD ?: project.property("signing.element.nightly.keyPassword")
storeFile file('./signature/nightly.keystore')
storePassword System.env.ELEMENT_ANDROID_NIGHTLY_STOREPASSWORD ?: project.property("signing.element.nightly.storePassword")
}
release {
keyAlias project.property("signing.element.keyId")
keyPassword project.property("signing.element.keyPassword")
storeFile file(project.property("signing.element.storePath"))
storePassword project.property("signing.element.storePassword")
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
resValue "string", "app_name", "Element dbg"
resValue "color", "launcher_background", "#0DBD8B"
if (project.hasProperty("coverage")) {
testCoverageEnabled = coverage.enableTestCoverage
}
}
release {
resValue "string", "app_name", "Element"
resValue "color", "launcher_background", "#0DBD8B"
postprocessing {
removeUnusedCode true
removeUnusedResources true
// We do not activate obfuscation as it makes it hard then to read crash reports, and it's a bit useless on an open source project :)
obfuscate false
optimizeCode true
proguardFiles 'proguard-rules.pro'
}
// signingConfig signingConfigs.release
}
nightly {
initWith release
applicationIdSuffix ".nightly"
versionNameSuffix "-nightly"
// Just override the background color of the launcher icon for the nightly build.
resValue "color", "launcher_background", "#07007E"
// We need to copy paste this block, this is not done automatically by `initWith release`
postprocessing {
removeUnusedCode true
removeUnusedResources true
// We do not activate obfuscation as it makes it hard then to read crash reports, and it's a bit useless on an open source project :)
obfuscate false
optimizeCode true
proguardFiles 'proguard-rules.pro'
}
matchingFallbacks = ['release']
signingConfig signingConfigs.nightly
firebaseAppDistribution {
artifactType = "APK"
// We upload the universal APK to fix this error:
// "App Distribution found more than 1 output file for this variant.
// Please contact firebase-support@google.com for help using APK splits with App Distribution."
artifactPath = "$rootDir/vector-app/build/outputs/apk/gplay/nightly/vector-gplay-universal-nightly.apk"
// This file will be generated by the GitHub action
releaseNotesFile = "CHANGES_NIGHTLY.md"
groups = "external-testers"
// This should not be required, but if I do not add the appId, I get this error:
// "App Distribution halted because it had a problem uploading the APK: [404] Requested entity was not found."
appId = "1:912726360885:android:efd8545af52a9f9300427c"
}
}
}
flavorDimensions "store"
productFlavors {
gplay {
apply plugin: 'com.google.gms.google-services'
afterEvaluate {
tasks.matching { it.name.contains("GoogleServices") && !it.name.contains("Gplay") }*.enabled = false
}
dimension "store"
isDefault = true
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getGplayVersionSuffix()}"
buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"G\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"GooglePlay\""
}
fdroid {
dimension "store"
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getFdroidVersionSuffix()}"
buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"F\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"FDroid\""
}
}
lintOptions {
lintConfig file("../tools/lint/lint.xml")
checkDependencies true
abortOnError true
}
compileOptions {
sourceCompatibility versions.sourceCompat
targetCompatibility versions.targetCompat
}
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += [
"-opt-in=kotlin.RequiresOptIn",
// Fixes false positive "This is an internal Mavericks API. It is not intended for external use."
// of MvRx `by viewModel()` calls. Maybe due to the inlining of code... This is a temporary fix...
"-opt-in=com.airbnb.mvrx.InternalMavericksApi",
// Opt in for kotlinx.coroutines.FlowPreview too
"-opt-in=kotlinx.coroutines.FlowPreview",
// Opt in for kotlinx.coroutines.ExperimentalCoroutinesApi too
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
]
}
}
dependencies {
implementation project(':vector')
implementation project(':vector-config')
implementation libs.dagger.hilt
implementation 'androidx.multidex:multidex:2.0.1'
implementation "androidx.sharetarget:sharetarget:1.1.0"
kapt libs.dagger.hiltCompiler
androidTestImplementation libs.androidx.testCore
androidTestImplementation libs.androidx.testRunner
androidTestImplementation libs.androidx.testRules
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espressoCore
androidTestImplementation libs.androidx.espressoContrib
androidTestImplementation libs.androidx.espressoIntents
androidTestImplementation libs.tests.kluent
androidTestImplementation libs.androidx.coreTesting
androidTestImplementation(libs.jetbrains.coroutinesTest) {
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
}
// Plant Timber tree for test
androidTestImplementation libs.tests.timberJunitRule
// "The one who serves a great Espresso"
androidTestImplementation('com.adevinta.android:barista:4.2.0') {
exclude group: 'org.jetbrains.kotlin'
}
androidTestImplementation libs.mockk.mockkAndroid
androidTestUtil libs.androidx.orchestrator
androidTestImplementation libs.androidx.fragmentTesting
androidTestImplementation "org.jetbrains.kotlin:kotlin-reflect:1.7.10"
debugImplementation libs.androidx.fragmentTesting
}