-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.gradle.kts
353 lines (298 loc) · 12.9 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
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
import co.electriccoin.zcash.Git
import com.android.build.api.variant.BuildConfigField
import com.android.build.api.variant.ResValue
import java.util.Locale
plugins {
id("com.android.application")
kotlin("android")
id("secant.android-build-conventions")
id("com.osacky.fladle")
id("wtf.emulator.gradle")
id("secant.emulator-wtf-conventions")
id("publish.secant.publish-conventions")
}
val hasFirebaseApiKeys = run {
val srcDir = File(project.projectDir, "src")
val releaseApiKey = File(File(srcDir, "release"), "google-services.json")
val debugApiKey = File(File(srcDir, "debug"), "google-services.json")
val result = releaseApiKey.exists() && debugApiKey.exists()
if (!result) {
project.logger.info("Firebase API keys not found. Crashlytics will not be enabled. To enable " +
"Firebase, add the API keys for ${releaseApiKey.path} and ${debugApiKey.path}.")
}
result
}
if (hasFirebaseApiKeys) {
apply(plugin = "com.google.gms.google-services")
apply(plugin = "com.google.firebase.crashlytics")
}
val packageName = project.property("ZCASH_RELEASE_PACKAGE_NAME").toString()
val testnetNetworkName = "Testnet"
android {
namespace = "co.electriccoin.zcash.app"
defaultConfig {
applicationId = packageName
// If Google Play deployment is triggered, then these are placeholders which are overwritten
// when the deployment runs
versionCode = project.property("ZCASH_VERSION_CODE").toString().toInt()
versionName = project.property("ZCASH_VERSION_NAME").toString()
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
testInstrumentationRunner = "co.electriccoin.zcash.test.ZcashUiTestRunner"
}
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
buildFeatures {
buildConfig = true
}
flavorDimensions.add("network")
val testNetFlavorName = "zcashtestnet"
productFlavors {
// would rather name them "testnet" and "mainnet" but product flavor names cannot start with the word "test"
create(testNetFlavorName) {
dimension = "network"
applicationId = "$packageName.testnet" // allow to be installed alongside mainnet
matchingFallbacks.addAll(listOf("zcashtestnet", "debug"))
}
create("zcashmainnet") {
dimension = "network"
applicationId = packageName
matchingFallbacks.addAll(listOf("zcashmainnet", "release"))
}
}
val releaseKeystorePath = project.property("ZCASH_RELEASE_KEYSTORE_PATH").toString()
val releaseKeystorePassword = project.property("ZCASH_RELEASE_KEYSTORE_PASSWORD").toString()
val releaseKeyAlias = project.property("ZCASH_RELEASE_KEY_ALIAS").toString()
val releaseKeyAliasPassword =
project.property("ZCASH_RELEASE_KEY_ALIAS_PASSWORD").toString()
val isReleaseSigningConfigured = listOf(
releaseKeystorePath,
releaseKeystorePassword,
releaseKeyAlias,
releaseKeyAliasPassword
).all { it.isNotBlank() }
signingConfigs {
if (isReleaseSigningConfigured) {
// If this block doesn't execute, the output will be unsigned
create("release").apply {
storeFile = File(releaseKeystorePath)
storePassword = releaseKeystorePassword
keyAlias = releaseKeyAlias
keyPassword = releaseKeyAliasPassword
}
}
}
buildTypes {
getByName("debug").apply {
// Note that the build-conventions defines the res configs
isPseudoLocalesEnabled = true
// Suffixing app package name and version to avoid collisions with other installed Zcash
// apps (e.g. from Google Play)
versionNameSuffix = "-debug"
applicationIdSuffix = ".debug"
}
getByName("release").apply {
isMinifyEnabled = project.property("IS_MINIFY_ENABLED").toString().toBoolean()
isShrinkResources = project.property("IS_MINIFY_ENABLED").toString().toBoolean()
ndk.debugSymbolLevel = project.property("NDK_DEBUG_SYMBOL_LEVEL").toString()
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-project.txt"
)
val isReleaseBuildDebuggable = project.property("IS_RELEASE_BUILD_DEBUGGABLE")
.toString().toBoolean()
isDebuggable = isReleaseBuildDebuggable
val isSignReleaseBuildWithDebugKey = project.property("IS_SIGN_RELEASE_BUILD_WITH_DEBUG_KEY")
.toString().toBoolean()
if (isReleaseSigningConfigured) {
signingConfig = signingConfigs.getByName("release")
} else if (isSignReleaseBuildWithDebugKey) {
// Warning: in this case is the release build signed with the debug key
signingConfig = signingConfigs.getByName("debug")
}
}
}
// Resolve final app name
applicationVariants.all {
val defaultAppName = project.property("ZCASH_RELEASE_APP_NAME").toString()
val debugAppNameSuffix = project.property("ZCASH_DEBUG_APP_NAME_SUFFIX").toString()
val supportEmailAddress = project.property("ZCASH_SUPPORT_EMAIL_ADDRESS").toString()
when (this.name) {
"zcashtestnetDebug" -> {
resValue("string", "app_name", "$defaultAppName ($testnetNetworkName)$debugAppNameSuffix")
}
"zcashmainnetDebug" -> {
resValue("string", "app_name", "$defaultAppName$debugAppNameSuffix")
}
"zcashtestnetRelease" -> {
resValue("string", "app_name", "$defaultAppName ($testnetNetworkName)")
}
"zcashmainnetRelease" -> {
resValue("string", "app_name", defaultAppName)
}
}
resValue("string", "support_email_address", supportEmailAddress)
}
testCoverage {
jacocoVersion = project.property("JACOCO_VERSION").toString()
}
}
dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.annotation)
implementation(libs.androidx.core)
// just to support baseline profile installation needed by benchmark tests
implementation(libs.androidx.profileinstaller)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.zcash.sdk) // just to configure logging
implementation(projects.crashAndroidLib)
implementation(projects.preferenceApiLib)
implementation(projects.preferenceImplAndroidLib)
implementation(projects.spackleAndroidLib)
implementation(projects.uiLib)
androidTestImplementation(projects.testLib)
androidTestUtil(libs.androidx.test.services) {
artifact {
type = "apk"
}
}
if (project.property("IS_USE_TEST_ORCHESTRATOR").toString().toBoolean()) {
androidTestUtil(libs.androidx.test.orchestrator) {
artifact {
type = "apk"
}
}
}
}
androidComponents {
onVariants { variant ->
for (output in variant.outputs) {
// Configure strict mode in runtime
variant.buildConfigFields.put(
"IS_STRICT_MODE_CRASH_ENABLED",
BuildConfigField(
type = "boolean",
value = project.property("IS_CRASH_ON_STRICT_MODE_VIOLATION").toString(),
comment = "Whether is the strict mode enabled"
)
)
variant.resValues.put(
// Key matches the one in crash-android-lib/src/res/values/bools.xml
variant.makeResValueKey("bool", "co_electriccoin_zcash_crash_is_firebase_enabled"),
ResValue(value = hasFirebaseApiKeys.toString())
)
if (project.property("ZCASH_GOOGLE_PLAY_SERVICE_ACCOUNT_KEY").toString().isNotEmpty() &&
project.property("ZCASH_GOOGLE_PLAY_PUBLISHER_API_KEY").toString().isNotEmpty()
) {
// Update the versionName to reflect bumps in versionCode
val versionCodeOffset = 0 // Change this to zero the final digit of the versionName
val processedVersionCode = output.versionCode.map { playVersionCode ->
val defaultVersionName = project.property("ZCASH_VERSION_NAME").toString()
// Version names will look like `myCustomVersionName.123`
@Suppress("UNNECESSARY_SAFE_CALL")
playVersionCode?.let {
val delta = it - versionCodeOffset
if (delta < 0) {
defaultVersionName
} else {
"$defaultVersionName ($delta)"
}
} ?: defaultVersionName
}
output.versionName.set(processedVersionCode)
val gitInfo = Git.newInfo(Git.MAIN, parent!!.projectDir)
output.versionCode.set(gitInfo.commitCount)
}
}
variant.packaging.resources.excludes.addAll(listOf(
".readme",
))
// The fixed Locale.US is intended
if (variant.name.lowercase(Locale.US).contains("release")) {
variant.packaging.resources.excludes.addAll(listOf(
"**/*.kotlin_metadata",
"DebugProbesKt.bin",
"META-INF/*.kotlin_module",
"META-INF/*.version",
"META-INF/android.arch**",
"META-INF/androidx**",
"META-INF/com.android**",
"META-INF/com.google.android.material_material.version",
"META-INF/com.google.dagger_dagger.version",
"build-data.properties",
"core.properties",
"firebase-**.properties",
"kotlin-tooling-metadata.json",
"kotlin/**",
"play-services-**.properties",
"protolite-well-known-types.properties",
"transport-api.properties",
"transport-backend-cct.properties",
"transport-runtime.properties"
))
}
}
}
fladle {
// Firebase Test Lab has min and max values that might differ from our project's
// These are determined by `gcloud firebase test android models list`
@Suppress("MagicNumber", "VariableNaming")
val FIREBASE_TEST_LAB_MIN_SDK = 27 // Minimum for Pixel2.arm device
@Suppress("MagicNumber", "VariableNaming")
val FIREBASE_TEST_LAB_MAX_SDK = 33
val minSdkVersion = run {
val buildMinSdk = project.properties["ANDROID_MIN_SDK_VERSION"].toString().toInt()
buildMinSdk.coerceAtLeast(FIREBASE_TEST_LAB_MIN_SDK).toString()
}
val targetSdkVersion = run {
val buildTargetSdk = project.properties["ANDROID_TARGET_SDK_VERSION"].toString().toInt()
buildTargetSdk.coerceAtMost(FIREBASE_TEST_LAB_MAX_SDK).toString()
}
val firebaseTestLabKeyPath = project.properties["ZCASH_FIREBASE_TEST_LAB_API_KEY_PATH"].toString()
val firebaseProject = project.properties["ZCASH_FIREBASE_TEST_LAB_PROJECT"].toString()
if (firebaseTestLabKeyPath.isNotEmpty()) {
serviceAccountCredentials.set(File(firebaseTestLabKeyPath))
} else if (firebaseProject.isNotEmpty()) {
projectId.set(firebaseProject)
}
@Suppress("MagicNumber")
flakyTestAttempts.set(1)
configs {
val buildDirectory = layout.buildDirectory.get().asFile
create("sanityConfigDebug") {
clearPropertiesForSanityRobo()
debugApk.set(
project.provider {
"${buildDirectory}/outputs/apk/zcashmainnet/debug/app-zcashmainnet-debug.apk"
}
)
testTimeout.set("3m")
devices.addAll(
mapOf("model" to "Pixel2.arm", "version" to minSdkVersion),
mapOf("model" to "Pixel2.arm", "version" to targetSdkVersion)
)
flankVersion.set(libs.versions.flank.get())
}
create("sanityConfigRelease") {
clearPropertiesForSanityRobo()
debugApk.set(
project.provider {
"$buildDirectory" +
"/outputs/apk_from_bundle/zcashmainnetRelease/app-zcashmainnet-release-universal.apk"
}
)
testTimeout.set("3m")
devices.addAll(
mapOf("model" to "Pixel2", "version" to minSdkVersion),
mapOf("model" to "Pixel2.arm", "version" to targetSdkVersion)
)
flankVersion.set(libs.versions.flank.get())
}
}
}